[FIX] web: fix the Reference field in list view with a default value
Bug === If the Reference field is in a list view, and has a default value, an error is raised if we create a new record without editing the reference value. This is because the ORM return a string "model,id" in the onchange method and this value is wrongly parsed in that case. Task-2234179 closes odoo/odoo#113392 X-original-commit: b1a35d1b95612bc449b68ed38749d8b3755287ed Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
This commit is contained in:
@@ -724,7 +724,9 @@ export class Record extends DataPoint {
|
||||
: false;
|
||||
} else if (fieldType === "reference") {
|
||||
const value = changes[fieldName];
|
||||
changes[fieldName] = value ? `${value.resModel},${value.resId}` : false;
|
||||
changes[fieldName] = value && value.resModel && value.resId
|
||||
? `${value.resModel},${value.resId}`
|
||||
: (value || false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -845,6 +845,36 @@ QUnit.module("Fields", (hooks) => {
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("Reference field with default value in list view", async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<tree string="Test" editable="top">
|
||||
<field name="reference"/>
|
||||
<field name="display_name"/>
|
||||
</tree>`,
|
||||
mockRPC: (route, { method, args }) => {
|
||||
if (method === "onchange") {
|
||||
return {
|
||||
value: {reference: "partner,2"},
|
||||
};
|
||||
} else if (method === "create") {
|
||||
assert.strictEqual(args.length, 1);
|
||||
assert.strictEqual(args[0][0].reference, "partner,2");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await click(target, '.o_list_button_add');
|
||||
await click(target, '.o_list_char[name="display_name"] input');
|
||||
await editInput(target, '.o_list_char[name="display_name"] input', "Blabla");
|
||||
await click(target, '.o_list_button_save');
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"ReferenceField with model_field option (tree list in form view)",
|
||||
async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user