From bf922b150222fe67f40d12a07d8672c1e3a109bc Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 19 Nov 2014 12:41:25 +0100 Subject: [PATCH] [IMP] When no stock moves, change whatever you want, otherwise no change at all for UoM. #3440 Enhancement request richard-willowit The default UoM can only be changed when there are no stock moves (or only cancelled ones), but to any category. The purchase UoM can be changed whenever you want, but has to be in the same category as the default UoM. Closes #3440 [IMP] When no stock moves, change whatever you want, otherwise no change at all for UoM. #3440 Enhancement request richard-willowit [FIX] Remove line [FIX] Constraint should be applied when UoM or PO UoM is changed --- addons/product/product.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/product/product.py b/addons/product/product.py index fa35591c0b4..9025f46602f 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -715,6 +715,13 @@ 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_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', '!=', 'cancel')], context=context): + raise osv.except_osv(_('Unit of Measure can not be changed anymore!'), _("As there are existing stock moves of this product, you can not change the Unit of Measurement anymore. ")) 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) @@ -767,7 +774,7 @@ class product_template(osv.osv): return True _constraints = [ - (_check_uom, 'Error: The default Unit of Measure and the purchase Unit of Measure must be in the same category.', ['uom_id']), + (_check_uom, 'Error: The default Unit of Measure and the purchase Unit of Measure must be in the same category.', ['uom_id', 'uom_po_id']), ] def name_get(self, cr, user, ids, context=None):