diff options
| author | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2021-05-04 07:38:39 +0000 |
|---|---|---|
| committer | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2021-05-04 07:50:06 +0000 |
| commit | 721a88ea3386dc25669c78fb39f2247557780d6f (patch) | |
| tree | cf0429a13d96deac91f0893680244723018737f8 | |
| parent | b5800c9d2088df2bb9c4fbe0fed91c7ef24299c5 (diff) | |
[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#70293
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
| -rw-r--r-- | addons/account_edi/models/account_edi_format.py | 23 | ||||
| -rw-r--r-- | addons/account_edi_facturx/models/account_edi_format.py | 6 | ||||
| -rw-r--r-- | addons/account_edi_facturx/tests/test_facturx.py | 5 |
3 files changed, 29 insertions, 5 deletions
diff --git a/addons/account_edi/models/account_edi_format.py b/addons/account_edi/models/account_edi_format.py index 36c36941625..0eb87fa9e95 100644 --- a/addons/account_edi/models/account_edi_format.py +++ b/addons/account_edi/models/account_edi_format.py @@ -98,6 +98,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=None, state=None, company=None): """ 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. @@ -247,11 +261,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 diff --git a/addons/account_edi_facturx/models/account_edi_format.py b/addons/account_edi_facturx/models/account_edi_format.py index 587604c868b..21480f5a1a2 100644 --- a/addons/account_edi_facturx/models/account_edi_format.py +++ b/addons/account_edi_facturx/models/account_edi_format.py @@ -45,6 +45,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): diff --git a/addons/account_edi_facturx/tests/test_facturx.py b/addons/account_edi_facturx/tests/test_facturx.py index 92eb22655d0..46729101fbe 100644 --- a/addons/account_edi_facturx/tests/test_facturx.py +++ b/addons/account_edi_facturx/tests/test_facturx.py @@ -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 #################################################### |
