[FIX] l10n_be_edi: error at PDF generation
An UBL invoice can contain several `AdditionalDocumentReference`, some
of them without `Attachment`. For example:
```
<cac:AdditionalDocumentReference>
<cbc:ID>UBL.BE</cbc:ID>
<cbc:DocumentDescription>BOB50 6.07.0</cbc:DocumentDescription>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>Facture N°19090118 - 30-09-2019.pdf</cbc:ID>
<cbc:DocumentDescription>CommercialInvoice</cbc:DocumentDescription>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject filename="Facture.pdf" mimeCode="application/pdf">JVBERi0xLjMK...
...
```
In this case, a crash occurs since:
```
element.xpath('cac:Attachment//cbc:EmbeddedDocumentBinaryObject', namespaces=namespaces)
```
is an empty list.
To avoid this, we loop on all elements and generate all PDFs.
opw-2128083
closes odoo/odoo#40721
X-original-commit: 2174e4066c5c8f87ed45aa564c184d1ce7063758
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
committed by
fw-bot
parent
26e32dac34
commit
c52f91a588
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user