diff --git a/addons/l10n_be_edi/models/account_invoice.py b/addons/l10n_be_edi/models/account_invoice.py index 66b82756ada..d6d755e71e1 100644 --- a/addons/l10n_be_edi/models/account_invoice.py +++ b/addons/l10n_be_edi/models/account_invoice.py @@ -108,18 +108,21 @@ class AccountMove(models.Model): invoice_form.partner_id = self.env['res.partner'] # Regenerate PDF + attachments = self.env['ir.attachment'] elements = tree.xpath('//cac:AdditionalDocumentReference', namespaces=namespaces) - if elements: - attachment_name = elements[0].xpath('cbc:ID', namespaces=namespaces)[0].text - attachment_data = elements[0].xpath('cac:Attachment//cbc:EmbeddedDocumentBinaryObject', namespaces=namespaces)[0].text - attachment_id = self.env['ir.attachment'].create({ - 'name': attachment_name, - 'res_id': self.id, - 'res_model': 'account.move', - 'datas': attachment_data, - 'type': 'binary', - }) - self.with_context(no_new_invoice=True).message_post(attachment_ids=[attachment_id.id]) + for element in elements: + attachment_name = element.xpath('cbc:ID', namespaces=namespaces) + attachment_data = element.xpath('cac:Attachment//cbc:EmbeddedDocumentBinaryObject', namespaces=namespaces) + if attachment_name and attachment_data: + attachments |= self.env['ir.attachment'].create({ + 'name': attachment_name[0].text, + 'res_id': self.id, + 'res_model': 'account.move', + 'datas': attachment_data[0].text, + 'type': 'binary', + }) + if attachments: + self.with_context(no_new_invoice=True).message_post(attachment_ids=attachments.ids) # Lines lines_elements = tree.xpath('//cac:InvoiceLine', namespaces=namespaces)