summaryrefslogtreecommitdiff
path: root/addons/account_edi_ubl
diff options
context:
space:
mode:
authorBenjamin Frantzen (bfr) <bfr@odoo.com>2021-04-21 07:40:32 +0000
committerBenjamin Frantzen (bfr) <bfr@odoo.com>2021-04-21 07:40:32 +0000
commit0fd0fbc5c227f0a362e1efcda9eeaa5b663dc56a (patch)
treefe3c1ce55a8f8363652ae0012a424abddab2963a /addons/account_edi_ubl
parent683c3fd267162c93cb278fd903152ac387e6aba6 (diff)
[FIX] account_edi_ubl: extracting the pdf from the imported xml doesn't raise an exception any more when creating a new invoice
Before this commit, when an attachment was present in the xml (pdf) and the import was to create a new invoice, it crashed when trying to post the pdf on the not-yet existant invoice. This commit also fixes: - In the tests, `create_invoice_from_file` didn't handle the subfolder parameter correctly - `create_invoice_from_file` now returns the created invoice closes odoo/odoo#69582 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Diffstat (limited to 'addons/account_edi_ubl')
-rw-r--r--addons/account_edi_ubl/models/account_edi_format.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/addons/account_edi_ubl/models/account_edi_format.py b/addons/account_edi_ubl/models/account_edi_format.py
index d1f2cb17bf5..981568bf588 100644
--- a/addons/account_edi_ubl/models/account_edi_format.py
+++ b/addons/account_edi_ubl/models/account_edi_format.py
@@ -119,29 +119,6 @@ class AccountEdiFormat(models.Model):
else:
invoice_form.partner_id = self.env['res.partner']
- # Regenerate PDF
- attachments = self.env['ir.attachment']
- elements = tree.xpath('//cac:AdditionalDocumentReference', namespaces=namespaces)
- 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:
- text = attachment_data[0].text
- # Normalize the name of the file : some e-fff emitters put the full path of the file
- # (Windows or Linux style) and/or the name of the xml instead of the pdf.
- # Get only the filename with a pdf extension.
- name = PureWindowsPath(attachment_name[0].text).stem + '.pdf'
- attachments |= self.env['ir.attachment'].create({
- 'name': name,
- 'res_id': invoice.id,
- 'res_model': 'account.move',
- 'datas': text + '=' * (len(text) % 3), # Fix incorrect padding
- 'type': 'binary',
- 'mimetype': 'application/pdf',
- })
- if attachments:
- invoice.with_context(no_new_invoice=True).message_post(attachment_ids=attachments.ids)
-
# Lines
lines_elements = tree.xpath('//cac:InvoiceLine', namespaces=namespaces)
for eline in lines_elements:
@@ -196,4 +173,29 @@ class AccountEdiFormat(models.Model):
if tax:
invoice_line_form.tax_ids.add(tax)
- return invoice_form.save()
+ invoice = invoice_form.save()
+
+ # Regenerate PDF
+ attachments = self.env['ir.attachment']
+ elements = tree.xpath('//cac:AdditionalDocumentReference', namespaces=namespaces)
+ 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:
+ text = attachment_data[0].text
+ # Normalize the name of the file : some e-fff emitters put the full path of the file
+ # (Windows or Linux style) and/or the name of the xml instead of the pdf.
+ # Get only the filename with a pdf extension.
+ name = PureWindowsPath(attachment_name[0].text).stem + '.pdf'
+ attachments |= self.env['ir.attachment'].create({
+ 'name': name,
+ 'res_id': invoice.id,
+ 'res_model': 'account.move',
+ 'datas': text + '=' * (len(text) % 3), # Fix incorrect padding
+ 'type': 'binary',
+ 'mimetype': 'application/pdf',
+ })
+ if attachments:
+ invoice.with_context(no_new_invoice=True).message_post(attachment_ids=attachments.ids)
+
+ return invoice