[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) <lpe@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2022-11-15 18:25:53 +01:00
parent ba450b568f
commit 2d7a32a223
2 changed files with 28 additions and 2 deletions
@@ -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;
@@ -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: `
<tree editable="top">
<field name="foo" invisible="1"/>
<field name="trululu" domain="[['foo', '=', 'blip']]"/>
</tree>`,
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);