[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
This commit is contained in:
parent
c8f985e831
commit
9daa68e67c
|
@ -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',
|
'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):
|
def _check_model_name(self, cr, uid, ids, context=None):
|
||||||
for model in self.browse(cr, uid, ids):
|
for model in self.browse(cr, uid, ids, context=context):
|
||||||
if model.state=='manual':
|
if model.state=='manual':
|
||||||
if not model.model.startswith('x_'):
|
if not model.model.startswith('x_'):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -47,7 +47,7 @@ class ir_rule(osv.osv):
|
||||||
res[rule.id] = False
|
res[rule.id] = False
|
||||||
return res
|
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))
|
return not any(isinstance(self.pool.get(rule.model_id.model), osv.osv_memory) for rule in self.browse(cr, uid, ids, context))
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
|
|
@ -257,16 +257,6 @@ class ir_ui_menu(osv.osv):
|
||||||
return {}
|
return {}
|
||||||
return {'type': {'icon_pict': 'picture'}, 'value': {'icon_pict': ('stock', (icon,'ICON_SIZE_MENU'))}}
|
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):
|
def read_image(self, path):
|
||||||
path_info = path.split(',')
|
path_info = path.split(',')
|
||||||
icon_path = addons.get_module_resource(path_info[0],path_info[1])
|
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.')
|
return _('Error ! You can not create recursive Menu.')
|
||||||
|
|
||||||
_constraints = [
|
_constraints = [
|
||||||
(_check_recursion, _rec_message , ['parent_id'])
|
(osv.osv._check_recursion, _rec_message , ['parent_id'])
|
||||||
]
|
]
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'icon' : 'STOCK_OPEN',
|
'icon' : 'STOCK_OPEN',
|
||||||
|
|
|
@ -28,7 +28,7 @@ import netsvc
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def _check_xml(self, cr, uid, ids, context={}):
|
def _check_xml(self, cr, uid, ids, context=None):
|
||||||
logger = logging.getLogger('init')
|
logger = logging.getLogger('init')
|
||||||
for view in self.browse(cr, uid, ids, context):
|
for view in self.browse(cr, uid, ids, context):
|
||||||
eview = etree.fromstring(view.arch.encode('utf8'))
|
eview = etree.fromstring(view.arch.encode('utf8'))
|
||||||
|
|
|
@ -51,16 +51,6 @@ class res_partner_category(osv.osv):
|
||||||
res = self.name_get(cr, uid, ids, context=context)
|
res = self.name_get(cr, uid, ids, context=context)
|
||||||
return dict(res)
|
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'
|
_description='Partner Categories'
|
||||||
_name = 'res.partner.category'
|
_name = 'res.partner.category'
|
||||||
_columns = {
|
_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."),
|
'active' : fields.boolean('Active', help="The active field allows you to hide the category without removing it."),
|
||||||
}
|
}
|
||||||
_constraints = [
|
_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 = {
|
_defaults = {
|
||||||
'active' : lambda *a: 1,
|
'active' : lambda *a: 1,
|
||||||
|
@ -149,7 +139,7 @@ class res_partner(osv.osv):
|
||||||
def do_share(self, cr, uid, ids, *args):
|
def do_share(self, cr, uid, ids, *args):
|
||||||
return True
|
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',]):
|
for partner_o in pooler.get_pool(cr.dbname).get('res.partner').read(cr, uid, ids, ['ean13',]):
|
||||||
thisean=partner_o['ean13']
|
thisean=partner_o['ean13']
|
||||||
if thisean and thisean!='':
|
if thisean and thisean!='':
|
||||||
|
|
|
@ -184,16 +184,6 @@ class res_company(osv.osv):
|
||||||
except:
|
except:
|
||||||
return False
|
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):
|
def _get_logo(self, cr, uid, ids):
|
||||||
return open(os.path.join(
|
return open(os.path.join(
|
||||||
tools.config['root_path'], '..', 'pixmaps', 'openerp-header.png'),
|
tools.config['root_path'], '..', 'pixmaps', 'openerp-header.png'),
|
||||||
|
@ -280,7 +270,7 @@ class res_company(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
_constraints = [
|
_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()
|
res_company()
|
||||||
|
|
|
@ -4233,14 +4233,14 @@ class orm(orm_template):
|
||||||
cr.execute(query + "WHERE ID IN %s", (tuple(ids),))
|
cr.execute(query + "WHERE ID IN %s", (tuple(ids),))
|
||||||
return cr.fetchone()[0] == len(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!" % \
|
warnings.warn("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \
|
||||||
self._name, DeprecationWarning, stacklevel=3)
|
self._name, DeprecationWarning, stacklevel=3)
|
||||||
assert parent is None or parent in self._columns or parent in self._inherit_fields,\
|
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"
|
"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,
|
Verifies that there is no loop in a hierarchical structure of records,
|
||||||
by following the parent relationship using the **parent** field until a loop
|
by following the parent relationship using the **parent** field until a loop
|
||||||
|
|
Loading…
Reference in New Issue