diff --git a/addons/account_edi/models/account_edi_format.py b/addons/account_edi/models/account_edi_format.py index dced5f43abc..e1c5753a541 100644 --- a/addons/account_edi/models/account_edi_format.py +++ b/addons/account_edi/models/account_edi_format.py @@ -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 diff --git a/addons/account_edi_facturx/models/account_edi_format.py b/addons/account_edi_facturx/models/account_edi_format.py index 3a487e0e691..8432c506af0 100644 --- a/addons/account_edi_facturx/models/account_edi_format.py +++ b/addons/account_edi_facturx/models/account_edi_format.py @@ -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): diff --git a/addons/account_edi_facturx/tests/test_facturx.py b/addons/account_edi_facturx/tests/test_facturx.py index 881d8fbd8b4..f089a602eb4 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 ####################################################