summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/account_edi/models/account_edi_format.py23
-rw-r--r--addons/account_edi_facturx/models/account_edi_format.py6
-rw-r--r--addons/account_edi_facturx/tests/test_facturx.py5
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
####################################################