diff --git a/addons/account/product.py b/addons/account/product.py index b7bffee43a9a2aa46dd6d9e9db76175affd06657..1562ff0069589a7ef1cb0461d6940b3860c1ac2d 100644 --- a/addons/account/product.py +++ b/addons/account/product.py @@ -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: diff --git a/addons/product/product.py b/addons/product/product.py index cc8d1affb3ab2b2f6018e11095d2c4ab6fcd5900..25ed44ffd73a0c604d5ef748c6ebc637f2becd52 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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) diff --git a/addons/stock/product.py b/addons/stock/product.py index bb60b77ba1da552b5006c6a3f9eed1e8add88684..02e6e773e057ab9c8ed23cee684caf3d538986d0 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -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' diff --git a/addons/stock/stock_demo.yml b/addons/stock/stock_demo.yml index a9a4d64c5649a01071eaefbe3a4e4fb7131559b9..4f72b66982fa0ba5519e2e10664309c2b9596dbe 100644 --- a/addons/stock/stock_demo.yml +++ b/addons/stock/stock_demo.yml @@ -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. -