[IMP] replace all tests like 'registry.get(X)' by 'X in registry' where X is non static

bzr revid: rco@openerp.com-20130329140723-dnrl02saky570xg0
This commit is contained in:
Raphael Collet 2013-03-29 15:07:23 +01:00
parent d3657d858f
commit 09be864f1d
21 changed files with 170 additions and 176 deletions

View File

@ -185,9 +185,9 @@ class act_window(osv.osv):
def _check_model(self, cr, uid, ids, context=None): def _check_model(self, cr, uid, ids, context=None):
for action in self.browse(cr, uid, ids, context): for action in self.browse(cr, uid, ids, context):
if not self.pool.get(action.res_model): if action.res_model not in self.pool:
return False return False
if action.src_model and not self.pool.get(action.src_model): if action.src_model and action.src_model not in self.pool:
return False return False
return True return True
@ -530,7 +530,7 @@ class actions_server(osv.osv):
} }
def get_email(self, cr, uid, action, context): def get_email(self, cr, uid, action, context):
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool[action.model_id.model]
id = context.get('active_id') id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id) obj = obj_pool.browse(cr, uid, id)
@ -550,7 +550,7 @@ class actions_server(osv.osv):
return obj return obj
def get_mobile(self, cr, uid, action, context): def get_mobile(self, cr, uid, action, context):
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool[action.model_id.model]
id = context.get('active_id') id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id) obj = obj_pool.browse(cr, uid, id)
@ -574,7 +574,7 @@ class actions_server(osv.osv):
context = {} context = {}
def merge(match): def merge(match):
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool[action.model_id.model]
id = context.get('active_id') id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id) obj = obj_pool.browse(cr, uid, id)
exp = str(match.group()[2:-2]).strip() exp = str(match.group()[2:-2]).strip()
@ -607,7 +607,7 @@ class actions_server(osv.osv):
user = self.pool.get('res.users').browse(cr, uid, uid) user = self.pool.get('res.users').browse(cr, uid, uid)
for action in self.browse(cr, uid, ids, context): for action in self.browse(cr, uid, ids, context):
obj = None obj = None
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool[action.model_id.model]
if context.get('active_model') == action.model_id.model and context.get('active_id'): if context.get('active_model') == action.model_id.model and context.get('active_id'):
obj = obj_pool.browse(cr, uid, context['active_id'], context=context) obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
cxt = { cxt = {
@ -628,8 +628,7 @@ class actions_server(osv.osv):
if action.state=='client_action': if action.state=='client_action':
if not action.action_id: if not action.action_id:
raise osv.except_osv(_('Error'), _("Please specify an action to launch !")) raise osv.except_osv(_('Error'), _("Please specify an action to launch !"))
return self.pool.get(action.action_id.type)\ return self.pool[action.action_id.type].read(cr, uid, action.action_id.id, context=context)
.read(cr, uid, action.action_id.id, context=context)
if action.state=='code': if action.state=='code':
eval(action.code, cxt, mode="exec", nocopy=True) # nocopy allows to return 'action' eval(action.code, cxt, mode="exec", nocopy=True) # nocopy allows to return 'action'
@ -708,16 +707,16 @@ class actions_server(osv.osv):
if not action.write_id: if not action.write_id:
if not action.srcmodel_id: if not action.srcmodel_id:
obj_pool = self.pool.get(action.model_id.model) obj_pool = self.pool[action.model_id.model]
obj_pool.write(cr, uid, [context.get('active_id')], res) obj_pool.write(cr, uid, [context.get('active_id')], res)
else: else:
write_id = context.get('active_id') write_id = context.get('active_id')
obj_pool = self.pool.get(action.srcmodel_id.model) obj_pool = self.pool[action.srcmodel_id.model]
obj_pool.write(cr, uid, [write_id], res) obj_pool.write(cr, uid, [write_id], res)
elif action.write_id: elif action.write_id:
obj_pool = self.pool.get(action.srcmodel_id.model) obj_pool = self.pool[action.srcmodel_id.model]
rec = self.pool.get(action.model_id.model).browse(cr, uid, context.get('active_id')) rec = self.pool[action.model_id.model].browse(cr, uid, context.get('active_id'))
id = eval(action.write_id, {'object': rec}) id = eval(action.write_id, {'object': rec})
try: try:
id = int(id) id = int(id)
@ -739,10 +738,10 @@ class actions_server(osv.osv):
expr = exp.value expr = exp.value
res[exp.col1.name] = expr res[exp.col1.name] = expr
obj_pool = self.pool.get(action.srcmodel_id.model) obj_pool = self.pool[action.srcmodel_id.model]
res_id = obj_pool.create(cr, uid, res) res_id = obj_pool.create(cr, uid, res)
if action.record_id: if action.record_id:
self.pool.get(action.model_id.model).write(cr, uid, [context.get('active_id')], {action.record_id.name:res_id}) self.pool[action.model_id.model].write(cr, uid, [context.get('active_id')], {action.record_id.name:res_id})
if action.state == 'object_copy': if action.state == 'object_copy':
res = {} res = {}
@ -756,7 +755,7 @@ class actions_server(osv.osv):
model = action.copy_object.split(',')[0] model = action.copy_object.split(',')[0]
cid = action.copy_object.split(',')[1] cid = action.copy_object.split(',')[1]
obj_pool = self.pool.get(model) obj_pool = self.pool[model]
obj_pool.copy(cr, uid, int(cid), res) obj_pool.copy(cr, uid, int(cid), res)
return False return False
@ -813,7 +812,7 @@ Launch Manually Once: after having been launched manually, it sets automatically
# Load action # Load action
act_type = self.pool.get('ir.actions.actions').read(cr, uid, wizard.action_id.id, ['type'], context=context) act_type = self.pool.get('ir.actions.actions').read(cr, uid, wizard.action_id.id, ['type'], context=context)
res = self.pool.get(act_type['type']).read(cr, uid, wizard.action_id.id, [], context=context) res = self.pool[act_type['type']].read(cr, uid, wizard.action_id.id, [], context=context)
if act_type['type'] != 'ir.actions.act_window': if act_type['type'] != 'ir.actions.act_window':
return res return res
res.setdefault('context','{}') res.setdefault('context','{}')

View File

@ -50,7 +50,7 @@ class ir_attachment(osv.osv):
model_object = attachment.res_model model_object = attachment.res_model
res_id = attachment.res_id res_id = attachment.res_id
if model_object and res_id: if model_object and res_id:
model_pool = self.pool.get(model_object) model_pool = self.pool[model_object]
res = model_pool.name_get(cr,uid,[res_id],context) res = model_pool.name_get(cr,uid,[res_id],context)
res_name = res and res[0][1] or False res_name = res and res[0][1] or False
if res_name: if res_name:
@ -205,9 +205,9 @@ class ir_attachment(osv.osv):
for model, mids in res_ids.items(): for model, mids in res_ids.items():
# ignore attachments that are not attached to a resource anymore when checking access rights # ignore attachments that are not attached to a resource anymore when checking access rights
# (resource was deleted but attachment was not) # (resource was deleted but attachment was not)
mids = self.pool.get(model).exists(cr, uid, mids) mids = self.pool[model].exists(cr, uid, mids)
ima.check(cr, uid, model, mode) ima.check(cr, uid, model, mode)
self.pool.get(model).check_access_rule(cr, uid, mids, mode, context=context) self.pool[model].check_access_rule(cr, uid, mids, mode, context=context)
def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None): def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None):
ids = super(ir_attachment, self)._search(cr, uid, args, offset=offset, ids = super(ir_attachment, self)._search(cr, uid, args, offset=offset,
@ -250,7 +250,7 @@ class ir_attachment(osv.osv):
# filter ids according to what access rules permit # filter ids according to what access rules permit
target_ids = targets.keys() target_ids = targets.keys()
allowed_ids = self.pool.get(model).search(cr, uid, [('id', 'in', target_ids)], context=context) allowed_ids = self.pool[model].search(cr, uid, [('id', 'in', target_ids)], context=context)
disallowed_ids = set(target_ids).difference(allowed_ids) disallowed_ids = set(target_ids).difference(allowed_ids)
for res_id in disallowed_ids: for res_id in disallowed_ids:
for attach_id in targets[res_id]: for attach_id in targets[res_id]:

View File

@ -124,21 +124,23 @@ class ir_cron(osv.osv):
args = str2tuple(args) args = str2tuple(args)
openerp.modules.registry.RegistryManager.check_registry_signaling(cr.dbname) openerp.modules.registry.RegistryManager.check_registry_signaling(cr.dbname)
registry = openerp.registry(cr.dbname) registry = openerp.registry(cr.dbname)
model = registry.get(model_name) if model_name in registry:
if model and hasattr(model, method_name): model = registry[model_name]
method = getattr(model, method_name) if hasattr(model, method_name):
log_depth = (None if _logger.isEnabledFor(logging.DEBUG) else 1) log_depth = (None if _logger.isEnabledFor(logging.DEBUG) else 1)
netsvc.log(_logger, logging.DEBUG, 'cron.object.execute', (cr.dbname,uid,'*',model_name,method_name)+tuple(args), depth=log_depth) netsvc.log(_logger, logging.DEBUG, 'cron.object.execute', (cr.dbname,uid,'*',model_name,method_name)+tuple(args), depth=log_depth)
if _logger.isEnabledFor(logging.DEBUG): if _logger.isEnabledFor(logging.DEBUG):
start_time = time.time() start_time = time.time()
method(cr, uid, *args) getattr(model, method_name)(cr, uid, *args)
if _logger.isEnabledFor(logging.DEBUG): if _logger.isEnabledFor(logging.DEBUG):
end_time = time.time() end_time = time.time()
_logger.debug('%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name)) _logger.debug('%.3fs (%s, %s)' % (end_time - start_time, model_name, method_name))
openerp.modules.registry.RegistryManager.signal_caches_change(cr.dbname) openerp.modules.registry.RegistryManager.signal_caches_change(cr.dbname)
else:
msg = "Method `%s.%s` does not exist." % (model_name, method_name)
_logger.warning(msg)
else: else:
msg = "Method `%s.%s` does not exist." % (model_name, method_name) \ msg = "Model `%s` does not exist." % model_name
if model else "Model `%s` does not exist." % model_name
_logger.warning(msg) _logger.warning(msg)
except Exception, e: except Exception, e:
self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e) self._handle_callback_exception(cr, uid, model_name, method_name, args, job_id, e)

View File

@ -70,7 +70,7 @@ class ir_model(osv.osv):
models = self.browse(cr, uid, ids, context=context) models = self.browse(cr, uid, ids, context=context)
res = dict.fromkeys(ids) res = dict.fromkeys(ids)
for model in models: for model in models:
if self.pool.get(model.model): if model.model in self.pool:
res[model.id] = self.pool[model.model].is_transient() res[model.id] = self.pool[model.model].is_transient()
else: else:
_logger.error('Missing model %s' % (model.model, )) _logger.error('Missing model %s' % (model.model, ))
@ -340,7 +340,7 @@ class ir_model_fields(osv.osv):
if vals.get('relation',False) and not self.pool['ir.model'].search(cr, user, [('model','=',vals['relation'])]): if vals.get('relation',False) and not self.pool['ir.model'].search(cr, user, [('model','=',vals['relation'])]):
raise except_orm(_('Error'), _("Model %s does not exist!") % vals['relation']) raise except_orm(_('Error'), _("Model %s does not exist!") % vals['relation'])
if self.pool.get(vals['model']): if vals['model'] in self.pool:
self.pool[vals['model']].__init__(self.pool, cr) self.pool[vals['model']].__init__(self.pool, cr)
#Added context to _auto_init for special treatment to custom field for select_level #Added context to _auto_init for special treatment to custom field for select_level
ctx = dict(context, ctx = dict(context,
@ -367,7 +367,6 @@ class ir_model_fields(osv.osv):
raise except_orm(_('Error!'), _('Renaming sparse field "%s" is not allowed')%field.name) raise except_orm(_('Error!'), _('Renaming sparse field "%s" is not allowed')%field.name)
column_rename = None # if set, *one* column can be renamed here column_rename = None # if set, *one* column can be renamed here
obj = None
models_patch = {} # structs of (obj, [(field, prop, change_to),..]) models_patch = {} # structs of (obj, [(field, prop, change_to),..])
# data to be updated on the orm model # data to be updated on the orm model
@ -390,8 +389,7 @@ class ir_model_fields(osv.osv):
checked_selection = False # need only check it once, so defer checked_selection = False # need only check it once, so defer
for item in self.browse(cr, user, ids, context=context): for item in self.browse(cr, user, ids, context=context):
if not (obj and obj._name == item.model): obj = self.pool.get(item.model)
obj = self.pool.get(item.model)
if item.state != 'manual': if item.state != 'manual':
raise except_orm(_('Error!'), raise except_orm(_('Error!'),
@ -427,7 +425,7 @@ class ir_model_fields(osv.osv):
# We don't check the 'state', because it might come from the context # We don't check the 'state', because it might come from the context
# (thus be set for multiple fields) and will be ignored anyway. # (thus be set for multiple fields) and will be ignored anyway.
if obj: if obj is not None:
models_patch.setdefault(obj._name, (obj,[])) models_patch.setdefault(obj._name, (obj,[]))
# find out which properties (per model) we need to update # find out which properties (per model) we need to update
for field_name, field_property, set_fn in model_props: for field_name, field_property, set_fn in model_props:
@ -507,7 +505,7 @@ class ir_model_constraint(Model):
ids.reverse() ids.reverse()
for data in self.browse(cr, uid, ids, context): for data in self.browse(cr, uid, ids, context):
model = data.model.model model = data.model.model
model_obj = self.pool.get(model) model_obj = self.pool[model]
name = openerp.tools.ustr(data.name) name = openerp.tools.ustr(data.name)
typ = data.type typ = data.type
@ -682,7 +680,7 @@ class ir_model_access(osv.osv):
model_name = model model_name = model
# TransientModel records have no access rights, only an implicit access rule # TransientModel records have no access rights, only an implicit access rule
if not self.pool.get(model_name): if model_name not in self.pool:
_logger.error('Missing model %s' % (model_name, )) _logger.error('Missing model %s' % (model_name, ))
elif self.pool[model_name].is_transient(): elif self.pool[model_name].is_transient():
return True return True
@ -746,9 +744,8 @@ class ir_model_access(osv.osv):
def call_cache_clearing_methods(self, cr): def call_cache_clearing_methods(self, cr):
self.check.clear_cache(self) # clear the cache of check function self.check.clear_cache(self) # clear the cache of check function
for model, method in self.__cache_clearing_methods: for model, method in self.__cache_clearing_methods:
object_ = self.pool.get(model) if model in self.pool:
if object_: getattr(self.pool[model], method)()
getattr(object_, method)()
# #
# Check rights on actions # Check rights on actions
@ -896,7 +893,7 @@ class ir_model_data(osv.osv):
return super(ir_model_data,self).unlink(cr, uid, ids, context=context) return super(ir_model_data,self).unlink(cr, uid, ids, context=context)
def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False, context=None): def _update(self,cr, uid, model, module, values, xml_id=False, store=True, noupdate=False, mode='init', res_id=False, context=None):
model_obj = self.pool.get(model) model_obj = self.pool[model]
if not context: if not context:
context = {} context = {}
# records created during module install should not display the messages of OpenChatter # records created during module install should not display the messages of OpenChatter
@ -1114,7 +1111,7 @@ class ir_model_data(osv.osv):
to_unlink.append((model,res_id)) to_unlink.append((model,res_id))
if not config.get('import_partial'): if not config.get('import_partial'):
for (model, res_id) in to_unlink: for (model, res_id) in to_unlink:
if self.pool.get(model): if model in self.pool:
_logger.info('Deleting %s@%s', res_id, model) _logger.info('Deleting %s@%s', res_id, model)
self.pool[model].unlink(cr, uid, [res_id]) self.pool[model].unlink(cr, uid, [res_id])

View File

@ -65,7 +65,7 @@ class ir_rule(osv.osv):
return res return res
def _check_model_obj(self, cr, uid, ids, context=None): def _check_model_obj(self, cr, uid, ids, context=None):
return not any(self.pool.get(rule.model_id.model).is_transient() for rule in self.browse(cr, uid, ids, context)) return not any(self.pool[rule.model_id.model].is_transient() for rule in self.browse(cr, uid, ids, context))
def _check_model_name(self, cr, uid, ids, context=None): def _check_model_name(self, cr, uid, ids, context=None):
# Don't allow rules on rules records (this model). # Don't allow rules on rules records (this model).
@ -153,9 +153,9 @@ class ir_rule(osv.osv):
# involve objects on which the real uid has no acces rights. # involve objects on which the real uid has no acces rights.
# This means also there is no implicit restriction (e.g. an object # This means also there is no implicit restriction (e.g. an object
# references another object the user can't see). # references another object the user can't see).
query = self.pool.get(model_name)._where_calc(cr, SUPERUSER_ID, dom, active_test=False) query = self.pool[model_name]._where_calc(cr, SUPERUSER_ID, dom, active_test=False)
return query.where_clause, query.where_clause_params, query.tables return query.where_clause, query.where_clause_params, query.tables
return [], [], ['"'+self.pool.get(model_name)._table+'"'] return [], [], ['"' + self.pool[model_name]._table + '"']
def unlink(self, cr, uid, ids, context=None): def unlink(self, cr, uid, ids, context=None):
res = super(ir_rule, self).unlink(cr, uid, ids, context=context) res = super(ir_rule, self).unlink(cr, uid, ids, context=context)

View File

@ -334,7 +334,7 @@ class ir_translation(osv.osv):
return result return result
def translate_fields(self, cr, uid, model, id, field=None, context=None): def translate_fields(self, cr, uid, model, id, field=None, context=None):
trans_model = self.pool.get(model) trans_model = self.pool[model]
domain = ['&', ('res_id', '=', id), ('name', '=like', model + ',%')] domain = ['&', ('res_id', '=', id), ('name', '=like', model + ',%')]
langs_ids = self.pool.get('res.lang').search(cr, uid, [('code', '!=', 'en_US')], context=context) langs_ids = self.pool.get('res.lang').search(cr, uid, [('code', '!=', 'en_US')], context=context)
if not langs_ids: if not langs_ids:

View File

@ -289,8 +289,7 @@ class ir_ui_menu(osv.osv):
res = dict.fromkeys(ids, False) res = dict.fromkeys(ids, False)
for menu in self.browse(cr, uid, ids, context=context): for menu in self.browse(cr, uid, ids, context=context):
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model: if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model:
obj = self.pool.get(menu.action.res_model) if menu.action.res_model in self.pool and self.pool[menu.action.res_model]._needaction:
if obj and obj._needaction:
res[menu.id] = True res[menu.id] = True
return res return res
@ -307,14 +306,15 @@ class ir_ui_menu(osv.osv):
'needaction_counter': False, 'needaction_counter': False,
} }
if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model: if menu.action and menu.action.type in ('ir.actions.act_window', 'ir.actions.client') and menu.action.res_model:
obj = self.pool.get(menu.action.res_model) if menu.action.res_model in self.pool:
if obj and obj._needaction: obj = self.pool[menu.action.res_model]
if menu.action.type == 'ir.actions.act_window': if obj._needaction:
dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or [] if menu.action.type == 'ir.actions.act_window':
else: dom = menu.action.domain and eval(menu.action.domain, {'uid': uid}) or []
dom = eval(menu.action.params_store or '{}', {'uid': uid}).get('domain') else:
res[menu.id]['needaction_enabled'] = obj._needaction dom = eval(menu.action.params_store or '{}', {'uid': uid}).get('domain')
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=context) res[menu.id]['needaction_enabled'] = obj._needaction
res[menu.id]['needaction_counter'] = obj._needaction_count(cr, uid, dom, context=context)
return res return res
_columns = { _columns = {

View File

@ -122,7 +122,7 @@ class view(osv.osv):
if no error occurred, else False. if no error occurred, else False.
""" """
try: try:
fvg = self.pool.get(view.model).fields_view_get(cr, uid, view_id=view.id, view_type=view.type, context=context) fvg = self.pool[view.model].fields_view_get(cr, uid, view_id=view.id, view_type=view.type, context=context)
return fvg['arch'] return fvg['arch']
except: except:
_logger.exception("Can't render view %s for model: %s", view.xml_id, view.model) _logger.exception("Can't render view %s for model: %s", view.xml_id, view.model)
@ -216,9 +216,9 @@ class view(osv.osv):
no_ancester=[] no_ancester=[]
blank_nodes = [] blank_nodes = []
_Model_Obj=self.pool.get(model) _Model_Obj = self.pool[model]
_Node_Obj=self.pool.get(node_obj) _Node_Obj = self.pool[node_obj]
_Arrow_Obj=self.pool.get(conn_obj) _Arrow_Obj = self.pool[conn_obj]
for model_key,model_value in _Model_Obj._columns.items(): for model_key,model_value in _Model_Obj._columns.items():
if model_value._type=='one2many': if model_value._type=='one2many':
@ -292,7 +292,7 @@ class view_sc(osv.osv):
def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context=None): def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context=None):
ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context) ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context)
results = self.read(cr, uid, ids, ['res_id'], context=context) results = self.read(cr, uid, ids, ['res_id'], context=context)
name_map = dict(self.pool.get(model).name_get(cr, uid, [x['res_id'] for x in results], context=context)) name_map = dict(self.pool[model].name_get(cr, uid, [x['res_id'] for x in results], context=context))
# Make sure to return only shortcuts pointing to exisintg menu items. # Make sure to return only shortcuts pointing to exisintg menu items.
filtered_results = filter(lambda result: result['res_id'] in name_map, results) filtered_results = filter(lambda result: result['res_id'] in name_map, results)
for result in filtered_results: for result in filtered_results:

View File

@ -397,11 +397,11 @@ class ir_values(osv.osv):
action_model,id = action['value'].split(',') action_model,id = action['value'].split(',')
fields = [ fields = [
field field
for field in self.pool.get(action_model)._all_columns for field in self.pool[action_model]._all_columns
if field not in EXCLUDED_FIELDS] if field not in EXCLUDED_FIELDS]
# FIXME: needs cleanup # FIXME: needs cleanup
try: try:
action_def = self.pool.get(action_model).read(cr, uid, int(id), fields, context) action_def = self.pool[action_model].read(cr, uid, int(id), fields, context)
if action_def: if action_def:
if action_model in ('ir.actions.report.xml','ir.actions.act_window', if action_model in ('ir.actions.report.xml','ir.actions.act_window',
'ir.actions.wizard'): 'ir.actions.wizard'):

View File

@ -34,7 +34,7 @@ class ir_module_reference_print(report_sxw.rml_parse):
'findflds': self._fields_find, 'findflds': self._fields_find,
}) })
def _object_doc(self, obj): def _object_doc(self, obj):
modobj = self.pool.get(obj) modobj = self.pool[obj]
strdocs= modobj.__doc__ strdocs= modobj.__doc__
if not strdocs: if not strdocs:
return None return None
@ -48,7 +48,7 @@ class ir_module_reference_print(report_sxw.rml_parse):
return res return res
def _object_doc2(self, obj): def _object_doc2(self, obj):
modobj = self.pool.get(obj) modobj = self.pool[obj]
strdocs= modobj.__doc__ strdocs= modobj.__doc__
if not strdocs: if not strdocs:
return None return None
@ -72,7 +72,7 @@ class ir_module_reference_print(report_sxw.rml_parse):
return modobj.browse(self.cr, self.uid, ids) return modobj.browse(self.cr, self.uid, ids)
def _fields_find(self, obj): def _fields_find(self, obj):
modobj = self.pool.get(obj) modobj = self.pool[obj]
res = modobj.fields_get(self.cr, self.uid).items() res = modobj.fields_get(self.cr, self.uid).items()
res.sort() res.sort()
return res return res

View File

@ -348,8 +348,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
if processed_modules: if processed_modules:
cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""") cr.execute("""select model,name from ir_model where id NOT IN (select distinct model_id from ir_model_access)""")
for (model, name) in cr.fetchall(): for (model, name) in cr.fetchall():
model_obj = registry.get(model) if model in registry and not registry[model].is_transient():
if model_obj and not model_obj.is_transient():
_logger.warning('The model %s has no access rules, consider adding one. E.g. access_%s,access_%s,model_%s,,1,1,1,1', _logger.warning('The model %s has no access rules, consider adding one. E.g. access_%s,access_%s,model_%s,,1,1,1,1',
model, model.replace('.', '_'), model.replace('.', '_'), model.replace('.', '_')) model, model.replace('.', '_'), model.replace('.', '_'), model.replace('.', '_'))
@ -357,15 +356,13 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
# been replaced by owner-only access rights # been replaced by owner-only access rights
cr.execute("""select distinct mod.model, mod.name from ir_model_access acc, ir_model mod where acc.model_id = mod.id""") cr.execute("""select distinct mod.model, mod.name from ir_model_access acc, ir_model mod where acc.model_id = mod.id""")
for (model, name) in cr.fetchall(): for (model, name) in cr.fetchall():
model_obj = registry.get(model) if model in registry and registry[model].is_transient():
if model_obj and model_obj.is_transient():
_logger.warning('The transient model %s (%s) should not have explicit access rules!', model, name) _logger.warning('The transient model %s (%s) should not have explicit access rules!', model, name)
cr.execute("SELECT model from ir_model") cr.execute("SELECT model from ir_model")
for (model,) in cr.fetchall(): for (model,) in cr.fetchall():
obj = registry.get(model) if model in registry:
if obj: registry[model]._check_removed_columns(cr, log=True)
obj._check_removed_columns(cr, log=True)
else: else:
_logger.warning("Model %s is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)", model) _logger.warning("Model %s is declared but cannot be loaded! (Perhaps a module was partially removed or renamed)", model)

View File

@ -758,7 +758,7 @@ class expression(object):
field_path = left.split('.', 1) field_path = left.split('.', 1)
field = working_model._columns.get(field_path[0]) field = working_model._columns.get(field_path[0])
if field and field._obj: if field and field._obj:
relational_model = working_model.pool.get(field._obj) relational_model = working_model.pool[field._obj]
else: else:
relational_model = None relational_model = None
@ -787,7 +787,7 @@ class expression(object):
# comments about inherits'd fields # comments about inherits'd fields
# { 'field_name': ('parent_model', 'm2o_field_to_reach_parent', # { 'field_name': ('parent_model', 'm2o_field_to_reach_parent',
# field_column_obj, origina_parent_model), ... } # field_column_obj, origina_parent_model), ... }
next_model = working_model.pool.get(working_model._inherit_fields[field_path[0]][0]) next_model = working_model.pool[working_model._inherit_fields[field_path[0]][0]]
leaf.add_join_context(next_model, working_model._inherits[next_model._name], 'id', working_model._inherits[next_model._name]) leaf.add_join_context(next_model, working_model._inherits[next_model._name], 'id', working_model._inherits[next_model._name])
push(leaf) push(leaf)

View File

@ -193,7 +193,7 @@ class reference(_column):
result[value['id']] = value[name] result[value['id']] = value[name]
if value[name]: if value[name]:
model, res_id = value[name].split(',') model, res_id = value[name].split(',')
if not obj.pool.get(model).exists(cr, uid, [int(res_id)], context=context): if not obj.pool[model].exists(cr, uid, [int(res_id)], context=context):
result[value['id']] = False result[value['id']] = False
return result return result
@ -203,8 +203,8 @@ class reference(_column):
# reference fields have a 'model,id'-like value, that we need to convert # reference fields have a 'model,id'-like value, that we need to convert
# to a real name # to a real name
model_name, res_id = value.split(',') model_name, res_id = value.split(',')
model = obj.pool.get(model_name) if model_name in obj.pool and res_id:
if model and res_id: model = obj.pool[model_name]
return model.name_get(cr, uid, [int(res_id)], context=context)[0][1] return model.name_get(cr, uid, [int(res_id)], context=context)[0][1]
return tools.ustr(value) return tools.ustr(value)
@ -456,7 +456,7 @@ class many2one(_column):
res[r['id']] = r[name] res[r['id']] = r[name]
for id in ids: for id in ids:
res.setdefault(id, '') res.setdefault(id, '')
obj = obj.pool.get(self._obj) obj = obj.pool[self._obj]
# build a dictionary of the form {'id_of_distant_resource': name_of_distant_resource} # build a dictionary of the form {'id_of_distant_resource': name_of_distant_resource}
# we use uid=1 because the visibility of a many2one field value (just id and name) # we use uid=1 because the visibility of a many2one field value (just id and name)
@ -474,8 +474,8 @@ class many2one(_column):
def set(self, cr, obj_src, id, field, values, user=None, context=None): def set(self, cr, obj_src, id, field, values, user=None, context=None):
if not context: if not context:
context = {} context = {}
obj = obj_src.pool.get(self._obj) obj = obj_src.pool[self._obj]
self._table = obj_src.pool.get(self._obj)._table self._table = obj._table
if type(values) == type([]): if type(values) == type([]):
for act in values: for act in values:
if act[0] == 0: if act[0] == 0:
@ -496,7 +496,7 @@ class many2one(_column):
cr.execute('update '+obj_src._table+' set '+field+'=null where id=%s', (id,)) cr.execute('update '+obj_src._table+' set '+field+'=null where id=%s', (id,))
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None): def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit, context=context) return obj.pool[self._obj].search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit, context=context)
@classmethod @classmethod
@ -533,8 +533,9 @@ class one2many(_column):
res[id] = [] res[id] = []
domain = self._domain(obj) if callable(self._domain) else self._domain domain = self._domain(obj) if callable(self._domain) else self._domain
ids2 = obj.pool.get(self._obj).search(cr, user, domain + [(self._fields_id, 'in', ids)], limit=self._limit, context=context) model = obj.pool[self._obj]
for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'): ids2 = model.search(cr, user, domain + [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
for r in model._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
if r[self._fields_id] in res: if r[self._fields_id] in res:
res[r[self._fields_id]].append(r['id']) res[r[self._fields_id]].append(r['id'])
return res return res
@ -549,8 +550,8 @@ class one2many(_column):
context['no_store_function'] = True context['no_store_function'] = True
if not values: if not values:
return return
_table = obj.pool.get(self._obj)._table obj = obj.pool[self._obj]
obj = obj.pool.get(self._obj) _table = obj._table
for act in values: for act in values:
if act[0] == 0: if act[0] == 0:
act[2][self._fields_id] = id act[2][self._fields_id] = id
@ -595,7 +596,7 @@ class one2many(_column):
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None): def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
domain = self._domain(obj) if callable(self._domain) else self._domain domain = self._domain(obj) if callable(self._domain) else self._domain
return obj.pool.get(self._obj).name_search(cr, uid, value, domain, operator, context=context,limit=limit) return obj.pool[self._obj].name_search(cr, uid, value, domain, operator, context=context,limit=limit)
@classmethod @classmethod
@ -666,7 +667,7 @@ class many2many(_column):
tbl, col1, col2 = self._rel, self._id1, self._id2 tbl, col1, col2 = self._rel, self._id1, self._id2
if not all((tbl, col1, col2)): if not all((tbl, col1, col2)):
# the default table name is based on the stable alphabetical order of tables # the default table name is based on the stable alphabetical order of tables
dest_model = source_model.pool.get(self._obj) dest_model = source_model.pool[self._obj]
tables = tuple(sorted([source_model._table, dest_model._table])) tables = tuple(sorted([source_model._table, dest_model._table]))
if not tbl: if not tbl:
assert tables[0] != tables[1], 'Implicit/Canonical naming of m2m relationship table '\ assert tables[0] != tables[1], 'Implicit/Canonical naming of m2m relationship table '\
@ -707,7 +708,7 @@ class many2many(_column):
_logger.warning( _logger.warning(
"Specifying offset at a many2many.get() is deprecated and may" "Specifying offset at a many2many.get() is deprecated and may"
" produce unpredictable results.") " produce unpredictable results.")
obj = model.pool.get(self._obj) obj = model.pool[self._obj]
rel, id1, id2 = self._sql_names(model) rel, id1, id2 = self._sql_names(model)
# static domains are lists, and are evaluated both here and on client-side, while string # static domains are lists, and are evaluated both here and on client-side, while string
@ -749,7 +750,7 @@ class many2many(_column):
if not values: if not values:
return return
rel, id1, id2 = self._sql_names(model) rel, id1, id2 = self._sql_names(model)
obj = model.pool.get(self._obj) obj = model.pool[self._obj]
for act in values: for act in values:
if not (isinstance(act, list) or isinstance(act, tuple)) or not act: if not (isinstance(act, list) or isinstance(act, tuple)) or not act:
continue continue
@ -785,7 +786,7 @@ class many2many(_column):
# TODO: use a name_search # TODO: use a name_search
# #
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None): def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', operator, value)], offset, limit, context=context) return obj.pool[self._obj].search(cr, uid, args+self._domain+[('name', operator, value)], offset, limit, context=context)
@classmethod @classmethod
def _as_display_name(cls, field, cr, uid, obj, value, context=None): def _as_display_name(cls, field, cr, uid, obj, value, context=None):
@ -1107,7 +1108,7 @@ class function(_column):
if field_type == "many2one": if field_type == "many2one":
# make the result a tuple if it is not already one # make the result a tuple if it is not already one
if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'): if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'):
obj_model = obj.pool.get(obj._columns[field].relation) obj_model = obj.pool[obj._columns[field].relation]
dict_names = dict(obj_model.name_get(cr, uid, [value], context)) dict_names = dict(obj_model.name_get(cr, uid, [value], context))
result = (value, dict_names[value]) result = (value, dict_names[value])
@ -1204,7 +1205,7 @@ class related(function):
# Perform name_get as root, as seeing the name of a related object depends on # Perform name_get as root, as seeing the name of a related object depends on
# access right of source document, not target, so user may not have access. # access right of source document, not target, so user may not have access.
value_ids = list(set(value.id for value in res.itervalues() if value)) value_ids = list(set(value.id for value in res.itervalues() if value))
value_name = dict(obj.pool.get(self._obj).name_get(cr, SUPERUSER_ID, value_ids, context=context)) value_name = dict(obj.pool[self._obj].name_get(cr, SUPERUSER_ID, value_ids, context=context))
res = dict((id, value and (value.id, value_name[value.id])) for id, value in res.iteritems()) res = dict((id, value and (value.id, value_name[value.id])) for id, value in res.iteritems())
elif self._type in ('one2many', 'many2many'): elif self._type in ('one2many', 'many2many'):
@ -1258,7 +1259,7 @@ class sparse(function):
elif self._type == 'one2many': elif self._type == 'one2many':
if not read_value: if not read_value:
read_value = [] read_value = []
relation_obj = obj.pool.get(self.relation) relation_obj = obj.pool[self.relation]
for vals in value: for vals in value:
assert vals[0] in (0,1,2), 'Unsupported o2m value for sparse field: %s' % vals assert vals[0] in (0,1,2), 'Unsupported o2m value for sparse field: %s' % vals
if vals[0] == 0: if vals[0] == 0:
@ -1301,10 +1302,10 @@ class sparse(function):
value = value or [] value = value or []
if value: if value:
# filter out deleted records as superuser # filter out deleted records as superuser
relation_obj = obj.pool.get(obj._columns[field_name].relation) relation_obj = obj.pool[obj._columns[field_name].relation]
value = relation_obj.exists(cr, openerp.SUPERUSER_ID, value) value = relation_obj.exists(cr, openerp.SUPERUSER_ID, value)
if type(value) in (int,long) and field_type == 'many2one': if type(value) in (int,long) and field_type == 'many2one':
relation_obj = obj.pool.get(obj._columns[field_name].relation) relation_obj = obj.pool[obj._columns[field_name].relation]
# check for deleted record as superuser # check for deleted record as superuser
if not relation_obj.exists(cr, openerp.SUPERUSER_ID, [value]): if not relation_obj.exists(cr, openerp.SUPERUSER_ID, [value]):
value = False value = False
@ -1452,7 +1453,7 @@ class property(function):
# not target, so user may not have access) in order to avoid # not target, so user may not have access) in order to avoid
# pointing on an unexisting record. # pointing on an unexisting record.
if property_destination_obj: if property_destination_obj:
if res[id][prop_name] and obj.pool.get(property_destination_obj).exists(cr, SUPERUSER_ID, res[id][prop_name].id): if res[id][prop_name] and obj.pool[property_destination_obj].exists(cr, SUPERUSER_ID, res[id][prop_name].id):
name_get_ids[id] = res[id][prop_name].id name_get_ids[id] = res[id][prop_name].id
else: else:
res[id][prop_name] = False res[id][prop_name] = False
@ -1460,7 +1461,7 @@ class property(function):
# name_get as root (as seeing the name of a related # name_get as root (as seeing the name of a related
# object depends on access right of source document, # object depends on access right of source document,
# not target, so user may not have access.) # not target, so user may not have access.)
name_get_values = dict(obj.pool.get(property_destination_obj).name_get(cr, SUPERUSER_ID, name_get_ids.values(), context=context)) name_get_values = dict(obj.pool[property_destination_obj].name_get(cr, SUPERUSER_ID, name_get_ids.values(), context=context))
# the property field is a m2o, we need to return a tuple with (id, name) # the property field is a m2o, we need to return a tuple with (id, name)
for k, v in name_get_ids.iteritems(): for k, v in name_get_ids.iteritems():
if res[k][prop_name]: if res[k][prop_name]:

View File

@ -420,7 +420,7 @@ class browse_record(object):
for field_name, field_column in fields_to_fetch: for field_name, field_column in fields_to_fetch:
if field_column._type == 'many2one': if field_column._type == 'many2one':
if result_line[field_name]: if result_line[field_name]:
obj = self._table.pool.get(field_column._obj) obj = self._table.pool[field_column._obj]
if isinstance(result_line[field_name], (list, tuple)): if isinstance(result_line[field_name], (list, tuple)):
value = result_line[field_name][0] value = result_line[field_name][0]
else: else:
@ -450,7 +450,7 @@ class browse_record(object):
else: else:
new_data[field_name] = browse_null() new_data[field_name] = browse_null()
elif field_column._type in ('one2many', 'many2many') and len(result_line[field_name]): elif field_column._type in ('one2many', 'many2many') and len(result_line[field_name]):
new_data[field_name] = self._list_class([browse_record(self._cr, self._uid, id, self._table.pool.get(field_column._obj), self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process) for id in result_line[field_name]], self._context) new_data[field_name] = self._list_class([browse_record(self._cr, self._uid, id, self._table.pool[field_column._obj], self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process) for id in result_line[field_name]], self._context)
elif field_column._type == 'reference': elif field_column._type == 'reference':
if result_line[field_name]: if result_line[field_name]:
if isinstance(result_line[field_name], browse_record): if isinstance(result_line[field_name], browse_record):
@ -459,7 +459,7 @@ class browse_record(object):
ref_obj, ref_id = result_line[field_name].split(',') ref_obj, ref_id = result_line[field_name].split(',')
ref_id = long(ref_id) ref_id = long(ref_id)
if ref_id: if ref_id:
obj = self._table.pool.get(ref_obj) obj = self._table.pool[ref_obj]
new_data[field_name] = browse_record(self._cr, self._uid, ref_id, obj, self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process) new_data[field_name] = browse_record(self._cr, self._uid, ref_id, obj, self._cache, context=self._context, list_class=self._list_class, fields_process=self._fields_process)
else: else:
new_data[field_name] = browse_null() new_data[field_name] = browse_null()
@ -867,10 +867,10 @@ class BaseModel(object):
raise TypeError('_name is mandatory in case of multiple inheritance') raise TypeError('_name is mandatory in case of multiple inheritance')
for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]): for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]):
parent_model = pool.get(parent_name) if parent_name not in pool:
if not parent_model:
raise TypeError('The model "%s" specifies an unexisting parent class "%s"\n' raise TypeError('The model "%s" specifies an unexisting parent class "%s"\n'
'You may need to add a dependency on the parent class\' module.' % (name, parent_name)) 'You may need to add a dependency on the parent class\' module.' % (name, parent_name))
parent_model = pool[parent_name]
if not getattr(cls, '_original_module', None) and name == parent_model._name: if not getattr(cls, '_original_module', None) and name == parent_model._name:
cls._original_module = parent_model._original_module cls._original_module = parent_model._original_module
parent_class = parent_model.__class__ parent_class = parent_model.__class__
@ -1095,7 +1095,7 @@ class BaseModel(object):
return '' return ''
def selection_field(in_field): def selection_field(in_field):
col_obj = self.pool.get(in_field.keys()[0]) col_obj = self.pool[in_field.keys()[0]]
if f[i] in col_obj._columns.keys(): if f[i] in col_obj._columns.keys():
return col_obj._columns[f[i]] return col_obj._columns[f[i]]
elif f[i] in col_obj._inherits.keys(): elif f[i] in col_obj._inherits.keys():
@ -1183,10 +1183,10 @@ class BaseModel(object):
if not data[fpos]: if not data[fpos]:
dt = '' dt = ''
for rr in r: for rr in r:
name_relation = self.pool.get(rr._table_name)._rec_name name_relation = self.pool[rr._table_name]._rec_name
if isinstance(rr[name_relation], browse_record): if isinstance(rr[name_relation], browse_record):
rr = rr[name_relation] rr = rr[name_relation]
rr_name = self.pool.get(rr._table_name).name_get(cr, uid, [rr.id], context=context) rr_name = self.pool[rr._table_name].name_get(cr, uid, [rr.id], context=context)
rr_name = rr_name and rr_name[0] and rr_name[0][1] or '' rr_name = rr_name and rr_name[0] and rr_name[0][1] or ''
dt += tools.ustr(rr_name or '') + ',' dt += tools.ustr(rr_name or '') + ','
data[fpos] = dt[:-1] data[fpos] = dt[:-1]
@ -1199,7 +1199,7 @@ class BaseModel(object):
i += 1 i += 1
if i == len(f): if i == len(f):
if isinstance(r, browse_record): if isinstance(r, browse_record):
r = self.pool.get(r._table_name).name_get(cr, uid, [r.id], context=context) r = self.pool[r._table_name].name_get(cr, uid, [r.id], context=context)
r = r and r[0] and r[0][1] or '' r = r and r[0] and r[0][1] or ''
data[fpos] = tools.ustr(r or '') data[fpos] = tools.ustr(r or '')
return [data] + lines return [data] + lines
@ -1570,8 +1570,7 @@ class BaseModel(object):
# get the default values for the inherited fields # get the default values for the inherited fields
for t in self._inherits.keys(): for t in self._inherits.keys():
defaults.update(self.pool.get(t).default_get(cr, uid, fields_list, defaults.update(self.pool[t].default_get(cr, uid, fields_list, context))
context))
# get the default values defined in the object # get the default values defined in the object
for f in fields_list: for f in fields_list:
@ -1605,11 +1604,11 @@ class BaseModel(object):
if field in fields_list: if field in fields_list:
fld_def = (field in self._columns) and self._columns[field] or self._inherit_fields[field][2] fld_def = (field in self._columns) and self._columns[field] or self._inherit_fields[field][2]
if fld_def._type == 'many2one': if fld_def._type == 'many2one':
obj = self.pool.get(fld_def._obj) obj = self.pool[fld_def._obj]
if not obj.search(cr, uid, [('id', '=', field_value or False)]): if not obj.search(cr, uid, [('id', '=', field_value or False)]):
continue continue
if fld_def._type == 'many2many': if fld_def._type == 'many2many':
obj = self.pool.get(fld_def._obj) obj = self.pool[fld_def._obj]
field_value2 = [] field_value2 = []
for i in range(len(field_value or [])): for i in range(len(field_value or [])):
if not obj.search(cr, uid, [('id', '=', if not obj.search(cr, uid, [('id', '=',
@ -1618,18 +1617,18 @@ class BaseModel(object):
field_value2.append(field_value[i]) field_value2.append(field_value[i])
field_value = field_value2 field_value = field_value2
if fld_def._type == 'one2many': if fld_def._type == 'one2many':
obj = self.pool.get(fld_def._obj) obj = self.pool[fld_def._obj]
field_value2 = [] field_value2 = []
for i in range(len(field_value or [])): for i in range(len(field_value or [])):
field_value2.append({}) field_value2.append({})
for field2 in field_value[i]: for field2 in field_value[i]:
if field2 in obj._columns.keys() and obj._columns[field2]._type == 'many2one': if field2 in obj._columns.keys() and obj._columns[field2]._type == 'many2one':
obj2 = self.pool.get(obj._columns[field2]._obj) obj2 = self.pool[obj._columns[field2]._obj]
if not obj2.search(cr, uid, if not obj2.search(cr, uid,
[('id', '=', field_value[i][field2])]): [('id', '=', field_value[i][field2])]):
continue continue
elif field2 in obj._inherit_fields.keys() and obj._inherit_fields[field2][2]._type == 'many2one': elif field2 in obj._inherit_fields.keys() and obj._inherit_fields[field2][2]._type == 'many2one':
obj2 = self.pool.get(obj._inherit_fields[field2][2]._obj) obj2 = self.pool[obj._inherit_fields[field2][2]._obj]
if not obj2.search(cr, uid, if not obj2.search(cr, uid,
[('id', '=', field_value[i][field2])]): [('id', '=', field_value[i][field2])]):
continue continue
@ -1649,7 +1648,7 @@ class BaseModel(object):
# TODO I believe this loop can be replace by # TODO I believe this loop can be replace by
# res.extend(self._inherit_fields.key()) # res.extend(self._inherit_fields.key())
for parent in self._inherits: for parent in self._inherits:
res.extend(self.pool.get(parent).fields_get_keys(cr, user, context)) res.extend(self.pool[parent].fields_get_keys(cr, user, context))
return res return res
def _rec_name_fallback(self, cr, uid, context=None): def _rec_name_fallback(self, cr, uid, context=None):
@ -1745,7 +1744,7 @@ class BaseModel(object):
new_xml = etree.fromstring(encode(xml)) new_xml = etree.fromstring(encode(xml))
ctx = context.copy() ctx = context.copy()
ctx['base_model_name'] = self._name ctx['base_model_name'] = self._name
xarch, xfields = self.pool.get(node.get('object')).__view_look_dom_arch(cr, user, new_xml, view_id, ctx) xarch, xfields = self.pool[node.get('object')].__view_look_dom_arch(cr, user, new_xml, view_id, ctx)
views['form'] = { views['form'] = {
'arch': xarch, 'arch': xarch,
'fields': xfields 'fields': xfields
@ -1763,7 +1762,7 @@ class BaseModel(object):
column = False column = False
if column: if column:
relation = self.pool.get(column._obj) relation = self.pool[column._obj] if column._obj else None
children = False children = False
views = {} views = {}
@ -1899,13 +1898,13 @@ class BaseModel(object):
fields = {} fields = {}
if node.tag == 'diagram': if node.tag == 'diagram':
if node.getchildren()[0].tag == 'node': if node.getchildren()[0].tag == 'node':
node_model = self.pool.get(node.getchildren()[0].get('object')) node_model = self.pool[node.getchildren()[0].get('object')]
node_fields = node_model.fields_get(cr, user, None, context) node_fields = node_model.fields_get(cr, user, None, context)
fields.update(node_fields) fields.update(node_fields)
if not node.get("create") and not node_model.check_access_rights(cr, user, 'create', raise_exception=False): if not node.get("create") and not node_model.check_access_rights(cr, user, 'create', raise_exception=False):
node.set("create", 'false') node.set("create", 'false')
if node.getchildren()[1].tag == 'arrow': if node.getchildren()[1].tag == 'arrow':
arrow_fields = self.pool.get(node.getchildren()[1].get('object')).fields_get(cr, user, None, context) arrow_fields = self.pool[node.getchildren()[1].get('object')].fields_get(cr, user, None, context)
fields.update(arrow_fields) fields.update(arrow_fields)
else: else:
fields = self.fields_get(cr, user, None, context) fields = self.fields_get(cr, user, None, context)
@ -2446,7 +2445,7 @@ class BaseModel(object):
res[lang][f] = self._columns[f].string res[lang][f] = self._columns[f].string
for table in self._inherits: for table in self._inherits:
cols = intersect(self._inherit_fields.keys(), fields) cols = intersect(self._inherit_fields.keys(), fields)
res2 = self.pool.get(table).read_string(cr, uid, id, langs, cols, context) res2 = self.pool[table].read_string(cr, uid, id, langs, cols, context)
for lang in res2: for lang in res2:
if lang in res: if lang in res:
res[lang]['code'] = lang res[lang]['code'] = lang
@ -2465,7 +2464,7 @@ class BaseModel(object):
for table in self._inherits: for table in self._inherits:
cols = intersect(self._inherit_fields.keys(), vals) cols = intersect(self._inherit_fields.keys(), vals)
if cols: if cols:
self.pool.get(table).write_string(cr, uid, id, langs, vals, context) self.pool[table].write_string(cr, uid, id, langs, vals, context)
return True return True
def _add_missing_default_values(self, cr, uid, values, context=None): def _add_missing_default_values(self, cr, uid, values, context=None):
@ -2726,7 +2725,7 @@ class BaseModel(object):
:param query: query object on which the JOIN should be added :param query: query object on which the JOIN should be added
""" """
inherits_field = current_model._inherits[parent_model_name] inherits_field = current_model._inherits[parent_model_name]
parent_model = self.pool.get(parent_model_name) parent_model = self.pool[parent_model_name]
parent_alias, parent_alias_statement = query.add_join((current_model._table, parent_model._table, inherits_field, 'id', inherits_field), implicit=True) parent_alias, parent_alias_statement = query.add_join((current_model._table, parent_model._table, inherits_field, 'id', inherits_field), implicit=True)
return parent_alias return parent_alias
@ -2743,7 +2742,7 @@ class BaseModel(object):
parent_alias = '"%s"' % current_table._table parent_alias = '"%s"' % current_table._table
while field in current_table._inherit_fields and not field in current_table._columns: while field in current_table._inherit_fields and not field in current_table._columns:
parent_model_name = current_table._inherit_fields[field][0] parent_model_name = current_table._inherit_fields[field][0]
parent_table = self.pool.get(parent_model_name) parent_table = self.pool[parent_model_name]
parent_alias = self._inherits_join_add(current_table, parent_model_name, query) parent_alias = self._inherits_join_add(current_table, parent_model_name, query)
current_table = parent_table current_table = parent_table
return '%s."%s"' % (parent_alias, field) return '%s."%s"' % (parent_alias, field)
@ -3142,7 +3141,7 @@ class BaseModel(object):
_schema.debug(msg, self._table, k, f._type) _schema.debug(msg, self._table, k, f._type)
if isinstance(f, fields.many2one): if isinstance(f, fields.many2one):
dest_model = self.pool.get(f._obj) dest_model = self.pool[f._obj]
if dest_model._table != 'ir_actions': if dest_model._table != 'ir_actions':
self._m2o_fix_foreign_key(cr, self._table, k, dest_model, f.ondelete) self._m2o_fix_foreign_key(cr, self._table, k, dest_model, f.ondelete)
@ -3177,9 +3176,9 @@ class BaseModel(object):
# and add constraints if needed # and add constraints if needed
if isinstance(f, fields.many2one): if isinstance(f, fields.many2one):
if not self.pool.get(f._obj): if f._obj not in self.pool:
raise except_orm('Programming Error', 'There is no reference available for %s' % (f._obj,)) raise except_orm('Programming Error', 'There is no reference available for %s' % (f._obj,))
dest_model = self.pool.get(f._obj) dest_model = self.pool[f._obj]
ref = dest_model._table ref = dest_model._table
# ir_actions is inherited so foreign key doesn't work on it # ir_actions is inherited so foreign key doesn't work on it
if ref != 'ir_actions': if ref != 'ir_actions':
@ -3299,9 +3298,8 @@ class BaseModel(object):
def _o2m_raise_on_missing_reference(self, cr, f): def _o2m_raise_on_missing_reference(self, cr, f):
# TODO this check should be a method on fields.one2many. # TODO this check should be a method on fields.one2many.
if f._obj in self.pool:
other = self.pool.get(f._obj) other = self.pool[f._obj]
if other:
# TODO the condition could use fields_get_keys(). # TODO the condition could use fields_get_keys().
if f._fields_id not in other._columns.keys(): if f._fields_id not in other._columns.keys():
if f._fields_id not in other._inherit_fields.keys(): if f._fields_id not in other._inherit_fields.keys():
@ -3312,9 +3310,9 @@ class BaseModel(object):
self._save_relation_table(cr, m2m_tbl) self._save_relation_table(cr, m2m_tbl)
cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (m2m_tbl,)) cr.execute("SELECT relname FROM pg_class WHERE relkind IN ('r','v') AND relname=%s", (m2m_tbl,))
if not cr.dictfetchall(): if not cr.dictfetchall():
if not self.pool.get(f._obj): if f._obj not in self.pool:
raise except_orm('Programming Error', 'Many2Many destination model does not exist: `%s`' % (f._obj,)) raise except_orm('Programming Error', 'Many2Many destination model does not exist: `%s`' % (f._obj,))
dest_model = self.pool.get(f._obj) dest_model = self.pool[f._obj]
ref = dest_model._table ref = dest_model._table
cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL, UNIQUE("%s","%s"))' % (m2m_tbl, col1, col2, col1, col2)) cr.execute('CREATE TABLE "%s" ("%s" INTEGER NOT NULL, "%s" INTEGER NOT NULL, UNIQUE("%s","%s"))' % (m2m_tbl, col1, col2, col1, col2))
# create foreign key references with ondelete=cascade, unless the targets are SQL views # create foreign key references with ondelete=cascade, unless the targets are SQL views
@ -3419,7 +3417,7 @@ class BaseModel(object):
""" """
res = {} res = {}
for table in self._inherits: for table in self._inherits:
other = self.pool.get(table) other = self.pool[table]
for col in other._columns.keys(): for col in other._columns.keys():
res[col] = (table, self._inherits[table], other._columns[col], table) res[col] = (table, self._inherits[table], other._columns[col], table)
for col in other._inherit_fields.keys(): for col in other._inherit_fields.keys():
@ -3503,7 +3501,7 @@ class BaseModel(object):
translation_obj = self.pool.get('ir.translation') translation_obj = self.pool.get('ir.translation')
for parent in self._inherits: for parent in self._inherits:
res.update(self.pool.get(parent).fields_get(cr, user, allfields, context)) res.update(self.pool[parent].fields_get(cr, user, allfields, context))
for f, field in self._columns.iteritems(): for f, field in self._columns.iteritems():
if (allfields and f not in allfields) or \ if (allfields and f not in allfields) or \
@ -3669,7 +3667,7 @@ class BaseModel(object):
cols = [x for x in intersect(self._inherit_fields.keys(), fields_to_read) if x not in self._columns.keys()] cols = [x for x in intersect(self._inherit_fields.keys(), fields_to_read) if x not in self._columns.keys()]
if not cols: if not cols:
continue continue
res2 = self.pool.get(table).read(cr, user, [x[col] for x in res], cols, context, load) res2 = self.pool[table].read(cr, user, [x[col] for x in res], cols, context, load)
res3 = {} res3 = {}
for r in res2: for r in res2:
@ -4009,9 +4007,9 @@ class BaseModel(object):
if ir_value_ids: if ir_value_ids:
ir_values_obj.unlink(cr, uid, ir_value_ids, context=context) ir_values_obj.unlink(cr, uid, ir_value_ids, context=context)
for order, object, store_ids, fields in result_store: for order, obj_name, store_ids, fields in result_store:
if object != self._name: if obj_name != self._name:
obj = self.pool.get(object) obj = self.pool[obj_name]
cr.execute('select id from '+obj._table+' where id IN %s', (tuple(store_ids),)) cr.execute('select id from '+obj._table+' where id IN %s', (tuple(store_ids),))
rids = map(lambda x: x[0], cr.fetchall()) rids = map(lambda x: x[0], cr.fetchall())
if rids: if rids:
@ -4175,7 +4173,7 @@ class BaseModel(object):
# TODO: optimize # TODO: optimize
for f in direct: for f in direct:
if self._columns[f].translate: if self._columns[f].translate:
src_trans = self.pool.get(self._name).read(cr, user, ids, [f])[0][f] src_trans = self.pool[self._name].read(cr, user, ids, [f])[0][f]
if not src_trans: if not src_trans:
src_trans = vals[f] src_trans = vals[f]
# Inserting value to DB # Inserting value to DB
@ -4211,7 +4209,7 @@ class BaseModel(object):
v[val] = vals[val] v[val] = vals[val]
unknown_fields.remove(val) unknown_fields.remove(val)
if v: if v:
self.pool.get(table).write(cr, user, nids, v, context) self.pool[table].write(cr, user, nids, v, context)
if unknown_fields: if unknown_fields:
_logger.warning( _logger.warning(
@ -4277,8 +4275,8 @@ class BaseModel(object):
result.sort() result.sort()
done = {} done = {}
for order, object, ids_to_update, fields_to_recompute in result: for order, model_name, ids_to_update, fields_to_recompute in result:
key = (object, tuple(fields_to_recompute)) key = (model_name, tuple(fields_to_recompute))
done.setdefault(key, {}) done.setdefault(key, {})
# avoid to do several times the same computation # avoid to do several times the same computation
todo = [] todo = []
@ -4286,7 +4284,7 @@ class BaseModel(object):
if id not in done[key]: if id not in done[key]:
done[key][id] = True done[key][id] = True
todo.append(id) todo.append(id)
self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context) self.pool[model_name]._store_set_values(cr, user, todo, fields_to_recompute, context)
self.step_workflow(cr, user, ids, context=context) self.step_workflow(cr, user, ids, context=context)
return True return True
@ -4379,9 +4377,9 @@ class BaseModel(object):
parent_context.pop('no_store_function', None) parent_context.pop('no_store_function', None)
if record_id is None or not record_id: if record_id is None or not record_id:
record_id = self.pool.get(table).create(cr, user, tocreate[table], context=parent_context) record_id = self.pool[table].create(cr, user, tocreate[table], context=parent_context)
else: else:
self.pool.get(table).write(cr, user, [record_id], tocreate[table], context=parent_context) self.pool[table].write(cr, user, [record_id], tocreate[table], context=parent_context)
upd0 += ',' + self._inherits[table] upd0 += ',' + self._inherits[table]
upd1 += ',%s' upd1 += ',%s'
@ -4493,10 +4491,10 @@ class BaseModel(object):
result += self._store_get_values(cr, user, [id_new], vals.keys(), context) result += self._store_get_values(cr, user, [id_new], vals.keys(), context)
result.sort() result.sort()
done = [] done = []
for order, object, ids, fields2 in result: for order, model_name, ids, fields2 in result:
if not (object, ids, fields2) in done: if not (model_name, ids, fields2) in done:
self.pool.get(object)._store_set_values(cr, user, ids, fields2, context) self.pool[model_name]._store_set_values(cr, user, ids, fields2, context)
done.append((object, ids, fields2)) done.append((model_name, ids, fields2))
if self._log_create and not (context and context.get('no_store_function', False)): if self._log_create and not (context and context.get('no_store_function', False)):
message = self._description + \ message = self._description + \
@ -4720,7 +4718,7 @@ class BaseModel(object):
# to reach the parent table (if it was not JOINed yet in the query) # to reach the parent table (if it was not JOINed yet in the query)
parent_alias = child_object._inherits_join_add(child_object, parent_model, query) parent_alias = child_object._inherits_join_add(child_object, parent_model, query)
# inherited rules are applied on the external table -> need to get the alias and replace # inherited rules are applied on the external table -> need to get the alias and replace
parent_table = self.pool.get(parent_model)._table parent_table = self.pool[parent_model]._table
added_clause = [clause.replace('"%s"' % parent_table, '"%s"' % parent_alias) for clause in added_clause] added_clause = [clause.replace('"%s"' % parent_table, '"%s"' % parent_alias) for clause in added_clause]
# change references to parent_table to parent_alias, because we now use the alias to refer to the table # change references to parent_table to parent_alias, because we now use the alias to refer to the table
new_tables = [] new_tables = []
@ -4775,7 +4773,7 @@ class BaseModel(object):
return return
# figure out the applicable order_by for the m2o # figure out the applicable order_by for the m2o
dest_model = self.pool.get(order_field_column._obj) dest_model = self.pool[order_field_column._obj]
m2o_order = dest_model._order m2o_order = dest_model._order
if not regex_order.match(m2o_order): if not regex_order.match(m2o_order):
# _order is complex, can't use it here, so we default to _rec_name # _order is complex, can't use it here, so we default to _rec_name
@ -4822,7 +4820,7 @@ class BaseModel(object):
else: else:
continue # ignore non-readable or "non-joinable" fields continue # ignore non-readable or "non-joinable" fields
elif order_field in self._inherit_fields: elif order_field in self._inherit_fields:
parent_obj = self.pool.get(self._inherit_fields[order_field][3]) parent_obj = self.pool[self._inherit_fields[order_field][3]]
order_column = parent_obj._columns[order_field] order_column = parent_obj._columns[order_field]
if order_column._classic_read: if order_column._classic_read:
inner_clause = self._inherits_join_calc(order_field, query) inner_clause = self._inherits_join_calc(order_field, query)
@ -4895,7 +4893,7 @@ class BaseModel(object):
if not args: if not args:
args = [] args = []
if field in self._inherit_fields: if field in self._inherit_fields:
return self.pool.get(self._inherit_fields[field][0]).distinct_field_get(cr, uid, field, value, args, offset, limit) return self.pool[self._inherit_fields[field][0]].distinct_field_get(cr, uid, field, value, args, offset, limit)
else: else:
return self._columns[field].search(cr, self, args, field, value, offset, limit, uid) return self._columns[field].search(cr, self, args, field, value, offset, limit, uid)
@ -4949,9 +4947,9 @@ class BaseModel(object):
if field_to_other in default: if field_to_other in default:
# all the fields of 'other' are given by the record: default[field_to_other], # all the fields of 'other' are given by the record: default[field_to_other],
# except the ones redefined in self # except the ones redefined in self
blacklist.update(set(self.pool.get(other)._all_columns) - set(self._columns)) blacklist.update(set(self.pool[other]._all_columns) - set(self._columns))
else: else:
blacklist_given_fields(self.pool.get(other)) blacklist_given_fields(self.pool[other])
blacklist_given_fields(self) blacklist_given_fields(self)
res = dict(default) res = dict(default)
@ -4966,7 +4964,7 @@ class BaseModel(object):
elif field._type == 'many2one': elif field._type == 'many2one':
res[f] = data[f] and data[f][0] res[f] = data[f] and data[f][0]
elif field._type == 'one2many': elif field._type == 'one2many':
other = self.pool.get(field._obj) other = self.pool[field._obj]
# duplicate following the order of the ids because we'll rely on # duplicate following the order of the ids because we'll rely on
# it later for copying translations in copy_translation()! # it later for copying translations in copy_translation()!
lines = [other.copy_data(cr, uid, line_id, context=context) for line_id in sorted(data[f])] lines = [other.copy_data(cr, uid, line_id, context=context) for line_id in sorted(data[f])]
@ -4998,7 +4996,7 @@ class BaseModel(object):
for field_name, field_def in fields.items(): for field_name, field_def in fields.items():
# we must recursively copy the translations for o2o and o2m # we must recursively copy the translations for o2o and o2m
if field_def['type'] == 'one2many': if field_def['type'] == 'one2many':
target_obj = self.pool.get(field_def['relation']) target_obj = self.pool[field_def['relation']]
old_record, new_record = self.read(cr, uid, [old_id, new_id], [field_name], context=context) old_record, new_record = self.read(cr, uid, [old_id, new_id], [field_name], context=context)
# here we rely on the order of the ids to match the translations # here we rely on the order of the ids to match the translations
# as foreseen in copy_data() # as foreseen in copy_data()
@ -5267,7 +5265,7 @@ class BaseModel(object):
result, record_ids = [], list(command[2]) result, record_ids = [], list(command[2])
# read the records and apply the updates # read the records and apply the updates
other_model = self.pool.get(self._all_columns[field_name].column._obj) other_model = self.pool[self._all_columns[field_name].column._obj]
for record in other_model.read(cr, uid, record_ids, fields=fields, context=context): for record in other_model.read(cr, uid, record_ids, fields=fields, context=context):
record.update(updates.get(record['id'], {})) record.update(updates.get(record['id'], {}))
result.append(record) result.append(record)

View File

@ -201,7 +201,7 @@ class document(object):
args = [] args = []
# get the object # get the object
if 'model' in attrs: if 'model' in attrs:
obj = self.pool.get(attrs['model']) obj = self.pool[attrs['model']]
else: else:
if isinstance(browser, list): if isinstance(browser, list):
obj = browser[0]._table obj = browser[0]._table

View File

@ -116,8 +116,8 @@ def check(f):
last_quote_begin = errortxt.rfind('"', 0, last_quote_end) last_quote_begin = errortxt.rfind('"', 0, last_quote_end)
model_name = table = errortxt[last_quote_begin+1:last_quote_end].strip() model_name = table = errortxt[last_quote_begin+1:last_quote_end].strip()
model = table.replace("_",".") model = table.replace("_",".")
model_obj = registry.get(model) if model in registry:
if model_obj: model_obj = registry[model]
model_name = model_obj._description or model_obj._name model_name = model_obj._description or model_obj._name
msg += _('\n\n[object with reference: %s - %s]') % (model_name, model) msg += _('\n\n[object with reference: %s - %s]') % (model_name, model)
except Exception: except Exception:

View File

@ -15,9 +15,9 @@ def registry(model):
def cursor(): def cursor():
return openerp.modules.registry.RegistryManager.get(DB).db.cursor() return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
def get_module(module_name): def model_exists(model_name):
registry = openerp.modules.registry.RegistryManager.get(DB) registry = openerp.modules.registry.RegistryManager.get(DB)
return registry.get(module_name) return model_name in registry
def reload_registry(): def reload_registry():
openerp.modules.registry.RegistryManager.new( openerp.modules.registry.RegistryManager.new(
@ -61,7 +61,7 @@ class test_uninstall(unittest2.TestCase):
def test_01_install(self): def test_01_install(self):
""" Check a few things showing the module is installed. """ """ Check a few things showing the module is installed. """
install_module('test_uninstall') install_module('test_uninstall')
assert get_module('test_uninstall.model') assert model_exists('test_uninstall.model')
assert search_registry('ir.model.data', assert search_registry('ir.model.data',
[('module', '=', 'test_uninstall')]) [('module', '=', 'test_uninstall')])
@ -72,7 +72,7 @@ class test_uninstall(unittest2.TestCase):
def test_02_uninstall(self): def test_02_uninstall(self):
""" Check a few things showing the module is uninstalled. """ """ Check a few things showing the module is uninstalled. """
uninstall_module('test_uninstall') uninstall_module('test_uninstall')
assert not get_module('test_uninstall.model') assert not model_exists('test_uninstall.model')
assert not search_registry('ir.model.data', assert not search_registry('ir.model.data',
[('module', '=', 'test_uninstall')]) [('module', '=', 'test_uninstall')])

View File

@ -659,7 +659,7 @@ def trans_generate(lang, modules, cr):
model = encode(model) model = encode(model)
xml_name = "%s.%s" % (module, encode(xml_name)) xml_name = "%s.%s" % (module, encode(xml_name))
if not registry.get(model): if model not in registry:
_logger.error("Unable to find object %r", model) _logger.error("Unable to find object %r", model)
continue continue
@ -764,12 +764,12 @@ def trans_generate(lang, modules, cr):
push_constraint_msg(module, term_type, model._name, constraint[msg_pos]) push_constraint_msg(module, term_type, model._name, constraint[msg_pos])
for (_, model, module) in cr.fetchall(): for (_, model, module) in cr.fetchall():
model_obj = registry.get(model) if model not in registry:
if not model_obj:
_logger.error("Unable to find object %r", model) _logger.error("Unable to find object %r", model)
continue continue
model_obj = registry[model]
if model_obj._constraints: if model_obj._constraints:
push_local_constraints(module, model_obj, 'constraints') push_local_constraints(module, model_obj, 'constraints')

View File

@ -769,7 +769,7 @@ class YamlInterpreter(object):
def process_delete(self, node): def process_delete(self, node):
assert getattr(node, 'model'), "Attribute %s of delete tag is empty !" % ('model',) assert getattr(node, 'model'), "Attribute %s of delete tag is empty !" % ('model',)
if self.pool.get(node.model): if node.model in self.pool:
if node.search: if node.search:
ids = self.pool[node.model].search(self.cr, self.uid, eval(node.search, self.eval_context)) ids = self.pool[node.model].search(self.cr, self.uid, eval(node.search, self.eval_context))
else: else:

View File

@ -13,7 +13,7 @@ def run(args):
openerp.netsvc.init_logger() openerp.netsvc.init_logger()
registry = openerp.modules.registry.RegistryManager.get( registry = openerp.modules.registry.RegistryManager.get(
args.database, update_module=False) args.database, update_module=False)
model = registry.get(args.model) model = registry[args.model]
longest_k = 1 longest_k = 1
longest_string = 1 longest_string = 1
columns = model._columns columns = model._columns

View File

@ -19,7 +19,7 @@ def run(args):
openerp.netsvc.init_logger() openerp.netsvc.init_logger()
registry = openerp.modules.registry.RegistryManager.get( registry = openerp.modules.registry.RegistryManager.get(
args.database, update_module=False) args.database, update_module=False)
model = registry.get(args.model) model = registry[args.model]
cr = registry.db.cursor() # TODO context manager cr = registry.db.cursor() # TODO context manager
field_names = [args.field] if args.field else [] field_names = [args.field] if args.field else []
if args.short: if args.short: