From 2d7a32a223d49cbac485d515d01076bfba5f2eb9 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 15 Nov 2022 09:13:19 +0000 Subject: [PATCH] [FIX] web: do not combine field domain with view domain Have a many2one field with a domain set in the field definition in python. Use this field in an editable list view, with a domain set on the field node. For instance, go to Sales > Sales Team and see Team Leader field. Before this commit, we combined the field domain with the domain set in the view, which isn't the spec. The spec is to use the domain set in the view if there is one, and if there is not, use the field domain (see _getDomain in basic_model.js). In the scenario described above, it produced a crash because the field domain couldn't be evaluated with the fields defined in the view. This commit restores the previous behavior. closes odoo/odoo#105774 X-original-commit: 32654fd17ab366d20fff8b3fc8134ee209569f1d Signed-off-by: Lucas Perais (lpe) Signed-off-by: Aaron Bohy (aab) --- .../web/static/src/views/relational_model.js | 3 +-- .../views/fields/many2one_field_tests.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/relational_model.js b/addons/web/static/src/views/relational_model.js index 87c8335791b..15b29506aad 100644 --- a/addons/web/static/src/views/relational_model.js +++ b/addons/web/static/src/views/relational_model.js @@ -754,8 +754,7 @@ export class Record extends DataPoint { getFieldDomain(fieldName) { const rawDomains = [ this._domains[fieldName] || [], - this.fields[fieldName].domain || [], - this.activeFields[fieldName].domain, + this.activeFields[fieldName].domain || this.fields[fieldName].domain || [], ]; const evalContext = this.evalContext; diff --git a/addons/web/static/tests/views/fields/many2one_field_tests.js b/addons/web/static/tests/views/fields/many2one_field_tests.js index d7edf34b600..81286693fbf 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -3602,6 +3602,33 @@ QUnit.module("Fields", (hooks) => { assert.containsOnce(target, ".o_field_many2one .o-autocomplete--dropdown-item"); }); + QUnit.test("many2one: domain set in view and on field", async function (assert) { + assert.expect(2); + serverData.models.partner.fields.trululu.domain = "[('foo' ,'=', 'boum')]"; + + await makeView({ + type: "list", + resModel: "partner", + serverData, + arch: ` + + + + `, + mockRPC(route, { kwargs, method }) { + if (method === "name_search") { + // should only use the domain set in the view + assert.deepEqual(kwargs.args, [["foo", "=", "blip"]]); + } + }, + }); + + await click(target.querySelectorAll(".o_data_cell")[0]); + await click(target, ".o_field_many2one input"); + + assert.containsOnce(target, ".o_field_many2one .o-autocomplete--dropdown-item"); + }); + QUnit.test("many2one: domain updated by an onchange", async function (assert) { assert.expect(2);