From e8e6fecc2d135688a6788bd9bea61ebabb46f0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 30 Mar 2015 22:37:52 +0200 Subject: [PATCH] Filter leaf domain of Reference fields The domain of Reference fields must be filtered out for non-valid target because the localization will remove the target part and thus generate an invalid domain for the specific target. issue4680 review11141003 --- src/common.js | 16 ++++++++++++++++ src/model.js | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/common.js b/src/common.js index 6a6b619433..77e7e7ffac 100644 --- a/src/common.js +++ b/src/common.js @@ -1733,6 +1733,22 @@ return domain.map(this.inverse_leaf.bind(this)); } }, + filter_leaf: function(domain, field, model) { + if (~['AND', 'OR'].indexOf(domain)) { + return domain; + } else if (this.is_leaf(domain)) { + if (domain[0].startsWith(field) && (domain.length > 3)) { + if (domain[3] !== model) { + return ['id', '=', null]; + } + } + return domain; + } else { + return domain.map(function(d) { + return this.filter_leaf(d, field, model); + }.bind(this)); + } + }, eval_domain: function(domain, context, boolop) { if (boolop === undefined) { boolop = this.and; diff --git a/src/model.js b/src/model.js index 09b750b7e3..81b8a375f9 100644 --- a/src/model.js +++ b/src/model.js @@ -2059,6 +2059,19 @@ }, validation_domains: function(record, pre_validate) { return this.get_domains(record, pre_validate)[0]; + }, + get_domain: function(record) { + var model = null; + if (record._values[this.name]) { + model = record._values[this.name][0]; + } + var domains = this.get_domains(record); + var screen_domain = domains[0]; + var attr_domain = domains[1]; + var inversion = new Sao.common.DomainInversion(); + return inversion.concat([inversion.localize_domain( + inversion.filter_leaf(screen_domain, this.name, model)), + attr_domain]); } });