Skip to content
Snippets Groups Projects
Commit 2e2d1790 authored by Aaron Bohy's avatar Aaron Bohy
Browse files

[FIX] web: x2manys: correctly handle REPLACE_WITH operations


Have an x2many component that calls replaceWith with a list of
ids s.t. there're added **and** removed ids comparing to the
current value (e.g. the relation is currently [1, 2], and
replaceWith is called with [1, 3]). Before this commit, this didn't
work, and the resulting list of ids was empty. We never saw it
because no standard component allows to both add and remove at the
same time, but this can happen in custom components.

Issue reported by the PS-tech

closes odoo/odoo#136602

Signed-off-by: default avatarAaron Bohy (aab) <aab@odoo.com>
parent d8631646
Branches
Tags
No related merge requests found
......@@ -25,7 +25,7 @@ export function mapWowlValueToLegacy(value, type) {
case "one2many":
case "many2many":
if (value.operation === "REPLACE_WITH") {
return { operation: "REPLACE_WITH", ids: value.resIds };
return { operation: "REPLACE_WITH", ids: value.resIds || value.ids };
}
return value;
default:
......
/** @odoo-module **/
import { Component, xml } from "@odoo/owl";
import {
addRow,
click,
......@@ -2107,4 +2108,34 @@ QUnit.module("Fields", (hooks) => {
);
}
);
QUnit.test("many2many field calling replaceWith (add + remove)", async function (assert) {
serverData.models.partner.records[0].p = [1];
class MyX2Many extends Component {
onClick() {
this.props.value.replaceWith([2, 3]);
}
}
MyX2Many.template = xml`
<span class="ids" t-esc="this.props.value.resIds"/>
<button class="my_btn" t-on-click="onClick">To id</button>`;
registry.category("fields").add("my_x2many", MyX2Many);
await makeView({
type: "form",
resModel: "turtle",
serverData,
arch: `
<form>
<field name="partner_ids" widget="my_x2many"/>
</form>`,
resId: 2,
});
assert.strictEqual(target.querySelector(".ids").innerText, "2,4");
await click(target.querySelector(".my_btn"));
assert.strictEqual(target.querySelector(".ids").innerText, "2,3");
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment