From 63e58efaa629084ce013a5b153575cf1fa510308 Mon Sep 17 00:00:00 2001 From: "John Laterre (jol)" Date: Thu, 16 Jun 2022 14:01:39 +0000 Subject: [PATCH] [FIX] account: restore add_banner() method Since this commit : 7d69a28f0710ffc27979f6e977997f972bc129bb, the add_banner() method is no longer executed, which disables a recently added feature (see here : https://github.com/odoo/odoo/pull/84542). The goal here is simply to restore it. closes odoo/odoo#93860 X-original-commit: 29d3d5a3b5286fa6db625b3910ad325ed84472d8 Signed-off-by: Laurent Smet --- addons/account/models/ir_actions_report.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py index fa61961eed4..d940aec6e1c 100644 --- a/addons/account/models/ir_actions_report.py +++ b/addons/account/models/ir_actions_report.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import io - from collections import OrderedDict from odoo import models, _ from odoo.exceptions import UserError +from odoo.tools import pdf class IrActionsReport(models.Model): @@ -25,10 +25,15 @@ class IrActionsReport(models.Model): collected_streams = OrderedDict() for invoice in invoices: - if invoice.message_main_attachment_id: + attachment = invoice.message_main_attachment_id + if attachment: + stream = io.BytesIO(attachment.raw) + if attachment.mimetype == 'application/pdf': + record = self.env[attachment.res_model].browse(attachment.res_id) + stream = pdf.add_banner(stream, record.name, logo=True) collected_streams[invoice.id] = { - 'stream': io.BytesIO(invoice.message_main_attachment_id.raw), - 'attachment': invoice.message_main_attachment_id, + 'stream': stream, + 'attachment': attachment, } return collected_streams