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

Requested reviews:
  Ravi Gohil (OpenERP) (rgo-openerp)
  Naresh(OpenERP) (nch-openerp)

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

Hello,

If we just created a product and saved it, it is impossible to change the unit 
of the product with the unit which has other category than current unit's 
category.

Fix has been back-ported from the trunk branch: 
lp:~openerp-dev/openobject-addons/trunk-bug-894648-amp.

Kindly review the fix.

Thanks.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-576033-rgo/+merge/120982
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-576033-rgo.
=== modified file 'product/product.py'
--- product/product.py	2012-04-03 13:05:28 +0000
+++ product/product.py	2012-08-23 12:55:19 +0000
@@ -354,15 +354,6 @@
             return {'value': {'uom_po_id': uom_id}}
         return {}
 
-    def write(self, cr, uid, ids, vals, context=None):
-        if 'uom_po_id' in vals:
-            new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
-            for product in self.browse(cr, uid, ids, context=context):
-                old_uom = product.uom_po_id
-                if old_uom.category_id.id != new_uom.category_id.id:
-                    raise osv.except_osv(_('UoM categories Mismatch!'), _("New UoM '%s' must belong to same UoM category '%s' as of old UoM '%s'. If you need to change the unit of measure, you may desactivate this product from the 'Procurement & Locations' tab and create a new one.") % (new_uom.name, old_uom.category_id.name, old_uom.name,))
-        return super(product_template, self).write(cr, uid, ids, vals, context=context)
-
     _defaults = {
         'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'product.template', context=c),
         'list_price': lambda *a: 1,

=== modified file 'stock/product.py'
--- stock/product.py	2012-06-19 07:40:07 +0000
+++ stock/product.py	2012-08-23 12:55:19 +0000
@@ -493,6 +493,16 @@
                  "there is a specific valuation account set on the destination location. When not set on the product, the one from the product category is used."),
     }
 
+    def write(self, cr, uid, ids, vals, context=None):
+        if 'uom_po_id' in vals:
+            new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
+            product_move = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', ids[0])])
+            for product in self.browse(cr, uid, ids, context=context):
+                old_uom = product.uom_po_id
+                if old_uom.category_id.id != new_uom.category_id.id and product_move:
+                    raise osv.except_osv(_('UoM categories Mismatch!'), _("Product's new UoM '%s' must belong to same UoM category '%s' as of old UoM '%s'.Because product %s 's stock move is already created'") % (new_uom.name, old_uom.category_id.name, old_uom.name, product.name))
+        return super(product_template, self).write(cr, uid, ids, vals, context=context)
+
 product_template()
 
 class product_category(osv.osv):

_______________________________________________
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