diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index 583985b5930..80a24a45720 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -81,8 +81,8 @@ class ir_model(osv.osv): 'state': lambda self,cr,uid,ctx=None: (ctx and ctx.get('manual',False)) and 'manual' or 'base', } - def _check_model_name(self, cr, uid, ids): - for model in self.browse(cr, uid, ids): + def _check_model_name(self, cr, uid, ids, context=None): + for model in self.browse(cr, uid, ids, context=context): if model.state=='manual': if not model.model.startswith('x_'): return False diff --git a/bin/addons/base/ir/ir_rule.py b/bin/addons/base/ir/ir_rule.py index 657dc65a12a..f75528f6d47 100644 --- a/bin/addons/base/ir/ir_rule.py +++ b/bin/addons/base/ir/ir_rule.py @@ -47,7 +47,7 @@ class ir_rule(osv.osv): res[rule.id] = False return res - def _check_model_obj(self, cr, uid, ids, context={}): + def _check_model_obj(self, cr, uid, ids, context=None): return not any(isinstance(self.pool.get(rule.model_id.model), osv.osv_memory) for rule in self.browse(cr, uid, ids, context)) _columns = { diff --git a/bin/addons/base/ir/ir_ui_menu.py b/bin/addons/base/ir/ir_ui_menu.py index 43a5cb5bf76..800a3ede95a 100644 --- a/bin/addons/base/ir/ir_ui_menu.py +++ b/bin/addons/base/ir/ir_ui_menu.py @@ -257,16 +257,6 @@ class ir_ui_menu(osv.osv): return {} return {'type': {'icon_pict': 'picture'}, 'value': {'icon_pict': ('stock', (icon,'ICON_SIZE_MENU'))}} - def _check_recursion(self, cr, uid, ids): - level = 100 - while len(ids): - cr.execute('select distinct parent_id from ir_ui_menu where id IN %s',(tuple(ids),)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - def read_image(self, path): path_info = path.split(',') icon_path = addons.get_module_resource(path_info[0],path_info[1]) @@ -318,7 +308,7 @@ class ir_ui_menu(osv.osv): return _('Error ! You can not create recursive Menu.') _constraints = [ - (_check_recursion, _rec_message , ['parent_id']) + (osv.osv._check_recursion, _rec_message , ['parent_id']) ] _defaults = { 'icon' : 'STOCK_OPEN', diff --git a/bin/addons/base/ir/ir_ui_view.py b/bin/addons/base/ir/ir_ui_view.py index 4c90e85a35c..059d441e245 100644 --- a/bin/addons/base/ir/ir_ui_view.py +++ b/bin/addons/base/ir/ir_ui_view.py @@ -28,7 +28,7 @@ import netsvc import os import logging -def _check_xml(self, cr, uid, ids, context={}): +def _check_xml(self, cr, uid, ids, context=None): logger = logging.getLogger('init') for view in self.browse(cr, uid, ids, context): eview = etree.fromstring(view.arch.encode('utf8')) diff --git a/bin/addons/base/res/partner/partner.py b/bin/addons/base/res/partner/partner.py index 8318a7602bf..04d5547973b 100644 --- a/bin/addons/base/res/partner/partner.py +++ b/bin/addons/base/res/partner/partner.py @@ -51,16 +51,6 @@ class res_partner_category(osv.osv): res = self.name_get(cr, uid, ids, context=context) return dict(res) - def _check_recursion(self, cr, uid, ids): - level = 100 - while len(ids): - cr.execute('select distinct parent_id from res_partner_category where id IN %s',(tuple(ids),)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - _description='Partner Categories' _name = 'res.partner.category' _columns = { @@ -71,7 +61,7 @@ class res_partner_category(osv.osv): 'active' : fields.boolean('Active', help="The active field allows you to hide the category without removing it."), } _constraints = [ - (_check_recursion, 'Error ! You can not create recursive categories.', ['parent_id']) + (osv.osv._check_recursion, 'Error ! You can not create recursive categories.', ['parent_id']) ] _defaults = { 'active' : lambda *a: 1, @@ -149,7 +139,7 @@ class res_partner(osv.osv): def do_share(self, cr, uid, ids, *args): return True - def _check_ean_key(self, cr, uid, ids): + def _check_ean_key(self, cr, uid, ids, context=None): for partner_o in pooler.get_pool(cr.dbname).get('res.partner').read(cr, uid, ids, ['ean13',]): thisean=partner_o['ean13'] if thisean and thisean!='': diff --git a/bin/addons/base/res/res_company.py b/bin/addons/base/res/res_company.py index 098d8b9b50e..7361d1871d3 100644 --- a/bin/addons/base/res/res_company.py +++ b/bin/addons/base/res/res_company.py @@ -184,16 +184,6 @@ class res_company(osv.osv): except: return False - def _check_recursion(self, cr, uid, ids): - level = 100 - while len(ids): - cr.execute('select distinct parent_id from res_company where id IN %s',(tuple(ids),)) - ids = filter(None, map(lambda x:x[0], cr.fetchall())) - if not level: - return False - level -= 1 - return True - def _get_logo(self, cr, uid, ids): return open(os.path.join( tools.config['root_path'], '..', 'pixmaps', 'openerp-header.png'), @@ -280,7 +270,7 @@ class res_company(osv.osv): } _constraints = [ - (_check_recursion, 'Error! You can not create recursive companies.', ['parent_id']) + (osv.osv._check_recursion, 'Error! You can not create recursive companies.', ['parent_id']) ] res_company() diff --git a/bin/osv/orm.py b/bin/osv/orm.py index b66aa390e57..84b95d31661 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -4233,14 +4233,14 @@ class orm(orm_template): cr.execute(query + "WHERE ID IN %s", (tuple(ids),)) return cr.fetchone()[0] == len(ids) - def check_recursion(self, cr, uid, ids, parent=None): + def check_recursion(self, cr, uid, ids, context=None, parent=None): warnings.warn("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \ self._name, DeprecationWarning, stacklevel=3) assert parent is None or parent in self._columns or parent in self._inherit_fields,\ "The 'parent' parameter passed to check_recursion() must be None or a valid field name" - return self._check_recursion(cr, uid, ids, parent) + return self._check_recursion(cr, uid, ids, context, parent) - def _check_recursion(self, cr, uid, ids, parent=None): + def _check_recursion(self, cr, uid, ids, context=None, parent=None): """ Verifies that there is no loop in a hierarchical structure of records, by following the parent relationship using the **parent** field until a loop