From 6cf7bc8838fef9262735e644728d05356918a227 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 10 Feb 2015 15:11:57 +0100 Subject: [PATCH] [FIX] models: invoke old-api onchange methods with context This helps fixing old-api onchange methods with a record id as a parameter. Browsing this record id may be problematic, since it reads the record in an environment with an empty context. This is really problematic when the record is a new record, because such a record only exists in a given environment. --- openerp/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openerp/models.py b/openerp/models.py index ace7abed3a1..e57264ccae4 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -5715,9 +5715,13 @@ class BaseModel(object): } params = eval("[%s]" % params, global_vars, field_vars) - # call onchange method + # call onchange method with context when possible args = (self._cr, self._uid, self._origin.ids) + tuple(params) - method_res = getattr(self._model, method)(*args) + try: + method_res = getattr(self._model, method)(*args, context=self._context) + except TypeError: + method_res = getattr(self._model, method)(*args) + if not isinstance(method_res, dict): return if 'value' in method_res: