From fea975aaa42fcd1f25cd4835311e755d6cd4cce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Dec 2013 10:58:53 +0100 Subject: [PATCH] [IMP] ir_model: get_object: re-introduce old behavior controlled by a new argument. This allows to have a method allowing the new behavior without breaking compatibility with all addons that are based on receiving a ValueError. bzr revid: tde@openerp.com-20131206095853-6waq2v2ajbgv02vp --- openerp/addons/base/ir/ir_model.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index 0b89e489c7d..7284fc5ba72 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -884,10 +884,18 @@ 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): - """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_existence_and_raise=True): + """ Returns a browsable record for the given module name and xml_id or + raise ValueError if not found + + :param boolean check_existence_and_raise: v7 compatibility mode, check + existence and raise if not found + """ res_model, res_id = self.get_object_reference(cr, uid, module, xml_id) - return self.pool[res_model].browse(cr, uid, res_id, context=context) + result = self.pool[res_model].browse(cr, uid, res_id, context=context) + if check_existence_and_raise and not result.exists(): + raise ValueError('No record found for unique ID %s.%s. It may have been deleted.' % (module, xml_id)) + return result def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True): if not xml_id: