[IMP] ir.model.data: get_object() never raises an exception when check=False
bzr revid: rco@openerp.com-20140123103306-tilma2dahgfsm70t
This commit is contained in:
parent
5b0ff455c5
commit
d68bb48e44
|
@ -29,7 +29,7 @@ import openerp.modules.registry
|
|||
from openerp import SUPERUSER_ID
|
||||
from openerp import tools
|
||||
from openerp.osv import fields,osv
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv.orm import Model, browse_null
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
from openerp.tools import config
|
||||
from openerp.tools.translate import _
|
||||
|
@ -884,18 +884,26 @@ class ir_model_data(osv.osv):
|
|||
raise ValueError('Not enough access rights on the external ID: %s.%s' % (module, xml_id))
|
||||
return model, False
|
||||
|
||||
def get_object(self, cr, uid, module, xml_id, context=None, check_existence_and_raise=True):
|
||||
""" Returns a browsable record for the given module name and xml_id or
|
||||
raise ValueError if not found
|
||||
def get_object(self, cr, uid, module, xml_id, context=None, check=True):
|
||||
""" Returns a browsable record for the given module name and xml_id.
|
||||
If not found, raise a ValueError or return a browse_null, depending
|
||||
on the value of `check`.
|
||||
|
||||
:param boolean check_existence_and_raise: v7 compatibility mode, check
|
||||
existence and raise if not found
|
||||
:param check: when true, check whether record exists and raise a
|
||||
ValueError if it does not; otherwise return a browse_null or
|
||||
non-existing record.
|
||||
"""
|
||||
res_model, res_id = self.get_object_reference(cr, uid, module, xml_id)
|
||||
result = self.pool[res_model].browse(cr, uid, res_id, context=context)
|
||||
if check_existence_and_raise and not result.exists():
|
||||
try:
|
||||
res_model, res_id = self.get_object_reference(cr, uid, module, xml_id)
|
||||
record = self.pool[res_model].browse(cr, uid, res_id, context=context)
|
||||
except ValueError:
|
||||
if check:
|
||||
raise
|
||||
return browse_null()
|
||||
|
||||
if check and not record.exists():
|
||||
raise ValueError('No record found for unique ID %s.%s. It may have been deleted.' % (module, xml_id))
|
||||
return result
|
||||
return record
|
||||
|
||||
def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True):
|
||||
if not xml_id:
|
||||
|
|
|
@ -685,10 +685,7 @@ class groups_view(osv.osv):
|
|||
# and introduces the reified group fields
|
||||
# we have to try-catch this, because at first init the view does not exist
|
||||
# but we are already creating some basic groups
|
||||
try:
|
||||
view = self.pool['ir.model.data'].get_object(cr, SUPERUSER_ID, 'base', 'user_groups_view', context=context, check_existence_and_raise=False)
|
||||
except ValueError:
|
||||
view = False
|
||||
view = self.pool['ir.model.data'].get_object(cr, SUPERUSER_ID, 'base', 'user_groups_view', context=context, check=False)
|
||||
if view and view.exists() and view._table_name == 'ir.ui.view':
|
||||
xml1, xml2 = [], []
|
||||
xml1.append(E.separator(string=_('Application'), colspan="4"))
|
||||
|
|
Loading…
Reference in New Issue