Skip to content
Snippets Groups Projects
Commit 3557e66a authored by Thomas Lefebvre (thle)'s avatar Thomas Lefebvre (thle)
Browse files

[FIX] web: display download button if not dirty


Steps to reproduce:
-------------------
For example:
- add a work permit file to an employee (private information tab);
- try to download it before saving;

Issue:
------
The old file is downloaded or a traceback occurs
if there was no file before.

Cause:
------
When downloading, we use the `/web/content` endpoint.
We will try to read the record in the backend via `_record_to_stream`.
The record is not yet saved in database.

Solution:
---------
Disable download button if record is dirty.

opw-3458842

closes odoo/odoo#134521

Signed-off-by: default avatarMichaël Mattiello (mcm) <mcm@odoo.com>
parent 16912d7b
Branches
Tags
No related merge requests found
......@@ -10,7 +10,7 @@
file="{ data: props.value, name: fileName }"
onUploaded.bind="update"
>
<t t-if="props.record.resId">
<t t-if="props.record.resId and !props.record.isDirty">
<button
class="btn btn-secondary fa fa-download"
data-tooltip="Download"
......
......@@ -254,6 +254,36 @@ QUnit.module("Fields", (hooks) => {
);
});
QUnit.test("BinaryField is correctly rendered (isDirty)", async function (assert) {
assert.expect(2);
await makeView({
serverData,
type: "form",
resModel: "partner",
arch: `
<form>
<field name="document" filename="foo"/>
<field name="foo"/>
</form>`,
resId: 1,
});
// Simulate a file upload
const file = new File(["test"], "fake_file.txt", { type: "text/plain" });
await editInput(target, ".o_field_binary .o_input_file", file);
assert.containsNone(
target,
'.o_field_widget[name="document"] .fa-download',
"the binary field should not be rendered as a downloadable since the record is dirty"
);
await clickSave(target);
assert.containsOnce(
target,
'.o_field_widget[name="document"] .fa-download',
"the binary field should render as a downloadable link since the record is not dirty"
);
});
QUnit.test("file name field is not defined", async (assert) => {
await makeView({
serverData,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment