Skip to content
Snippets Groups Projects
Commit 9bc712b0 authored by Olivier Dony's avatar Olivier Dony
Browse files

[REV] product: rev. 42f51140 needs further review

Incorrect use of stock.move in product module + needs review.

This reverts commit 42f51140:
"[IMP] When no stock moves, change whatever you want, otherwise no change at all for UoM.  #3440 Enhancement request richard-willowit"
parent 42f51140
No related branches found
No related tags found
No related merge requests found
...@@ -728,13 +728,12 @@ class product_template(osv.osv): ...@@ -728,13 +728,12 @@ 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''' ''' 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)): if isinstance(ids, (int, long)):
ids = [ids] ids = [ids]
if 'uom_id' in vals: if 'uom_po_id' in vals:
new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_id'], context=context) 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): for product in self.browse(cr, uid, ids, context=context):
old_uom = product.uom_id old_uom = product.uom_po_id
if old_uom != new_uom: if old_uom.category_id.id != new_uom.category_id.id:
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 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,))
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: if 'standard_price' in vals:
for prod_template_id in ids: for prod_template_id in ids:
self._set_standard_price(cr, uid, prod_template_id, vals['standard_price'], context=context) self._set_standard_price(cr, uid, prod_template_id, vals['standard_price'], context=context)
...@@ -786,7 +785,7 @@ class product_template(osv.osv): ...@@ -786,7 +785,7 @@ class product_template(osv.osv):
return True return True
_constraints = [ _constraints = [
(_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']), (_check_uom, 'Error: The default Unit of Measure and the purchase Unit of Measure must be in the same category.', ['uom_id']),
] ]
def name_get(self, cr, user, ids, context=None): def name_get(self, cr, user, ids, context=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment