[FIX] web: update reference resModel with props

When ReferenceField uses an M2O field. The model is not updated along
with the props when the model field is updated.

Because of this, the onWillUpdateProps hook will keep trying to update
its value. This results in an infinite render loop.

task-3248500

closes odoo/odoo#139954

X-original-commit: f8f6aaa5e32967d6c7cd888fbe574acdc6f79dc6
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Renaud Thiry (reth) <reth@odoo.com>
This commit is contained in:
Renaud Thiry
2023-10-27 07:14:45 +00:00
parent 7940703757
commit 044cd8af7b
@@ -975,6 +975,52 @@ QUnit.module("Fields", (hooks) => {
}
);
QUnit.test(
"Change model field of a ReferenceField then select an invalid value (tree list in form view)",
async function (assert) {
serverData.models.turtle.records[0].partner_ids = [1];
serverData.models.partner.records[0].reference = "product,41";
serverData.models.partner.records[0].model_id = 20;
await makeView({
type: "form",
resModel: "turtle",
resId: 1,
serverData,
arch: `
<form>
<field name="partner_ids">
<tree editable="bottom">
<field name="name" />
<field name="model_id"/>
<field name="reference" required="true" options="{'model_field': 'model_id'}" class="reference_field" />
</tree>
</field>
</form>`,
});
assert.strictEqual(target.querySelector(".reference_field").textContent, "xpad");
assert.strictEqual(target.querySelector(".o_list_many2one").textContent, "Product");
await click(target, ".o_list_table td.o_list_many2one");
await click(target, ".o_list_table .o_list_many2one input");
//Select the "Partner" option, different from original "Product"
const dropdownItems = [...target.querySelectorAll(".o_list_table .o_list_many2one .o_input_dropdown .dropdown-item")];
await click(dropdownItems.filter(item => item.text === "Partner")[0]);
assert.strictEqual(target.querySelector(".reference_field input").value, "");
assert.strictEqual(target.querySelector(".o_list_many2one input").value, "Partner");
//Void the associated, required, "reference" field and make sure the form marks the field as required
await click(target, ".o_list_table .reference_field input");
const textInput = target.querySelector(".o_list_table .reference_field input");
textInput.setSelectionRange(0, textInput.value.length);
await triggerEvent(target, ".o_list_table .reference_field input", "keydown", {
key: "Backspace",
});
await click(target, ".o_form_view_container");
assert.containsOnce(target, ".o_list_table .reference_field.o_field_invalid");
}
);
QUnit.test("model selector is displayed only when it should be", async function (assert) {
//The model selector should be only displayed if
//there is no hide_model=True options AND no model_field specified