From 0ec704f8ec72cc256d63c60c3d91002b0ddd1e52 Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Tue, 23 Jun 2015 11:55:30 +0200 Subject: [PATCH] [FIX] stock: UoM of a product should not be changed when done stock moves exist. Backport from saas-6 (242a76cc979c3fc237d9e3c44ad18361b33a0d98) Closes #7224 opw-643168 --- addons/stock/product.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/stock/product.py b/addons/stock/product.py index f0863e7ef96..1a302801e1d 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -24,6 +24,7 @@ from openerp.tools.translate import _ from openerp.tools.safe_eval import safe_eval as eval import openerp.addons.decimal_precision as dp from openerp.tools.float_utils import float_round +from openerp.exceptions import except_orm class product_product(osv.osv): _inherit = "product.product" @@ -482,6 +483,16 @@ 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_id' in vals: + new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_id'], context=context) + for product in self.browse(cr, uid, ids, context=context): + old_uom = product.uom_id + if old_uom != new_uom: + if self.pool.get('stock.move').search(cr, uid, [('product_id', 'in', [x.id for x in product.product_variant_ids]), ('state', '=', 'done')], limit=1, context=context): + raise except_orm(_('Warning'), _("You can not change the unit of measure of a product that has already been used in a done 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'