[FIX] web: reload record when you click on attach_document
The goal of this commit is to restore the behaviour of the legacy attach_document widget. How to reproduce : - clicking on the attach_document button and selecting a file In legacy: We have a full reload of the view (Render and reload the record). Before this commit: Render the view without reloading the record. After this commit: We reload the model which causes a rendering of the view and a reload of the record. Why do we have to reload the record ? If the action linked to the attach_document button modifies the record, we want this modification to be applied in the view and not only on the server side. To do this, we need to reload the record data to ensure that all the changes are displayed in the view. closes odoo/odoo#103891 X-original-commit: 82d4f0cd2f0265393cf66cd7be1a0a714584400c Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com> Signed-off-by: Georis François (fge) <fge@odoo.com>
This commit is contained in:
@@ -14,12 +14,13 @@ class AttachDocumentWidget extends Component {
|
||||
}
|
||||
|
||||
async onFileUploaded(files) {
|
||||
const { action } = this.props;
|
||||
const { action, record } = this.props;
|
||||
if (action) {
|
||||
const { model, resId, resModel } = this.props.record;
|
||||
const { model, resId, resModel } = record;
|
||||
await this.orm.call(resModel, action, [resId], {
|
||||
attachment_ids: files.map((file) => file.id),
|
||||
});
|
||||
await record.load();
|
||||
model.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,17 +53,19 @@ QUnit.module("Widgets", (hooks) => {
|
||||
serverData,
|
||||
resId: 1,
|
||||
mockRPC(route, args) {
|
||||
assert.step(args.method);
|
||||
if (args.method === "my_action") {
|
||||
assert.step("my_action");
|
||||
assert.deepEqual(args.model, "partner");
|
||||
assert.deepEqual(args.args, [1]);
|
||||
assert.deepEqual(args.kwargs.attachment_ids, [5, 2]);
|
||||
return true;
|
||||
}
|
||||
if (args.method === "write") {
|
||||
assert.step("write");
|
||||
assert.deepEqual(args.args[1], { display_name: "yop" });
|
||||
}
|
||||
if (args.method === "read") {
|
||||
assert.deepEqual(args.args[0], [1]);
|
||||
}
|
||||
},
|
||||
arch: `
|
||||
<form>
|
||||
@@ -71,6 +73,7 @@ QUnit.module("Widgets", (hooks) => {
|
||||
<field name="display_name" required="1"/>
|
||||
</form>`,
|
||||
});
|
||||
assert.verifySteps(["get_views", "read"]);
|
||||
|
||||
await editInput(target, "[name='display_name'] input", "yop");
|
||||
await click(target, ".o_attach_document");
|
||||
@@ -81,6 +84,61 @@ QUnit.module("Widgets", (hooks) => {
|
||||
{},
|
||||
{ skipVisibilityCheck: true }
|
||||
);
|
||||
assert.verifySteps(["write", "post", "my_action"]);
|
||||
assert.verifySteps(["write", "read", "post", "my_action", "read"]);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"attach document widget calls action with attachment ids on a new record",
|
||||
async function (assert) {
|
||||
serviceRegistry.add("http", {
|
||||
start: () => ({
|
||||
post: (route, params) => {
|
||||
assert.step("post");
|
||||
assert.strictEqual(route, "/web/binary/upload_attachment");
|
||||
assert.strictEqual(params.model, "partner");
|
||||
assert.strictEqual(params.id, 2);
|
||||
return '[{ "id": 5 }, { "id": 2 }]';
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
mockRPC(route, args) {
|
||||
assert.step(args.method);
|
||||
if (args.method === "my_action") {
|
||||
assert.deepEqual(args.model, "partner");
|
||||
assert.deepEqual(args.args, [2]);
|
||||
assert.deepEqual(args.kwargs.attachment_ids, [5, 2]);
|
||||
return true;
|
||||
}
|
||||
if (args.method === "create") {
|
||||
assert.deepEqual(args.args[0], { display_name: "yop" });
|
||||
}
|
||||
if (args.method === "read") {
|
||||
assert.deepEqual(args.args[0], [2]);
|
||||
}
|
||||
},
|
||||
arch: `
|
||||
<form>
|
||||
<widget name="attach_document" action="my_action" string="Attach document"/>
|
||||
<field name="display_name" required="1"/>
|
||||
</form>`,
|
||||
});
|
||||
assert.verifySteps(["get_views", "onchange"]);
|
||||
|
||||
await editInput(target, "[name='display_name'] input", "yop");
|
||||
await click(target, ".o_attach_document");
|
||||
await triggerEvent(
|
||||
target,
|
||||
".o_file_input input",
|
||||
"change",
|
||||
{},
|
||||
{ skipVisibilityCheck: true }
|
||||
);
|
||||
assert.verifySteps(["create", "read", "post", "my_action", "read"]);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user