From 915dcda565992221b5bb91067d08372ca7896048 Mon Sep 17 00:00:00 2001 From: momegahed Date: Mon, 20 Mar 2023 13:44:06 +0000 Subject: [PATCH] [FIX] account_edi: EDI PDF not rendering when having an EDI XML Steps to reproduce: - install any edi l10n - create an invoice with edi xml - try to print the invoice (this adds a pdf attachment) - the attachment viewer shows whichever attachment added first - it shows only the xml file name Bug: `_message_set_main_attachment_id` only works if there are no `message_main_attachment_id` set. Fix: Override `_message_set_main_attachment_id` in the `account.move` module to alter this behavior OPW-3147811 closes odoo/odoo#117510 X-original-commit: 383834b11bf6b7a80848e5d238b12fa237b9edf3 Signed-off-by: Florian Gilbert (flg) Signed-off-by: Mohamed Megahed Abbas Megahed SALLAM (mome) --- addons/account_edi/models/account_move.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/account_edi/models/account_move.py b/addons/account_edi/models/account_move.py index fc1bdf414db..69cafa7565e 100644 --- a/addons/account_edi/models/account_move.py +++ b/addons/account_edi/models/account_move.py @@ -402,6 +402,12 @@ class AccountMove(models.Model): def _get_edi_attachment(self, edi_format): return self._get_edi_document(edi_format).sudo().attachment_id + # this override is to make sure that the main attachment is not the edi xml otherwise the attachment viewer will not work correctly + def _message_set_main_attachment_id(self, attachment_ids): + if self.message_main_attachment_id and len(attachment_ids) > 1 and self.message_main_attachment_id in self.edi_document_ids.attachment_id: + self.message_main_attachment_id = self.env['ir.attachment'] + super()._message_set_main_attachment_id(attachment_ids) + #################################################### # Business operations ####################################################