From 8c3d71ccb88950ecc5741c76e7217e478e2f2988 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Jan 2015 17:43:18 +0100 Subject: [PATCH] [CHG] Fix task 7536 / PR #499 differently Issue was the propagation of contextual values across actions, more precisely conserving the selected fiscal year when selecting an account from the chart of accounts tree view: the chart of accounts tree view is generally opened for a specific fiscal year, and it seemed sensible that opening an account would show only the journal items for the previously selected fiscal years rather than all items ever. PR #649 altered action.read by tentatively evaluating the action's context, however this has the side-effect of providing evaluated contexts when creating or editing actions via the UI, usually breaking them in the process (as the context at this point is basically nonsensical for the action's purpose). This backs out the previous fix, and creates a fix restricted to the tree view's JS (thereby removing the feature for window actions not invoked from a tree view). closes #4677, closes #4690 --- addons/web/static/src/js/view_tree.js | 22 ++++++++--------- openerp/addons/base/ir/ir_actions.py | 35 ++++++++++++--------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js index 2f92042c4d0..380f1609a33 100644 --- a/addons/web/static/src/js/view_tree.js +++ b/addons/web/static/src/js/view_tree.js @@ -222,27 +222,25 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie var local_context = { active_model: self.dataset.model, active_id: id, - active_ids: [id]}; + active_ids: [id] + }; + var ctx = instance.web.pyeval.eval( + 'context', new instance.web.CompoundContext( + this.dataset.get_context(), local_context)); return this.rpc('/web/treeview/action', { id: id, model: this.dataset.model, - context: instance.web.pyeval.eval( - 'context', new instance.web.CompoundContext( - this.dataset.get_context(), local_context)) + context: ctx }).then(function (actions) { if (!actions.length) { return; } var action = actions[0][2]; - var c = new instance.web.CompoundContext(local_context); + var c = new instance.web.CompoundContext(local_context).set_eval_context(ctx); if (action.context) { c.add(action.context); } - return instance.web.pyeval.eval_domains_and_contexts({ - contexts: [c], domains: [] - }).then(function (res) { - action.context = res.context; - return self.do_action(action); - }, null); - }, null); + action.context = c; + return self.do_action(action); + }); }, // show & hide the contents diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 9112fc4f947..1aeb3703a10 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -316,7 +316,6 @@ class ir_actions_act_window(osv.osv): 'auto_search':True, 'multi': False, } - def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): """ call the method get_empty_list_help of the model and set the window action help message """ @@ -325,24 +324,22 @@ class ir_actions_act_window(osv.osv): ids = [ids] results = super(ir_actions_act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load) - context = dict(context or {}) - eval_dict = { - 'active_model': context.get('active_model'), - 'active_id': context.get('active_id'), - 'active_ids': context.get('active_ids'), - 'uid': uid, - 'context': context, - } - for res in results: - model = res.get('res_model') - if model in self.pool: - try: - with tools.mute_logger("openerp.tools.safe_eval"): - eval_context = eval(res['context'] or "{}", eval_dict) or {} - res['context'] = str(eval_context) - except Exception: - continue - if not fields or 'help' in fields: + if not fields or 'help' in fields: + context = dict(context or {}) + eval_dict = { + 'active_model': context.get('active_model'), + 'active_id': context.get('active_id'), + 'active_ids': context.get('active_ids'), + 'uid': uid, + } + for res in results: + model = res.get('res_model') + if model and self.pool.get(model): + try: + with tools.mute_logger("openerp.tools.safe_eval"): + eval_context = eval(res['context'] or "{}", eval_dict) or {} + except Exception: + continue custom_context = dict(context, **eval_context) res['help'] = self.pool[model].get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context) if ids_int: