From 2f835add55abac8c802a04cd37e4eff3ea40e4a6 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Mon, 24 Oct 2011 18:41:26 +0530 Subject: [PATCH 1/5] [Fix] Product :User can not change the existing UOM category ,Old Uom and New Uom category is same lp bug: https://launchpad.net/bugs/707287 fixed bzr revid: aag@tinyerp.com-20111024131126-0forf4jjmd3aj900 --- addons/product/product.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/addons/product/product.py b/addons/product/product.py index 7e7f7375e87..02563051e96 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -166,6 +166,17 @@ class product_uom(osv.osv): if value == 'reference': return {'value': {'factor': 1, 'factor_inv': 1}} return {} + + def write(self, cr, uid, ids, vals, context=None, update_check=True): + if context is None: + context={} + category_browse = self.browse(cr, uid,ids)[0] + old_category = category_browse.category_id + if 'category_id' in vals.keys(): + if vals['category_id'] <> old_category.id: + raise osv.except_osv(_('Warning'),_("User can not change the existing UOM category '%s' !! ") % (old_category.name,)) + res = super(product_uom, self).write(cr, uid, ids, vals, context=context) + return res product_uom() @@ -328,6 +339,20 @@ class product_template(osv.osv): return {'value': {'uom_po_id': uom_id}} return False + def write(self, cr, uid, ids, vals, context=None, update_check=True): + if context is None: + context={} + product = self.pool.get('product.product') + uom_obj = self.pool.get('product.uom') + product_uom1 = product.browse(cr, uid, ids)[0] + category_1 = uom_obj.browse(cr, uid, product_uom1.uom_id.id).category_id + if 'uom_po_id' in vals.keys(): + category_2 = uom_obj.browse(cr, uid, vals['uom_po_id']).category_id + if category_1.id != category_2.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 ") % (category_1.name,category_2.name,)) + res = super(product_template, self).write(cr, uid, ids, vals, context=context) + return res + _defaults = { 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'product.template', context=c), 'list_price': lambda *a: 1, From 8589389073fd67d850b48e8d23014c4fb419b013 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Mon, 31 Oct 2011 18:15:47 +0530 Subject: [PATCH 2/5] [IMP]: Optimize code bzr revid: aag@tinyerp.com-20111031124547-iogcam738ttvgsxa --- addons/product/product.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 02563051e96..76a12bc35bd 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -342,14 +342,13 @@ class product_template(osv.osv): def write(self, cr, uid, ids, vals, context=None, update_check=True): if context is None: context={} - product = self.pool.get('product.product') uom_obj = self.pool.get('product.uom') - product_uom1 = product.browse(cr, uid, ids)[0] - category_1 = uom_obj.browse(cr, uid, product_uom1.uom_id.id).category_id + product_obj = self.browse(cr, uid, ids)[0] + old_category = product_obj.uom_id.category_id if 'uom_po_id' in vals.keys(): - category_2 = uom_obj.browse(cr, uid, vals['uom_po_id']).category_id - if category_1.id != category_2.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 ") % (category_1.name,category_2.name,)) + 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 From aa6badc3f89b63a12630b241fa6756d980528d06 Mon Sep 17 00:00:00 2001 From: "Rucha (Open ERP)" Date: Thu, 3 Nov 2011 16:15:21 +0530 Subject: [PATCH 3/5] [REF]: product: Code improvement in write() of product uom bzr revid: rpa@tinyerp.com-20111103104521-ig8yt4ize3vtci35 --- addons/product/product.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 76a12bc35bd..5ade648cef8 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -167,16 +167,12 @@ class product_uom(osv.osv): return {'value': {'factor': 1, 'factor_inv': 1}} return {} - def write(self, cr, uid, ids, vals, context=None, update_check=True): - if context is None: - context={} - category_browse = self.browse(cr, uid,ids)[0] - old_category = category_browse.category_id - if 'category_id' in vals.keys(): - if vals['category_id'] <> old_category.id: - raise osv.except_osv(_('Warning'),_("User can not change the existing UOM category '%s' !! ") % (old_category.name,)) - res = super(product_uom, self).write(cr, uid, ids, vals, context=context) - return res + def write(self, cr, uid, ids, vals, context=None): + if 'category_id' in vals: + for uom in self.browse(cr, uid, ids, context=context): + if uom.category_id != vals['category_id']: + raise osv.except_osv(_('Warning'),_("Cannot change the category of existing UoM '%s'.") % (uom.name,)) + return super(product_uom, self).write(cr, uid, ids, vals, context=context) product_uom() From 9181f7649e4aa15ab8f04c803ad2f80444cc0953 Mon Sep 17 00:00:00 2001 From: "Rucha (Open ERP)" Date: Thu, 3 Nov 2011 16:48:41 +0530 Subject: [PATCH 4/5] [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 --- addons/product/product.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 5ade648cef8..a5e56118026 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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), From 944f20c027d5df0ecd2c2349162166ca263f61d0 Mon Sep 17 00:00:00 2001 From: "Atik Agewan (OpenERP)" Date: Fri, 4 Nov 2011 15:25:28 +0530 Subject: [PATCH 5/5] [IMP] Product:Improvement in write method bzr revid: aag@tinyerp.com-20111104095528-mvtx2gm4nomy279l --- addons/product/product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index a5e56118026..99e61915a7b 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -335,10 +335,10 @@ class product_template(osv.osv): return {'value': {'uom_po_id': uom_id}} return False - def write(self, cr, uid, ids, vals, context=None, update_check=True): + def write(self, cr, uid, ids, vals, context=None): 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): - 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,))