From ee9b28b5469b4e8284b0a2954dfa29d437d5194a Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Tue, 9 Aug 2022 07:32:30 +0000 Subject: [PATCH] [FIX] web: allow empty domains on arch Since the new views, the empty domains on the archs were not be taking into account. Now, the empty domains are taken into account, this was the legacy behaviour closes odoo/odoo#97791 Signed-off-by: Lucas Perais (lpe) --- .../src/views/basic_relational_model.js | 2 +- addons/web/static/src/views/fields/field.js | 4 ++- .../tests/views/form/form_view_tests.js | 30 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/basic_relational_model.js b/addons/web/static/src/views/basic_relational_model.js index 8ec8deb572a..8821fd5bd0c 100644 --- a/addons/web/static/src/views/basic_relational_model.js +++ b/addons/web/static/src/views/basic_relational_model.js @@ -100,7 +100,7 @@ function mapActiveFieldsToFieldsInfo(activeFields, fields, viewType, env) { } Widget = Widget || fieldRegistry.get("abstract"); let domain; - if (fieldDescr.domain && fieldDescr.domain.toString() !== "[]") { + if (fieldDescr.domain) { domain = fieldDescr.domain.toString(); } let mode = fieldDescr.viewMode; diff --git a/addons/web/static/src/views/fields/field.js b/addons/web/static/src/views/fields/field.js index 0e780230be9..853333198c6 100644 --- a/addons/web/static/src/views/fields/field.js +++ b/addons/web/static/src/views/fields/field.js @@ -201,7 +201,6 @@ Field.parseFieldNode = function (node, models, modelName, viewType, jsClass) { name, viewType, context: node.getAttribute("context") || "{}", - domain: node.getAttribute("domain") || "[]", string: node.getAttribute("string") || field.string, help: node.getAttribute("help"), widget, @@ -216,6 +215,9 @@ Field.parseFieldNode = function (node, models, modelName, viewType, jsClass) { options: evaluateExpr(node.getAttribute("options") || "{}"), alwaysInvisible: modifiers.invisible === true || modifiers.column_invisible === true, }; + if (node.getAttribute("domain")) { + fieldInfo.domain = node.getAttribute("domain"); + } for (const attribute of node.attributes) { if (attribute.name in Field.forbiddenAttributeNames) { throw new Error(Field.forbiddenAttributeNames[attribute.name]); diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 852322c1bb6..9745c07d87d 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -4042,6 +4042,33 @@ QUnit.module("Views", (hooks) => { assert.containsNone(document.body, ".modal", "there should not be a confirm modal"); }); + QUnit.test("Domain: allow empty domain on fieldInfo", async function (assert) { + assert.expect(1); + serverData.models.partner.fields.product_id.domain = "[('display_name', '=', name)]"; + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+
+ +
+ + + + + +
`, + resId: 1, + mockRPC(route, args) { + if (args.method === "search_read") { + assert.strictEqual(JSON.stringify(args.kwargs.domain), "[]"); + } + }, + }); + }); + QUnit.test("discard form with specialdata", async function (assert) { await makeView({ type: "form", @@ -11643,7 +11670,8 @@ QUnit.module("Views", (hooks) => { assert.containsOnce(target, ".o_form_editable"); assert.containsOnce(target, ".o_form_button_save"); assert.containsOnce(target, ".o_form_button_cancel"); - }); + } + ); QUnit.test("save a form view with an invisible required field", async function (assert) { serverData.models.partner.fields.text = { string: "Text", type: "char", required: 1 };