[IMP] stock, inventory: improving the usability
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Thu, 10 Apr 2014 10:14:04 +0000 (12:14 +0200)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Thu, 10 Apr 2014 10:14:04 +0000 (12:14 +0200)
bzr revid: qdp-launchpad@openerp.com-20140410101404-uvufnxi4p6s4aicu

addons/stock/stock.py
addons/stock/stock_view.xml

index 96ec2c1..3c7f849 100644 (file)
@@ -2640,28 +2640,39 @@ class stock_inventory_line(osv.osv):
             vals['product_uom_qty'] = diff
         return stock_move_obj.create(cr, uid, vals, context=context)
 
-    def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, owner_id=False, lot_id=False, package_id=False, context=None):
-        """ Changes UoM and name if product_id changes.
+    def restrict_change(self, cr, uid, ids, th_qty, context=None):
+        if ids and th_qty:
+            #if the user try to modify a line prepared by openerp, reject the change and display an error message explaining how he should do
+            old_value = self.browse(cr, uid, ids[0], context=context)
+            return {
+                'value': {
+                    'product_id': old_value.product_id.id,
+                    'product_uom_id': old_value.product_uom_id.id,
+                    'location_id': old_value.location_id.id,
+                    'prod_lot_id': old_value.prod_lot_id.id,
+                    'package_id': old_value.package_id.id,
+                    'partner_id': old_value.partner_id.id,
+                    },
+                'warning': {
+                    'title': _('Error'),
+                    'message': _('You can only change the checked quantity of an existing inventory line. If you want modify a data, please set the checked quantity to 0 and create a new inventory line.')
+                }
+            }
+        return {}
+
+    def on_change_product_id(self, cr, uid, ids, product, uom, th_qty, context=None):
+        """ Changes UoM
         @param location_id: Location id
         @param product: Changed product_id
         @param uom: UoM product
         @return:  Dictionary of changed values
         """
-        context = context or {}
+        if ids and th_qty:
+            return self.restrict_change(cr, uid, ids, th_qty, context=context)
         if not product:
-            return {'value': {'product_qty': 0.0, 'product_uom_id': False}}
-        uom_obj = self.pool.get('product.uom')
-        ctx = context.copy()
-        ctx['location'] = location_id
-        ctx['lot_id'] = lot_id
-        ctx['owner_id'] = owner_id
-        ctx['package_id'] = package_id
-        obj_product = self.pool.get('product.product').browse(cr, uid, product, context=ctx)
-        th_qty = obj_product.qty_available
-        if uom and uom != obj_product.uom_id.id:
-            uom_record = uom_obj.browse(cr, uid, uom, context=context)
-            th_qty = uom_obj._compute_qty_obj(cr, uid, obj_product.uom_id, th_qty, uom_record)
-        return {'value': {'th_qty': th_qty, 'product_uom_id': uom or obj_product.uom_id.id}}
+            return {'value': {'product_uom_id': False}}
+        obj_product = self.pool.get('product.product').browse(cr, uid, product, context=context)
+        return {'value': {'product_uom_id': uom or obj_product.uom_id.id}}
 
 
 #----------------------------------------------------------
index 64539be..3889f79 100644 (file)
                             <button name="set_checked_qty" states="confirm" string="⇒ Set quantities to 0" type="object" class="oe_link oe_right" groups="stock.group_stock_user"/>
                             <field name="line_ids" string="Inventory Details" context="{'default_location_id': location_id,  'default_product_id': product_id, 'default_prod_lot_id': lot_id, 'default_package_id': package_id, 'default_partner_id': partner_id}">
                                 <tree string="Inventory Details" editable="bottom" colors="blue: product_qty != th_qty; red: th_qty &lt; 0">
-                                    <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,partner_id,prod_lot_id,package_id)" domain="[('type','=','product')]"/>
-                                    <field name="product_uom_id" groups="product.group_uom" on_change="on_change_product_id(location_id,product_id,product_uom_id,partner_id,prod_lot_id,package_id)"/>
-                                    <field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations" on_change="on_change_product_id(location_id,product_id,product_uom_id,partner_id,prod_lot_id,package_id)"/>
-                                    <field name="prod_lot_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,partner_id,prod_lot_id,package_id)" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}"  groups="stock.group_production_lot"/>
-                                    <field name="package_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,partner_id,prod_lot_id,package_id)" groups="stock.group_tracking_lot"/>
-                                    <field name="partner_id" on_change="on_change_product_id(location_id,product_id,product_uom_id,partner_id,prod_lot_id,package_id)" groups="stock.group_tracking_owner"/>
+                                    <field context="{'location':location_id, 'uom':product_uom_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(product_id,product_uom_id,th_qty,context)" domain="[('type','=','product')]"/>
+                                    <field name="product_uom_id" groups="product.group_uom" on_change="restrict_change(th_qty)"/>
+                                    <field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations" on_change="restrict_change(th_qty)"/>
+                                    <field name="prod_lot_id" on_change="restrict_change(th_qty)" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}"  groups="stock.group_production_lot"/>
+                                    <field name="package_id" on_change="restrict_change(th_qty)" groups="stock.group_tracking_lot"/>
+                                    <field name="partner_id" on_change="restrict_change(th_qty)" groups="stock.group_tracking_owner"/>
                                     <field name="th_qty" readonly="1"/>
                                     <field name="product_qty" string="Real Quantity"/>
                                     <field name="state" invisible="True"/>
                                 </tree>
                             </field>
-                            <p class="oe_grey">
-                                Inventory adjustments will be made by comparing the theoretical and the checked quantities. You can delete lines to ignore some products. If a product is not at the right place, set the checked quantity to 0 and create a new line with correct location.
-                            </p>
+                            <p></p>
+                            <h3 class="oe_grey">Notes</h3>
+                            <ul class="oe_grey"><li>Inventory adjustments will be made by comparing the theoretical and the checked quantities.</li>
+                            <li>You can delete lines to ignore some products.</li>
+                            <li>If a product is not at the right place, set the checked quantity to 0 and create a new line with correct location.</li>
+                            </ul>
                         </page>
                         <page string="Inventory Adjustments" attrs="{'invisible': [('state', '!=', 'done')]}">
                             <field name="move_ids">