[FIX] web: m2o field use the right context

When we save a many2one in a dialog opened by the external button, we
trigger a "read" of the "display_name" to update it if the changes made
in the dialog have had an impact on it.
Before this commit, the context used for this "read" was completely wrong,
it was an unevaluated string. This commit will therefore allow you to use
the evaluated context.

closes odoo/odoo#142862

X-original-commit: 7e9c8d41f5d035a00117198539ddebdbd8b4aa7c
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
This commit is contained in:
FrancoisGe
2023-11-21 22:00:09 +00:00
parent d71d52d16b
commit a24aa74602
2 changed files with 16 additions and 14 deletions
@@ -115,9 +115,10 @@ export class Many2OneField extends Component {
onRecordSaved: async (record) => {
const resId = this.value[0];
const fields = ["display_name"];
const { context } = this.props;
// use unity read + relatedFields from Field Component
const records = await this.orm.read(this.relation, [resId], fields, { context });
const records = await this.orm.read(this.relation, [resId], fields, {
context: this.context,
});
await this.updateRecord(m2oTupleFromData(records[0]));
},
onClose: () => this.focusInput(),
@@ -378,16 +378,22 @@ QUnit.module("Fields", (hooks) => {
arch: `
<form>
<sheet>
<field name="trululu"/>
<field name="int_field" />
<field name="trululu" context="{'blip': int_field, 'blop': 3}"/>
</sheet>
</form>`,
mockRPC(route, { method }) {
mockRPC(route, { args, method, model, kwargs }) {
if (method === "get_formview_id") {
return Promise.resolve(false);
}
if (method === "web_save") {
assert.step("web_save");
}
if (method === "read" && model === "partner" && args[0][0] === 4) {
assert.step(`read partner: ${args[1]}`);
assert.strictEqual(kwargs.context.blip, 10);
assert.strictEqual(kwargs.context.blop, 3);
}
},
});
@@ -402,7 +408,7 @@ QUnit.module("Fields", (hooks) => {
// save and close modal
await clickSave(target.querySelectorAll(".modal")[1]);
assert.verifySteps(["web_save"]);
assert.verifySteps(["web_save", "read partner: display_name"]);
// save form
await clickSave(target);
assert.verifySteps([]);
@@ -4572,21 +4578,16 @@ QUnit.module("Fields", (hooks) => {
</form>`,
mockRPC(route, { method, kwargs }) {
if (method === "name_search") {
return Promise.resolve([
[1, false]
]);
return Promise.resolve([[1, false]]);
}
},
});
const input = target.querySelector(".o_field_many2one input");
await click(input);
await triggerEvents(input, null, ["input", "change"]);
let dropdown = target.querySelector(".o_field_many2one[name='trululu'] .dropdown-menu")
assert.strictEqual(
dropdown.querySelector("a.dropdown-item").text,
"Unnamed"
);
const dropdown = target.querySelector(".o_field_many2one[name='trululu'] .dropdown-menu");
assert.strictEqual(dropdown.querySelector("a.dropdown-item").text, "Unnamed");
});
});