[FIX] l10n_it_edi: several fixes and improvements

- l10n_it_edi: EDI receiving cron error handling fix
If we cannot receive invoices or bills from the IAP proxy we also can't
iterate over them

- l10n_it_edi: Check edi_format before trying to remove signature
The edi_format must be checked before trying to remove the eventual
PKCS#7 signature from the file, otherwise we're uselessly going to try
and remove the signature for every edi_format check (facturX etc.)

- l10n_it_edi: .p7m files can wrongly be missing the signature
In the case that the .p7m extension is put by mistake, try to use the
content of the file as it is before discarding it.

Task link: https://www.odoo.com/web#id=3189457&model=project.task
Task-3189457

closes odoo/odoo#113451

X-original-commit: 942e3c7f2b549fed86f9eb76f98f30b7e5db1ae9
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Paolo Gatti (pgi) <pgi@odoo.com>
This commit is contained in:
Paolo Gatti (pgi)
2023-02-23 10:31:01 +01:00
parent 5ff5bb686c
commit 3cdb215684
2 changed files with 11 additions and 6 deletions
@@ -303,6 +303,7 @@ class AccountEdiFormat(models.Model):
res = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/in/RicezioneInvoice',
params={'recipient_codice_fiscale': company.l10n_it_codice_fiscale})
except AccountEdiProxyError as e:
res = {}
_logger.error('Error while receiving file from SdiCoop: %s', e)
proxy_acks = []
@@ -353,7 +354,7 @@ class AccountEdiFormat(models.Model):
def _check_filename_is_fattura_pa(self, filename):
return re.search("[A-Z]{2}[A-Za-z0-9]{2,28}_[A-Za-z0-9]{0,5}.((?i:xml.p7m|xml))", filename)
def _is_fattura_pa(self, filename, tree):
def _is_fattura_pa(self, filename, tree=None):
return self.code == 'fattura_pa' and self._check_filename_is_fattura_pa(filename)
def _create_invoice_from_xml_tree(self, filename, tree, journal=None):
@@ -393,17 +394,17 @@ class AccountEdiFormat(models.Model):
def _create_invoice_from_binary(self, filename, content, extension):
self.ensure_one()
if extension.lower() == '.xml.p7m':
if extension.lower() == '.xml.p7m' and self._is_fattura_pa(filename):
decoded_content = self._decode_p7m_to_xml(filename, content)
if decoded_content is not None and self._is_fattura_pa(filename, decoded_content):
if decoded_content is not None:
return self._import_fattura_pa(decoded_content, self.env['account.move'])
return super()._create_invoice_from_binary(filename, content, extension)
def _update_invoice_from_binary(self, filename, content, extension, invoice):
self.ensure_one()
if extension.lower() == '.xml.p7m':
if extension.lower() == '.xml.p7m' and self._is_fattura_pa(filename):
decoded_content = self._decode_p7m_to_xml(filename, content)
if decoded_content is not None and self._is_fattura_pa(filename, decoded_content):
if decoded_content is not None:
return self._import_fattura_pa(decoded_content, invoice)
return super()._update_invoice_from_binary(filename, content, extension, invoice)
+5 -1
View File
@@ -36,7 +36,11 @@ def remove_signature(content):
# This method is deprecated, but there are actually no alternatives
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
loaded_data = ssl_crypto.load_pkcs7_data(ssl_crypto.FILETYPE_ASN1, content)
try:
loaded_data = ssl_crypto.load_pkcs7_data(ssl_crypto.FILETYPE_ASN1, content)
except ssl_crypto.Error:
_logger.warning("Error reading the content, PKCS#7 signature missing or invalid. Content will be tentatively used as it is.")
return content
# Verify the signature
if verify(loaded_data._pkcs7, null, null, null, out_buffer, flags) != 1: