Skip to content

Commit

Permalink
[FIX] web: multisave take manual changes into account with a single r…
Browse files Browse the repository at this point in the history
…ecord

Steps to reproduce
==================

- Go to documents
- Click on a document
- Add a tag

-> Nothing happens

Cause of the issue
==================

Since odoo/enterprise@e350177 ,
the documents app uses the _multiSave method from the relational_model.

If the selection is of only one record, the changes passed to the method
are ignored.

opw-3393862

closes odoo#128515

X-original-commit: 7e36176
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
  • Loading branch information
hubvd committed Jul 24, 2023
1 parent 3599c50 commit 877b8a9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions addons/web/static/src/views/relational_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,9 @@ class DynamicList extends DataPoint {
// Protected
// -------------------------------------------------------------------------

async _multiSave(record, changes = record.getChanges()) {
async _multiSave(record, changes) {
const hasManualChanges = Boolean(changes);
changes = changes || record.getChanges();
if (!changes) {
return;
}
Expand All @@ -1736,7 +1738,7 @@ class DynamicList extends DataPoint {
},
};
return this.model.dialogService.add(AlertDialog, dialogProps);
} else if (validSelection.length > 1) {
} else if (validSelection.length > 1 || hasManualChanges) {
this.editedRecord = null;
const resIds = validSelection.map((r) => r.resId);
try {
Expand Down
35 changes: 35 additions & 0 deletions addons/web/static/tests/views/list_view_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
} from "../search/helpers";
import { createWebClient, doAction, loadState } from "../webclient/helpers";
import { makeView, makeViewInDialog, setupViewRegistries } from "./helpers";
import { x2ManyCommands } from "@web/core/orm_service";

const fieldRegistry = registry.category("fields");
const serviceRegistry = registry.category("services");
Expand Down Expand Up @@ -19223,4 +19224,38 @@ QUnit.module("Views", (hooks) => {
"Monetary cells should have ltr direction"
);
});

QUnit.test("multisave take changes into account when there is only one record selected", async function (assert) {
const listView = registry.category("views").get("list");

class CustomListRenderer extends listView.Renderer {
onGlobalClick(ev) {
const record = this.props.list.selection[0];
record.model.root._multiSave(record, {
m2m: [x2ManyCommands.linkTo(1)],
});
}
}

registry.category("views").add("custom_list", {
...listView,
Renderer: CustomListRenderer,
}, { force: true });

await makeView({
type: "list",
resModel: "foo",
serverData,
resId: 3,
arch: '<tree js_class="custom_list"><field name="foo"/></tree>',
mockRPC: (route, { method, args }) => {
if (method === "write") {
assert.deepEqual(args[1], { m2m: [[x2ManyCommands.LINK_TO, 1, false]] });
}
},
});

await click(target.querySelectorAll(".o_data_row .o_list_record_selector input")[0]);
await click(target.querySelectorAll(".o_data_row [name=foo]")[0]);
});
});

0 comments on commit 877b8a9

Please sign in to comment.