[IMP] product: remove UoM constraint from product module and give it in stock and...
authorrsi-odoo <rsi@openerp.com>
Mon, 8 Sep 2014 12:57:37 +0000 (18:27 +0530)
committerRichard Mathot <rim@openerp.com>
Fri, 19 Sep 2014 13:23:52 +0000 (15:23 +0200)
Closes #2440

addons/account/product.py
addons/product/product.py
addons/stock/product.py
addons/stock/stock_demo.yml

index b7bffee..1562ff0 100644 (file)
@@ -20,6 +20,7 @@
 ##############################################################################
 
 from openerp.osv import fields, osv
+from openerp.tools.translate import _
 
 class product_category(osv.osv):
     _inherit = "product.category"
@@ -61,5 +62,12 @@ class product_template(osv.osv):
             help="This account will be used for invoices instead of the default one to value expenses for the current product."),
     }
 
+    def write(self, cr, uid, ids, vals, context=None):
+        if 'uom_po_id' in vals:
+            product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', 'in', ids)], context=context)
+            if self.pool.get('account.move.line').search(cr, uid, [('product_id', 'in', product_ids)], context=context, limit=1):
+                raise osv.except_osv(_('Error!'), _("You can not change the unit of measure of a product that has been already used in an account journal item. If you need to change the unit of measure, you may deactivate this product.") % ())
+        return super(product_template, self).write(cr, uid, ids, vals, context=context)
+
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
index cc8d1af..25ed44f 100644 (file)
@@ -697,12 +697,6 @@ class product_template(osv.osv):
         ''' Store the standard price change in order to be able to retrieve the cost of a product template for a given date'''
         if isinstance(ids, (int, long)):
             ids = [ids]
-        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(_('Unit of Measure categories Mismatch!'), _("New Unit of Measure '%s' must belong to same Unit of Measure category '%s' as of old Unit of Measure '%s'. If you need to change the unit of measure, you may deactivate this product from the 'Procurements' tab and create a new one.") % (new_uom.name, old_uom.category_id.name, old_uom.name,))
         if 'standard_price' in vals:
             for prod_template_id in ids:
                 self._set_standard_price(cr, uid, prod_template_id, vals['standard_price'], context=context)
index bb60b77..02e6e77 100644 (file)
@@ -442,6 +442,13 @@ class product_template(osv.osv):
             result['context'] = "{'tree_view_ref':'stock.view_move_tree'}"
         return result
 
+    def write(self, cr, uid, ids, vals, context=None):
+        if 'uom_po_id' in vals:
+            product_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', 'in', ids)], context=context)
+            if self.pool.get('stock.move').search(cr, uid, [('product_id', 'in', product_ids)], context=context, limit=1):
+                raise osv.except_osv(_('Error!'), _("You can not change the unit of measure of a product that has already been used in a stock move. If you need to change the unit of measure, you may deactivate this product.") % ())
+        return super(product_template, self).write(cr, uid, ids, vals, context=context)
+
 
 class product_removal_strategy(osv.osv):
     _name = 'product.removal'
index a9a4d64..4f72b66 100644 (file)
@@ -28,7 +28,6 @@
     list_price: 100.0
     standard_price: 70.0
     uom_id: product.product_uom_kgm
-    uom_po_id: product.product_uom_kgm
     property_stock_inventory: location_inventory
     description: Ice cream can be mass-produced and thus is widely available in developed parts of the world. Ice cream can be purchased in large cartons (vats and squrounds) from supermarkets and grocery stores, in smaller quantities from ice cream shops, convenience stores, and milk bars, and in individual servings from small carts or vans at public events.
 -