From e9097e14acf2ce76ae47f4150ef86aea9d283294 Mon Sep 17 00:00:00 2001 From: "Rucha (Open ERP)" Date: Mon, 14 Feb 2011 17:29:43 +0530 Subject: [PATCH] [MREGE]: Merge with lp:~openerp-commiter/openobject-addons/dev-addons2-rha1 bzr revid: rpa@tinyerp.com-20110214115943-p9ss7bn09sj0ift1 --- addons/mrp/mrp.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 3ba8d4bde47..ac392f6565b 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -240,10 +240,28 @@ class mrp_bom(osv.osv): return False level -= 1 return True - _constraints = [ - (_check_recursion, 'Error ! You can not create recursive BoM.', ['parent_id']) - ] + def _check_product(self, cr, uid, ids, context=None): + all_prod = [] + bom_obj = self.pool.get('mrp.bom') + boms = self.browse(cr, uid, ids, context=context) + def check_bom(boms): + res = True + for bom in boms: + if bom.product_id.id in all_prod: + res = res and False + all_prod.append(bom.product_id.id) + lines = bom.bom_lines + if lines: + newboms = [a for a in lines if a not in boms] + res = res and check_bom(newboms) + return res + return check_bom(boms) + + _constraints = [ + (_check_recursion, 'Error ! You can not create recursive BoM.', ['parent_id']), + (_check_product, 'BoM line product should not be same as BoM product.', ['product_id']), + ] def onchange_product_id(self, cr, uid, ids, product_id, name, context=None): """ Changes UoM and name if product_id changes.