diff options
| author | Olivier Dony <odo@openerp.com> | 2010-12-09 11:57:33 +0100 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2010-12-09 11:57:33 +0100 |
| commit | 9daa68e67c17efbac26ece2a9e9d19df14ac439a (patch) | |
| tree | 2ace4dab3f8483a67b3fa955a3c45b8d329eec9f /bin/addons/base | |
| parent | c8f985e83195c3d037b17333a7b180e453b3029a (diff) | |
[IMP] orm,base: added context to _constraints functions + use generic osv.osv.check_recursion()
lp bug: https://launchpad.net/bugs/525808 fixed
bzr revid: odo@openerp.com-20101209105733-j3uffwp4rl07nzc4
Diffstat (limited to 'bin/addons/base')
| -rw-r--r-- | bin/addons/base/ir/ir_model.py | 4 | ||||
| -rw-r--r-- | bin/addons/base/ir/ir_rule.py | 2 | ||||
| -rw-r--r-- | bin/addons/base/ir/ir_ui_menu.py | 12 | ||||
| -rw-r--r-- | bin/addons/base/ir/ir_ui_view.py | 2 | ||||
| -rw-r--r-- | bin/addons/base/res/partner/partner.py | 14 | ||||
| -rw-r--r-- | bin/addons/base/res/res_company.py | 12 |
6 files changed, 8 insertions, 38 deletions
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() |
