[FIX] sale/purchase: invert check - simplify forcing product's UoM only when changing...
authorXavier ALT <xal@openerp.com>
Tue, 9 Oct 2012 11:06:00 +0000 (13:06 +0200)
committerXavier ALT <xal@openerp.com>
Tue, 9 Oct 2012 11:06:00 +0000 (13:06 +0200)
bzr revid: xal@openerp.com-20121009110600-0d19szr59l2a0pw4

addons/purchase/purchase.py
addons/purchase/purchase_view.xml
addons/sale/sale.py
addons/sale/sale_view.xml

index 918cc54..2cb8429 100644 (file)
@@ -703,9 +703,6 @@ class purchase_order_line(osv.osv):
         """
         onchange handler of product_uom.
         """
-        if context is None:
-            context = {}
-        context = dict(context, uom_change=True)
         if not uom_id:
             return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False}}
         return self.onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id,
@@ -733,10 +730,9 @@ class purchase_order_line(osv.osv):
         """
         onchange handler of product_id.
 
-        :param dict context: 'uom_change' key in context override default onchange
-                             behaviour which force product's UoM, allowing to
-                             specify an 'uom_id' of the same category as product's
-                             UoM (ex: set when called from product_uom's onchange).
+        :param dict context: 'force_product_uom' key in context override
+                             default onchange behaviour to force using the UoM
+                             defined on the provided product
         """
         if context is None:
             context = {}
@@ -770,7 +766,7 @@ class purchase_order_line(osv.osv):
 
         # - check that uom and product uom belong to the same category
         product_uom_po_id = product.uom_po_id.id
-        if not uom_id or not context.get('uom_change'):
+        if not uom_id or context.get('force_product_uom'):
             uom_id = product_uom_po_id
         
         if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id:
index 1c93605..88d92af 100644 (file)
                 <form string="Purchase Order Line">
                     <notebook colspan="4">
                         <page string="Order Line">
-                            <field name="product_id" colspan="4" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)" required="1"/>
+                            <field name="product_id" colspan="4" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)" required="1" context="{'force_product_uom': True}"/>
                             <field name="product_qty" on_change="onchange_product_id(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id,parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)"/>
                             <field name="product_uom" on_change="onchange_product_uom(parent.pricelist_id,product_id,product_qty,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,notes,context)"/>
                             <field colspan="4" name="name"/>
index 064ae7d..7d35ec7 100644 (file)
@@ -1192,11 +1192,9 @@ class sale_order_line(osv.osv):
         """
         onchange handler for product_id.
 
-        :param dict context: 'uom_change' key in context override default onchange
-                             behaviour which force product's UoM, allowing to
-                             specify an 'uom_id' of the same category as product's
-                             UoM (ex: set when called from product_uom's onchange).
-
+        :param dict context: 'force_product_uom' key in context override
+                             default onchange behaviour to force using the UoM
+                             defined on the provided product
         """
         if context is None:
             context = {}
@@ -1227,7 +1225,7 @@ class sale_order_line(osv.osv):
         uom2 = False
         if uom:
             uom2 = product_uom_obj.browse(cr, uid, uom, context=context)
-            if product_obj.uom_id.category_id.id != uom2.category_id.id or not context.get('uom_change',False):
+            if product_obj.uom_id.category_id.id != uom2.category_id.id or context.get('force_product_uom'):
                 uom = False
                 uom2 = False
         if uos:
@@ -1321,7 +1319,6 @@ class sale_order_line(osv.osv):
         if context is None:
             context = {}
         lang = lang or context.get('lang',False)
-        context = dict(context, uom_change=True)
         res = self.product_id_change(cursor, user, ids, pricelist, product,
                 qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
                 partner_id=partner_id, lang=lang, update_tax=update_tax,
index 90d3838..9f10928 100644 (file)
                                         <page string="Order Line">
                                         <group colspan="4" col="5">
                                             <field colspan="3"
-                                                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
+                                                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom, 'force_product_uom': True}"
                                                 name="product_id"
                                                 on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, True, parent.date_order, product_packaging, parent.fiscal_position, False, context)"/>
                                             <field name="name"/>