← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-782149-ron into lp:openobject-addons

 

Rohan Nayani(Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-782149-ron into lp:openobject-addons.

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #782149 in OpenERP Addons: "[PS] Wrong calculated price in a PO when the Supplier UoM is different than the Purchase UoM"
  https://bugs.launchpad.net/openobject-addons/+bug/782149

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-782149-ron/+merge/61519
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-782149-ron/+merge/61519
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-782149-ron.
=== modified file 'purchase/purchase.py'
--- purchase/purchase.py	2011-04-26 07:39:18 +0000
+++ purchase/purchase.py	2011-05-19 09:29:26 +0000
@@ -655,7 +655,9 @@
 
     def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom,
             partner_id, date_order=False, fiscal_position=False, date_planned=False,
-            name=False, price_unit=False, notes=False):
+            name=False, price_unit=False, notes=False, context=None):
+        if context is None:
+            context={}
         if not pricelist:
             raise osv.except_osv(_('No Pricelist !'), _('You have to select a pricelist or a supplier in the purchase form !\nPlease set one before choosing a product.'))
         if not  partner_id:
@@ -669,11 +671,15 @@
         lang=False
         if partner_id:
             lang=self.pool.get('res.partner').read(cr, uid, partner_id, ['lang'])['lang']
-        context={'lang':lang}
+        context['lang'] = lang
         context['partner_id'] = partner_id
 
         prod = self.pool.get('product.product').browse(cr, uid, product, context=context)
         prod_uom_po = prod.uom_po_id.id
+
+        if uom and prod:
+            if uom <> prod_uom_po:
+                uom = prod_uom_po
         if not uom:
             uom = prod_uom_po
         if not date_order:
@@ -698,6 +704,9 @@
                 if qty < temp_qty: # If the supplier quantity is greater than entered from user, set minimal.
                     qty = temp_qty
                     res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s, you cannot purchase less.') % qty}})
+
+        if 'uom_change' in context:
+            uom = context['uom_change']
         qty_in_product_uom = product_uom_pool._compute_qty(cr, uid, uom, qty, to_uom_id=prod.uom_id.id)
         price = self.pool.get('product.pricelist').price_get(cr,uid,[pricelist],
                     product, qty_in_product_uom or 1.0, partner_id, {
@@ -711,7 +720,7 @@
             'taxes_id':map(lambda x: x.id, prod.supplier_taxes_id),
             'date_planned': date_planned or dt,'notes': notes or prod.description_purchase,
             'product_qty': qty,
-            'product_uom': prod.uom_id.id}})
+            'product_uom': uom or prod_uom_po}})
         domain = {}
 
         taxes = self.pool.get('account.tax').browse(cr, uid,map(lambda x: x.id, prod.supplier_taxes_id))
@@ -731,7 +740,7 @@
             name=False, price_unit=False, notes=False):
         res = self.product_id_change(cr, uid, ids, pricelist, product, qty, uom,
                 partner_id, date_order=date_order, fiscal_position=fiscal_position, date_planned=date_planned,
-            name=name, price_unit=price_unit, notes=notes)
+            name=name, price_unit=price_unit, notes=notes, context={'uom_change': uom})
         if 'product_uom' in res['value']:
             if uom and (uom != res['value']['product_uom']) and res['value']['product_uom']:
                 seller_uom_name = self.pool.get('product.uom').read(cr, uid, [res['value']['product_uom']], ['name'])[0]['name']