[REF]: product: Code improvement in write() of product to restrict changing UoM so that you cannot change the UoM if its NOT in the same UoM Category than before

bzr revid: rpa@tinyerp.com-20111103111841-ewmmmpoxcuconvjr
This commit is contained in:
Rucha (Open ERP) 2011-11-03 16:48:41 +05:30
parent aa6badc3f8
commit 9181f7649e
1 changed files with 7 additions and 11 deletions

View File

@ -336,17 +336,13 @@ class product_template(osv.osv):
return False
def write(self, cr, uid, ids, vals, context=None, update_check=True):
if context is None:
context={}
uom_obj = self.pool.get('product.uom')
product_obj = self.browse(cr, uid, ids)[0]
old_category = product_obj.uom_id.category_id
if 'uom_po_id' in vals.keys():
new_category = uom_obj.browse(cr, uid, vals['uom_po_id']).category_id
if old_category.id != new_category.id:
raise osv.except_osv(_('UOM categories Mismatch !'),_("You can not change the UoM/Purchase UoM category from '%s' to '%s' ! \n Old UoM And New UoM should be belongs to same category ") % (old_category.name,new_category.name,))
res = super(product_template, self).write(cr, uid, ids, vals, context=context)
return res
if 'uom_po_id' in vals:
for product in self.browse(cr, uid, ids, context=context):
new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
old_uom = product.uom_po_id
if old_uom.category_id.id != new_uom.category_id.id:
raise osv.except_osv(_('UoM categories Mismatch!'), _("New UoM '%s' must belongs to same UoM category '%s' as of old UoM '%s'.") % (new_uom.name, old_uom.category_id.name, old_uom.name,))
return super(product_template, self).write(cr, uid, ids, vals, context=context)
_defaults = {
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'product.template', context=c),