diff --git a/addons/l10n_it_edi/models/account_edi_format.py b/addons/l10n_it_edi/models/account_edi_format.py index 0f76a8e0b7e..9157eaa692a 100644 --- a/addons/l10n_it_edi/models/account_edi_format.py +++ b/addons/l10n_it_edi/models/account_edi_format.py @@ -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) diff --git a/addons/l10n_it_edi/tools/remove_signature.py b/addons/l10n_it_edi/tools/remove_signature.py index 1816b7fd1a7..69ce31993a6 100644 --- a/addons/l10n_it_edi/tools/remove_signature.py +++ b/addons/l10n_it_edi/tools/remove_signature.py @@ -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: