diff --git a/addons/web/static/src/views/fields/properties/property_value.xml b/addons/web/static/src/views/fields/properties/property_value.xml index 019b330466e..f7ab6bf1ca5 100644 --- a/addons/web/static/src/views/fields/properties/property_value.xml +++ b/addons/web/static/src/views/fields/properties/property_value.xml @@ -92,6 +92,7 @@ { ); }); + /** + * When the user creates a property field of type many2many, many2one, etc. + * and changes the co-model of the field, the model loaded by the "Search more..." + * modal should correspond to the selected model and should be updated dynamically. + */ + QUnit.test("properties: many2one 'Search more...'", async function (assert) { + async function mockRPC(route, { method, model }) { + if (method === "check_access_rights") { + return true; + } else if (method === "display_name_for" && model === "ir.model") { + return [ + { model: "partner", display_name: "Partner" }, + { model: "res.users", display_name: "User" }, + ]; + } else if (method === "get_available_models" && model === "ir.model") { + return [ + { model: "partner", display_name: "Partner" }, + { model: "res.users", display_name: "User" }, + ]; + } + } + + // Patch the test data + serverData.models.partner.records = [ + { + id: 1, + company_id: 37, + display_name: "Pierre", + properties: [ + { + name: "many_2_one", + type: "many2one", + string: "My Many-2-one", + comodel: "partner", + }, + ], + }, + ]; + serverData.views = { + "partner,false,list": ` + + + + `, + "res.users,false,list": ` + + + + `, + "res.users,false,search": ``, + }; + + // Patch the Many2XAutocomplete default search limit options + patchWithCleanup(Many2XAutocomplete.defaultProps, { + searchLimit: -1, + }); + + // Patch the SelectCreateDialog component + patchWithCleanup(SelectCreateDialog.prototype, { + /** + * @override + */ + setup() { + this._super(); + assert.step(this.props.resModel); + }, + }); + + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: ` +
+ + + + + + +
`, + mockRPC, + }); + + // Opening the popover + await click(target, '[property-name="many_2_one"] .o_field_property_open_popover'); + const popover = target.querySelector(".o_property_field_popover"); + + // Opening the "Search more..." modal + await click(popover, ".o_field_property_definition_value input"); + await click(popover, ".o_m2o_dropdown_option_search_more"); + + // Checking the model loaded + assert.verifySteps(["partner"]); + + // Closing the modal + await click(target.querySelector(".modal"), ".btn-close"); + + // Switching the co-model of the property field + await click(popover, ".o_field_property_definition_model input"); + await click(popover, ".o_field_property_definition_model .ui-menu-item:nth-child(2)"); + + // Opening the "Search more..." modal + await click(popover, ".o_field_property_definition_value input"); + await click(popover, ".o_m2o_dropdown_option_search_more"); + + // Checking the model loaded + assert.verifySteps(["res.users"]); + }); + QUnit.test("properties: date(time) property manipulations", async function (assert) { serverData.models.partner.records.push({ id: 5000,