[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#135405 X-original-commit: 3557e66a410428b877213508104e9accbbfdaf20 Signed-off-by: Michaël Mattiello (mcm) <mcm@odoo.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
acceptedFileExtensions="props.acceptedFileExtensions"
|
||||
onUploaded.bind="update"
|
||||
>
|
||||
<t t-if="props.record.resId">
|
||||
<t t-if="props.record.resId and !props.record.dirty">
|
||||
<button
|
||||
class="btn btn-link btn-sm lh-1 fa fa-download o_download_file_button"
|
||||
data-tooltip="Download"
|
||||
|
||||
@@ -246,6 +246,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,
|
||||
|
||||
Reference in New Issue
Block a user