summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2013-12-06 10:58:53 +0100
committerThibault Delavallée <tde@openerp.com>2013-12-06 10:58:53 +0100
commitfea975aaa42fcd1f25cd4835311e755d6cd4cce3 (patch)
treefb33355157b1471769f7c4168544b713c09f70ee
parent72e67607f1ec384787a5362fd79265a165298003 (diff)
[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
-rw-r--r--openerp/addons/base/ir/ir_model.py14
1 files 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: