summaryrefslogtreecommitdiff
path: root/addons/l10n_it_edi/tests
diff options
context:
space:
mode:
authorPaolo (pgi) <pgi@odoo.com>2021-05-21 11:00:53 +0000
committerPaolo (pgi) <pgi@odoo.com>2021-05-21 11:19:18 +0000
commited723be917637320fc4d2787bdf505e4a7a8216d (patch)
tree2b6e4dfccd323c3623898800de69cb3d977a2fb5 /addons/l10n_it_edi/tests
parent0c4111850ac2bf54c71e9da04fac5b0c651021cd (diff)
[FIX] l10n_it_edi: Vendor bill is not being created from PEC
When one or more vendor bills in Italian e-invoice format were sent to the registered PEC mailbox, if they are in the PKCS#7 format ('.xml.p7m'), nothing happened. The e-invoice content should be automatically decoded and the invoice should be created as soon as the xml file is fetched from the PEC mailbox. A new remove_signature function has been added in a tools/remove_signature.py file to handle this case. The OpenSSL and pyOpenSSL libraries must be installed. They are not in requirements.txt but they're probably available. New tests has been provided for the signed email reading method. opw-2460485 closes odoo/odoo#71138 Signed-off-by: Josse Colpaert <jco@openerp.com>
Diffstat (limited to 'addons/l10n_it_edi/tests')
-rw-r--r--addons/l10n_it_edi/tests/expected_xmls/IT01234567890_FPR01.xml.p7mbin0 -> 7083 bytes
-rw-r--r--addons/l10n_it_edi/tests/test_ir_mail_server.py15
2 files changed, 15 insertions, 0 deletions
diff --git a/addons/l10n_it_edi/tests/expected_xmls/IT01234567890_FPR01.xml.p7m b/addons/l10n_it_edi/tests/expected_xmls/IT01234567890_FPR01.xml.p7m
new file mode 100644
index 00000000000..ecb48417c5a
--- /dev/null
+++ b/addons/l10n_it_edi/tests/expected_xmls/IT01234567890_FPR01.xml.p7m
Binary files differ
diff --git a/addons/l10n_it_edi/tests/test_ir_mail_server.py b/addons/l10n_it_edi/tests/test_ir_mail_server.py
index c6dd9efe989..8e803d9ad56 100644
--- a/addons/l10n_it_edi/tests/test_ir_mail_server.py
+++ b/addons/l10n_it_edi/tests/test_ir_mail_server.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import datetime
import logging
from collections import namedtuple
from unittest.mock import patch
from odoo import tools
from odoo.addons.account_edi.tests.common import AccountEdiTestCommon
+from odoo.addons.l10n_it_edi.tools.remove_signature import remove_signature
_logger = logging.getLogger(__name__)
@@ -51,7 +53,9 @@ class PecMailServerTests(AccountEdiTestCommon):
# invoice_filename2 is used for vendor bill tests
cls.invoice_filename1 = 'IT01234567890_FPR01.xml'
cls.invoice_filename2 = 'IT01234567890_FPR02.xml'
+ cls.signed_invoice_filename = 'IT01234567890_FPR01.xml.p7m'
cls.invoice_content = cls._get_test_file_content(cls.invoice_filename1)
+ cls.signed_invoice_content = cls._get_test_file_content(cls.signed_invoice_filename)
cls.invoice = cls.env['account.move'].create({
'move_type': 'in_invoice',
'ref': '01234567890'
@@ -85,6 +89,8 @@ class PecMailServerTests(AccountEdiTestCommon):
def _create_invoice(self, content, filename):
""" Create an invoice from given attachment content """
with patch.object(self.server._cr, 'commit', return_value=None):
+ if filename.endswith(".p7m"):
+ content = remove_signature(content)
return self.server._create_invoice_from_mail(content, filename, 'fake@address.be')
# -----------------------------
@@ -98,6 +104,15 @@ class PecMailServerTests(AccountEdiTestCommon):
invoices = self._create_invoice(self.invoice_content, self.invoice_filename2)
self.assertTrue(bool(invoices))
+ def test_receive_signed_vendor_bill(self):
+ """ Test a signed (P7M) sample e-invoice file from https://www.fatturapa.gov.it/export/documenti/fatturapa/v1.2/IT01234567890_FPR01.xml """
+ invoices = self._create_invoice(self.signed_invoice_content, self.signed_invoice_filename)
+ self.assertRecordValues(invoices, [{
+ 'name': 'BILL/2014/12/0001',
+ 'date': datetime.date(2014, 12, 18),
+ 'ref': '01234567890',
+ }])
+
def test_receive_same_vendor_bill_twice(self):
""" Test that the second time we are receiving a PEC mail with the same attachment, the second is discarded """
content = self.fake_test_content.encode()