[FIX] web: Allow user to download binary file in always edit mode

Steps:
- Open studio in any form view
- Add Binary Field
- Close Studio
- Upload a file in the previously added binary field
- We can't download it because of always edit

This commit adds a new download button near edit and clear button

opw-3028094

closes odoo/odoo#104961

X-original-commit: 73a2329b8bf4e887890cae7669bc568ae0be7147
Signed-off-by: Luca Vitali <luvi@odoo.com>
This commit is contained in:
Achraf
2022-11-04 08:58:44 +01:00
parent 623ecff069
commit a167b3e7b5
2 changed files with 25 additions and 1 deletions
@@ -9,6 +9,14 @@
acceptedFileExtensions="props.acceptedFileExtensions"
onUploaded.bind="update"
>
<t if="props.record.resId">
<button
class="btn btn-secondary fa fa-download"
data-tooltip="Download"
aria-label="Download"
t-on-click="onFileDownload"
/>
</t>
<t t-set-slot="toggler">
<input type="text" class="o_input" t-att-value="fileName" readonly="readonly" />
<button
@@ -144,7 +144,7 @@ QUnit.module("Fields", (hooks) => {
});
QUnit.test("BinaryField is correctly rendered", async function (assert) {
assert.expect(9);
assert.expect(12);
async function send(data) {
assert.ok(data instanceof FormData);
@@ -205,6 +205,22 @@ QUnit.module("Fields", (hooks) => {
"the filename field should have the file name as value"
);
// Testing the download button in the field
// We must avoid the browser to download the file effectively
const prom = makeDeferred();
const downloadOnClick = (ev) => {
const target = ev.target;
if (target.tagName === "A" && "download" in target.attributes) {
ev.preventDefault();
document.removeEventListener("click", downloadOnClick);
prom.resolve();
}
};
document.addEventListener("click", downloadOnClick);
registerCleanup(() => document.removeEventListener("click", downloadOnClick));
await click(target.querySelector(".fa-download"));
await prom;
await click(target.querySelector(".o_field_binary .o_clear_file_button"));
assert.isNotVisible(