From c4296a85ac4b87904da80968cc7c345d1417889f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 10 Oct 2011 13:26:21 +0200 Subject: [PATCH] [fix] problem with some domains that need evaluation bzr revid: nicolas.vanhoren@openerp.com-20111010112621-3kl83keyjingzus8 --- addons/web/common/nonliterals.py | 8 +++++--- addons/web/static/src/js/view_form.js | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/addons/web/common/nonliterals.py b/addons/web/common/nonliterals.py index 4db333a5769..986ca36cb2f 100644 --- a/addons/web/common/nonliterals.py +++ b/addons/web/common/nonliterals.py @@ -199,6 +199,11 @@ class CompoundDomain(BaseDomain): self.add(domain) def evaluate(self, context=None): + ctx = dict(context or {}) + eval_context = self.get_eval_context() + if eval_context: + eval_context = self.session.eval_context(eval_context) + ctx.update(eval_context) final_domain = [] for domain in self.domains: if not isinstance(domain, (list, BaseDomain)): @@ -208,9 +213,6 @@ class CompoundDomain(BaseDomain): if isinstance(domain, list): final_domain.extend(domain) continue - - ctx = dict(context or {}) - ctx.update(self.get_eval_context() or {}) domain.session = self.session final_domain.extend(domain.evaluate(ctx)) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 22682ecbabb..4df2e812d32 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1083,7 +1083,11 @@ openerp.web.form.Field = openerp.web.form.Widget.extend(/** @lends openerp.web.f * the fields'context with the action's context. */ build_context: function() { - var f_context = this.field.context || null; + var f_context = this.field.context || {}; + if (!!f_context.__ref) { + var fields_values = this._build_eval_context(); + f_context = new openerp.web.CompoundDomain(f_context).set_eval_context(fields_values); + } // maybe the default_get should only be used when we do a default_get? var v_contexts = _.compact([this.node.attrs.default_get || null, this.node.attrs.context || null]); @@ -1098,14 +1102,15 @@ openerp.web.form.Field = openerp.web.form.Widget.extend(/** @lends openerp.web.f return ctx; }, build_domain: function() { - var f_domain = this.field.domain || null; - var v_domain = this.node.attrs.domain || []; - if (!(v_domain instanceof Array) || true) { //TODO niv: remove || true - var fields_values = this._build_eval_context(); - v_domain = new openerp.web.CompoundDomain(v_domain).set_eval_context(fields_values); - } + var f_domain = this.field.domain || []; + var n_domain = this.node.attrs.domain || null; // if there is a domain on the node, overrides the model's domain - return f_domain || v_domain; + var final_domain = n_domain !== null ? n_domain : f_domain; + if (!(final_domain instanceof Array)) { + var fields_values = this._build_eval_context(); + final_domain = new openerp.web.CompoundDomain(final_domain).set_eval_context(fields_values); + } + return final_domain; } });