From 821ee43327ab3dff5f8fca654089ea7c9528cd23 Mon Sep 17 00:00:00 2001 From: kcv-odoo Date: Mon, 1 Apr 2024 18:10:00 +0530 Subject: [PATCH] [FIX] web: fix binary field in settings form Steps: - Install sales app. - Go to settings of sales. - See header field there is no download button. Issue: - Binary field should have download button and user should be able to download file with out issue. Cause: - Since Settings is abstact model so it does not contains id field in it and download button visibility depends on id field. Fix: - Extend binary field for setting view to get proper file from related field where actual file is stored. task-3620555 closes odoo/odoo#160070 Signed-off-by: Jorge Pinna Puissant (jpp) --- .../src/views/fields/binary/binary_field.js | 26 ++-- .../src/views/fields/binary/binary_field.xml | 2 +- .../settings_binary_field.js | 26 ++++ .../settings_binary_field.xml | 10 ++ .../settings_form_view_tests.js | 129 +++++++++++++++++- 5 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 addons/web/static/src/webclient/settings_form_view/fields/settings_binary_field/settings_binary_field.js create mode 100644 addons/web/static/src/webclient/settings_form_view/fields/settings_binary_field/settings_binary_field.xml diff --git a/addons/web/static/src/views/fields/binary/binary_field.js b/addons/web/static/src/views/fields/binary/binary_field.js index 27b30b87af8..ad170b6d972 100644 --- a/addons/web/static/src/views/fields/binary/binary_field.js +++ b/addons/web/static/src/views/fields/binary/binary_field.js @@ -47,19 +47,23 @@ export class BinaryField extends Component { return this.props.record.update(changes); } + getDownloadData() { + return { + model: this.props.record.resModel, + id: this.props.record.resId, + field: this.props.name, + filename_field: this.fileName, + filename: this.fileName || "", + download: true, + data: isBinarySize(this.props.record.data[this.props.name]) + ? null + : this.props.record.data[this.props.name], + }; + } + async onFileDownload() { await download({ - data: { - model: this.props.record.resModel, - id: this.props.record.resId, - field: this.props.name, - filename_field: this.fileName, - filename: this.fileName || "", - download: true, - data: isBinarySize(this.props.record.data[this.props.name]) - ? null - : this.props.record.data[this.props.name], - }, + data: this.getDownloadData(), url: "/web/content", }); } diff --git a/addons/web/static/src/views/fields/binary/binary_field.xml b/addons/web/static/src/views/fields/binary/binary_field.xml index c2f6fdb34d2..ad202ef93c9 100644 --- a/addons/web/static/src/views/fields/binary/binary_field.xml +++ b/addons/web/static/src/views/fields/binary/binary_field.xml @@ -9,7 +9,7 @@ acceptedFileExtensions="props.acceptedFileExtensions" onUploaded.bind="update" > - +