From d6d468e5f15e0cc6bb27c3af8414afd9f65d0b5e Mon Sep 17 00:00:00 2001 From: "Maximilien (malb)" Date: Fri, 28 Jul 2023 15:23:43 +0200 Subject: [PATCH] [IMP] hr_expense: readability expense receipts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The goal of this PR is to improve the readability of expense receipts on hr_expense and hr_expense_sheet. This PR do the following: - Add the expense name next to the filename - Vertically center the receipt on both model (was previously done in hr_expense but not for the sheet) - Make sure the title doesn't get hidden by the image (was previously done in hr_expense but not for the sheet) Also, to achieve the first point we had to modify the attachment so that we can retrieve easily the information of which line the attachment is attached. closes odoo/odoo#130181 Task: 3443067 Signed-off-by: William André (wan) --- .../static/src/components/attachment_view.js | 13 +++++++++++++ addons/hr_expense/static/src/scss/hr_expense.scss | 5 ++++- addons/hr_expense/views/hr_expense_views.xml | 2 +- addons/mail/models/ir_attachment.py | 1 + .../mail/static/src/core/common/attachment_model.js | 1 + .../static/src/core/common/attachment_service.js | 1 + .../mail/static/src/core/common/attachment_view.js | 4 ++++ .../mail/static/src/core/common/attachment_view.xml | 2 +- 8 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 addons/hr_expense/static/src/components/attachment_view.js diff --git a/addons/hr_expense/static/src/components/attachment_view.js b/addons/hr_expense/static/src/components/attachment_view.js new file mode 100644 index 00000000000..cac1c86d888 --- /dev/null +++ b/addons/hr_expense/static/src/components/attachment_view.js @@ -0,0 +1,13 @@ +/** @odoo-module **/ + +import { patch } from "@web/core/utils/patch"; +import { AttachmentView } from "@mail/core/common/attachment_view"; + +patch(AttachmentView.prototype, { + get displayName() { + if (this.state.thread.model === 'hr.expense.sheet') { + return (this.state.thread.mainAttachment.res_name || this.state.thread.name) + ' - ' + this.state.thread.mainAttachment.filename; + } + return super.displayName; + } +}); diff --git a/addons/hr_expense/static/src/scss/hr_expense.scss b/addons/hr_expense/static/src/scss/hr_expense.scss index 22d7011d3ea..c308e997f37 100644 --- a/addons/hr_expense/static/src/scss/hr_expense.scss +++ b/addons/hr_expense/static/src/scss/hr_expense.scss @@ -23,8 +23,11 @@ display: flex; justify-content: center; z-index: -1; -} + img { + max-height: 100%; + } +} .o_dropzone { width: 100%; height: 100%; diff --git a/addons/hr_expense/views/hr_expense_views.xml b/addons/hr_expense/views/hr_expense_views.xml index 1d49978fbe2..f1a7deb474d 100644 --- a/addons/hr_expense/views/hr_expense_views.xml +++ b/addons/hr_expense/views/hr_expense_views.xml @@ -849,7 +849,7 @@ -
+
diff --git a/addons/mail/models/ir_attachment.py b/addons/mail/models/ir_attachment.py index 2624eb8b942..b735a96a0a7 100644 --- a/addons/mail/models/ir_attachment.py +++ b/addons/mail/models/ir_attachment.py @@ -81,6 +81,7 @@ class IrAttachment(models.Model): 'filename': attachment.name, 'name': attachment.name, "size": attachment.file_size, + 'res_name': attachment.res_name, 'mimetype': 'application/octet-stream' if safari and attachment.mimetype and 'video' in attachment.mimetype else attachment.mimetype, 'originThread': [('insert', { 'id': attachment.res_id, diff --git a/addons/mail/static/src/core/common/attachment_model.js b/addons/mail/static/src/core/common/attachment_model.js index d169cfe94a2..bf35db8d174 100644 --- a/addons/mail/static/src/core/common/attachment_model.js +++ b/addons/mail/static/src/core/common/attachment_model.js @@ -40,6 +40,7 @@ export class Attachment extends Record { mimetype; name; originThreadLocalId; + res_name; type; /** @type {string} */ tmpUrl; diff --git a/addons/mail/static/src/core/common/attachment_service.js b/addons/mail/static/src/core/common/attachment_service.js index 534f87cc7b0..edf4238867f 100644 --- a/addons/mail/static/src/core/common/attachment_service.js +++ b/addons/mail/static/src/core/common/attachment_service.js @@ -34,6 +34,7 @@ export class AttachmentService { "accessToken", "tmpUrl", "message", + "res_name", ]); if (!("extension" in data) && data["name"]) { attachment.extension = attachment.name.split(".").pop(); diff --git a/addons/mail/static/src/core/common/attachment_view.js b/addons/mail/static/src/core/common/attachment_view.js index cc933ba62dc..7be07e8b630 100644 --- a/addons/mail/static/src/core/common/attachment_view.js +++ b/addons/mail/static/src/core/common/attachment_view.js @@ -59,4 +59,8 @@ export class AttachmentView extends Component { model: props.threadModel, }); } + + get displayName() { + return this.state.thread.mainAttachment.filename; + } } diff --git a/addons/mail/static/src/core/common/attachment_view.xml b/addons/mail/static/src/core/common/attachment_view.xml index 1effb496c77..293bad23a10 100644 --- a/addons/mail/static/src/core/common/attachment_view.xml +++ b/addons/mail/static/src/core/common/attachment_view.xml @@ -4,7 +4,7 @@
-

+