[FIX] account_edi_facturx: fix filename in pdf embedding

When embedding to pdf, the name of the attached file should be 'factur-x.xml' (official specifications, section 6.2)

closes odoo/odoo#70442

X-original-commit: 04f4633d15f0a0824bd07f56a0f99491584f1a12
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: bfr-o <bfr-o@users.noreply.github.com>
This commit is contained in:
Benjamin Frantzen (bfr)
2021-05-06 07:03:48 +00:00
parent 03a11f5cf7
commit 5c3707832c
3 changed files with 29 additions and 5 deletions
@@ -104,6 +104,20 @@ class AccountEdiFormat(models.Model):
# TO OVERRIDE
return False
def _get_embedding_to_invoice_pdf_values(self, invoice):
""" Get the values to embed to pdf.
:returns: A dictionary {'name': name, 'datas': datas} or False if there are no values to embed.
* name: The name of the file.
* datas: The bytes ot the file.
"""
self.ensure_one()
attachment = invoice._get_edi_attachment(self)
if not attachment or not self._is_embedding_to_invoice_pdf_needed():
return False
datas = base64.b64decode(attachment.with_context(bin_size=False).datas)
return {'name': attachment.name, 'datas': datas}
def _support_batching(self, move, state, company):
""" Indicate if we can send multiple documents in the same time to the web services.
If True, the _post_%s_edi methods will get multiple documents in the same time.
@@ -259,11 +273,10 @@ class AccountEdiFormat(models.Model):
:returns: the same pdf_content with the EDI of the invoice embed in it.
"""
attachments = []
for edi_format in self:
attachment = invoice._get_edi_attachment(edi_format)
if attachment and edi_format._is_embedding_to_invoice_pdf_needed():
datas = base64.b64decode(attachment.with_context(bin_size=False).datas)
attachments.append({'name': attachment.name, 'datas': datas})
for edi_format in self.filtered(lambda edi_format: edi_format._is_embedding_to_invoice_pdf_needed()):
attach = edi_format._get_embedding_to_invoice_pdf_values(invoice)
if attach:
attachments.append(attach)
if attachments:
# Add the attachments to the pdf file
@@ -38,6 +38,12 @@ class AccountEdiFormat(models.Model):
self.ensure_one()
return True if self.code == 'facturx_1_0_05' else super()._is_embedding_to_invoice_pdf_needed()
def _get_embedding_to_invoice_pdf_values(self, invoice):
values = super()._get_embedding_to_invoice_pdf_values(invoice)
if self.code == 'facturx_1_0_05':
values['name'] = 'factur-x.xml'
return values
def _export_facturx(self, invoice):
def format_date(dt):
@@ -210,6 +210,11 @@ class TestAccountEdiFacturx(AccountEdiTestCommon):
self.assert_generated_file_equal(self.invoice, self.expected_invoice_facturx_values, applied_xpath)
def test_export_pdf(self):
self.invoice.action_post()
pdf_values = self.edi_format._get_embedding_to_invoice_pdf_values(self.invoice)
self.assertEqual(pdf_values['name'], 'factur-x.xml')
####################################################
# Test import
####################################################