[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) <flg@odoo.com>
Signed-off-by: Mohamed Megahed Abbas Megahed SALLAM (mome) <mome@odoo.com>
This commit is contained in:
momegahed
2023-04-03 20:48:02 +02:00
parent 49b7acf53c
commit 915dcda565
@@ -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
####################################################