Ravi Gohil (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-581987-rgo into 
lp:openobject-addons/6.1.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581987-rgo/+merge/137560

Hello,

Currently, there is no restriction on UoM for stock.inventory.line or 
stock.move objects, one can select any UoM whose UoM category is not same as 
previous one's.

To reproduce, go to "Warehouse/Inventory Control/Physical Inventories" and in 
Inventory lines and Stock Moves, you can set the UoM to any type.

To fix this, I have implemented an on_change for UoM for both the objects and 
modified on_change_product_id() accordingly to make this fix work.

This fix also restricts user from altering the records of inventory(inventory 
lines, stock move) after confirming it.

Kindly review the fix.

Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581987-rgo/+merge/137560
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-581987-rgo.
=== modified file 'stock/stock.py'
--- stock/stock.py	2012-10-05 07:47:57 +0000
+++ stock/stock.py	2012-12-03 13:15:42 +0000
@@ -1624,6 +1624,17 @@
             'You try to assign a lot which is not from the same product',
             ['prodlot_id'])]
 
+    def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None):
+        res = {'value':{}}
+        if not product_uom or not product_id:
+            return res
+        product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
+        uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context)
+        if uom.category_id.id != product.uom_id.category_id.id:
+            res['warning'] = {'title': _('Warning'), 'message': _('Selected Unit of Measure does not belong to the same category as the product Unit of Measure')}
+            res['value'].update({'product_uom': product.uom_id.id})
+        return res
+
     def _default_location_destination(self, cr, uid, context=None):
         """ Gets default address of partner for destination location
         @return: Address id or False
@@ -2619,8 +2630,8 @@
         '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)]}),
         'date_done': fields.datetime('Date done'),
-        'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventories', states={'done': [('readonly', True)]}),
-        'move_ids': fields.many2many('stock.move', 'stock_inventory_move_rel', 'inventory_id', 'move_id', 'Created Moves'),
+        'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventories', readonly=True, states={'draft': [('readonly', False)]}),
+        'move_ids': fields.many2many('stock.move', 'stock_inventory_move_rel', 'inventory_id', 'move_id', 'Created Moves', readonly=True, states={'draft': [('readonly', False)]}),
         'state': fields.selection( (('draft', 'Draft'), ('done', 'Done'), ('confirm','Confirmed'),('cancel','Cancelled')), 'State', readonly=True, select=True),
         'company_id': fields.many2one('res.company', 'Company', required=True, select=True, readonly=True, states={'draft':[('readonly',False)]}),
 
@@ -2758,6 +2769,17 @@
         'state': fields.related('inventory_id','state',type='char',string='State',readonly=True),
     }
 
+    def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None):
+        res = {'value':{}}
+        if not product_uom or not product_id:
+            return res
+        product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
+        uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context)
+        if uom.category_id.id != product.uom_id.category_id.id:
+            res['warning'] = {'title': _('Warning'), 'message': _('Selected Unit of Measure does not belong to the same category as the product Unit of Measure')}
+            res['value'].update({'product_uom': product.uom_id.id})
+        return res
+
     def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, to_date=False):
         """ Changes UoM and name if product_id changes.
         @param location_id: Location id
@@ -2768,7 +2790,7 @@
         if not product:
             return {'value': {'product_qty': 0.0, 'product_uom': False}}
         obj_product = self.pool.get('product.product').browse(cr, uid, product)
-        uom = uom or obj_product.uom_id.id
+        uom = obj_product.uom_id.id
         amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom, 'to_date': to_date, 'compute_child': False})[product]
         result = {'product_qty': amount, 'product_uom': uom}
         return {'value': result}

=== modified file 'stock/stock_view.xml'
--- stock/stock_view.xml	2012-11-16 16:43:29 +0000
+++ stock/stock_view.xml	2012-12-03 13:15:42 +0000
@@ -57,9 +57,9 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Stock Inventory Lines">
-                    <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)" select="1" domain="[('type','&lt;&gt;','service')]"/>
+                    <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,False,parent.date)" select="1" domain="[('type','&lt;&gt;','service')]"/>
                     <field name="product_qty"/>
-                    <field name="product_uom"/>
+                    <field name="product_uom" on_change="onchange_uom(product_id, product_uom, context)"/>
                     <field name="prod_lot_id" groups="base.group_extended"/>
                     <field colspan="4" domain="[('usage','=','internal')]" name="location_id" select="1"/>
                         <button name="%(stock.action_view_stock_inventory_line_split)d"
@@ -117,9 +117,9 @@
                         <field colspan="4" name="inventory_line_id" nolabel="1" widget="one2many_list">
                             <tree string="Products" editable="bottom">
                                 <field domain="[('usage','=','internal')]" name="location_id"/>
-                                <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)"  domain="[('type','&lt;&gt;','service')]"/>
+                                <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,False,parent.date)"  domain="[('type','&lt;&gt;','service')]"/>
                                 <field name="product_qty"/>
-                                <field name="product_uom"/>
+                                <field name="product_uom" on_change="onchange_uom(product_id, product_uom, context)"/>
                                 <field name="prod_lot_id" groups="base.group_extended"/>
                                 <button name="%(stock.action_view_stock_inventory_line_split)d"
                                     string="Split inventory lines" groups="base.group_extended"
@@ -129,9 +129,9 @@
                             <form string="Products ">
                                 <field domain="[('usage','=','internal')]" name="location_id"/>
                                 <newline/>
-                                <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)"  domain="[('type','&lt;&gt;','service')]"/>
+                                <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,False,parent.date)"  domain="[('type','&lt;&gt;','service')]"/>
                                 <field name="product_qty"/>
-                                <field name="product_uom"/>
+                                <field name="product_uom" on_change="onchange_uom(product_id, product_uom, context)"/>
                                 <group colspan="2" col="4">
                                 <field name="prod_lot_id" groups="base.group_extended"/>
                                     <button name="%(stock.action_view_stock_inventory_line_split)d"
@@ -1370,7 +1370,7 @@
                     <field name="partner_id"/>
                     <field name="product_id"/>
                     <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
-                    <field name="product_uom" string="UoM"/>
+                    <field name="product_uom" string="UoM" on_change="onchange_uom(product_id, product_uom, context)"/>
                     <field name="product_uos" groups="product.group_uos"/>
                     <button name="%(stock.move_scrap)d"
                         string="Scrap Products" type="action"
@@ -1413,7 +1413,7 @@
                     <group colspan="4" col="7">
                         <field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, False)"/>
                         <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
-                        <field name="product_uom" string="Unit Of Measure"/>
+                        <field name="product_uom" string="Unit Of Measure" on_change="onchange_uom(product_id, product_uom, context)"/>
                         <button name="%(stock.move_scrap)d" groups="base.group_extended"
                                 string="Scrap" type="action"
                                 icon="gtk-convert" context="{'scrap': True}"
@@ -1602,7 +1602,7 @@
                     <group colspan="4" col="7">
                         <field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, False)"/>
                         <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
-                        <field name="product_uom" string="Unit Of Measure"/>
+                        <field name="product_uom" string="Unit Of Measure" on_change="onchange_uom(product_id, product_uom, context)"/>
                         <button name="%(stock.move_scrap)d" groups="base.group_extended"
                                 string="Scrap" type="action"
                                 icon="gtk-convert" context="{'scrap': True}"

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to