[IMP] inventory usability

bzr revid: qdp-launchpad@openerp.com-20130806123008-cf9vtnpfxwat0x0g
This commit is contained in:
Quentin (OpenERP) 2013-08-06 14:30:08 +02:00
parent 11d431010b
commit cfeaa8c449
2 changed files with 41 additions and 49 deletions

View File

@ -1478,6 +1478,15 @@ class stock_move(osv.osv):
class stock_inventory(osv.osv):
_name = "stock.inventory"
_description = "Inventory"
def _get_move_ids_exist(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for inv in self.browse(cr, uid, ids, context=context):
res[inv.id] = False
if inv.move_ids:
res[inv.id] = True
return res
_columns = {
'name': fields.char('Inventory Reference', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}),
'date': fields.datetime('Creation Date', required=True, readonly=True, states={'draft': [('readonly', False)]}),
@ -1491,6 +1500,7 @@ class stock_inventory(osv.osv):
'package_id': fields.many2one('stock.quant.package', 'Pack'),
'partner_id': fields.many2one('res.partner', 'Owner'),
'lot_id': fields.many2one('stock.production.lot', 'Lot/Serial Number'),
'move_ids_exist': fields.function(_get_move_ids_exist, type='boolean', string=' Stock Move Exists?', help='technical field for attrs in view'),
}
def _default_stock_location(self, cr, uid, context=None):
@ -1530,6 +1540,8 @@ class stock_inventory(osv.osv):
context = {}
move_obj = self.pool.get('stock.move')
for inv in self.browse(cr, uid, ids, context=context):
if not inv.move_ids:
self.action_check(cr, uid, [inv.id], context=context)
move_obj.action_done(cr, uid, [x.id for x in inv.move_ids], context=context)
self.write(cr, uid, [inv.id], {'state': 'done', 'date_done': time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
return True
@ -1559,8 +1571,8 @@ class stock_inventory(osv.osv):
vals['product_uom_qty'] = todo_line['product_qty']
stock_move_obj.create(cr, uid, vals, context=context)
def action_confirm(self, cr, uid, ids, context=None):
""" Confirm the inventory and writes its finished date
def action_check(self, cr, uid, ids, context=None):
""" Checks the inventory and computes the stock move to do
@return: True
"""
inventory_line_obj = self.pool.get('stock.inventory.line')
@ -1578,7 +1590,6 @@ class stock_inventory(osv.osv):
for todo_line in theorical_lines:
if todo_line['product_qty'] != 0:
self._create_stock_move(cr, uid, inventory, todo_line, context=context)
return self.write(cr, uid, ids, {'state': 'confirm'})
def action_cancel_draft(self, cr, uid, ids, context=None):
""" Cancels the stock move and change inventory state to draft.
@ -1605,6 +1616,7 @@ class stock_inventory(osv.osv):
if full_of_zeros:
product_line['product_qty'] = 0
inventory_line_obj.create(cr, uid, product_line, context=context)
return self.write(cr, uid, ids, {'state': 'confirm'})
def _get_inventory_lines(self, cr, uid, inventory, context=None):
location_obj = self.pool.get('stock.location')

View File

@ -101,16 +101,13 @@
<field name="arch" type="xml">
<form string="Physical Inventory" version="7.0">
<header>
<button name="action_confirm" states="draft" string="Confirm Inventory" type="object" class="oe_highlight" groups="stock.group_stock_user"/>
<button name="%(action_view_stock_fill_inventory)d" states="draft" string="Fill Inventory" type="object" class="oe_highlight" groups="stock.group_stock_user"/>
<button name="action_done" states="confirm" string="Validate Inventory" type="object" class="oe_highlight" groups="stock.group_stock_manager"/>
<button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object"/>
<button name="action_cancel_inventory" states="draft,confirm,done" string="Cancel Inventory" type="object"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirm"/>
</header>
<sheet>
<div class="oe_right oe_button_box">
<button name="%(action_view_stock_fill_inventory)d" string="Fill Inventory" states="draft,confirm" type="action" />
</div>
<group>
<group>
<field name="name" placeholder="e.g. Annual inventory"/>
@ -125,48 +122,31 @@
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
</group>
</group>
<notebook>
<page string="General Information">
<field name="line_ids">
<tree string="Products" editable="bottom">
<field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations"/>
<field context="{'location':location_id, 'uom':product_uom_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,parent.date)" domain="[('type','=','product')]"/>
<field name="product_qty"/>
<field name="product_uom_id" groups="product.group_uom"/>
<field name="state" invisible="True"/>
</tree>
<form string="Products" version="7.0">
<group>
<group>
<field domain="[('usage','=','internal')]" name="location_id"/>
<field context="{'location':location_id, 'uom':product_uom_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
</group>
<group>
<label for="product_qty"/>
<div>
<field name="product_qty" class="oe_inline"/>
<field name="product_uom_id" class="oe_inline" groups="product.group_uom"/>
</div>
</group>
</group>
</form>
</field>
</page>
<page string="Posted Inventory">
<field name="move_ids" context="{'inventory_id':active_id}" >
<tree string="Stock Moves">
<field name="product_id"/>
<field name="product_uom_qty" on_change="onchange_quantity(product_id, product_uom_qty, product_uom, product_uos)"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
<field name="quant_ids"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="location_dest_id" groups="stock.group_locations"/>
<field name="date" string="Date"/>
<field name="state" invisible="True"/>
</tree>
</field>
</page>
</notebook>
<div class="oe_right oe_button_box">
<button name="action_check" string="Check Inventory Adjustments" states="draft,confirm" type="action" />
</div>
<field name="move_ids" context="{'inventory_id':active_id}" readonly="1" attrs="{'invisible': [('move_ids_exist', '=', False)]}">
<tree string="Inventory Adjustments">
<field name="product_id"/>
<field name="lot_id"/>
<field name="product_uom_qty" on_change="onchange_quantity(product_id, product_uom_qty, product_uom, product_uos)"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
<field name="location_id"/>
<field name="location_dest_id"/>
<field name="state" invisible="True"/>
</tree>
</field>
<field name="line_ids">
<tree string="Inventory Details" editable="bottom">
<field context="{'location':location_id, 'uom':product_uom_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,parent.date)" domain="[('type','=','product')]"/>
<field name="product_qty"/>
<field name="product_uom_id" groups="product.group_uom"/>
<field name="prod_lot_id"/>
<field name="package_id" readonly="1"/>
<field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations"/>
<field name="state" invisible="True"/>
</tree>
</field>
</sheet>
</form>
</field>