From 41d8bb8a287fcddc488a487850cf39b3ff8391f2 Mon Sep 17 00:00:00 2001 From: Yolann Sabaux Date: Thu, 20 Oct 2022 15:00:21 +0000 Subject: [PATCH] [FIX] l10n_es_edi_sii: handling error 1117 - NIF not registered Steps to reproduce: There is no possibility to reproduce it in test mode But the flow would be: - create a company with a NIF not registered - Set up the EDI invoice - Create an invoice Issue: When the NIF is not registered, is is possible to use it. It will only create an error `approbado con errores` which is apparently fine Solution: Whenever the server sent us an '1117' error code, we call again the post_invoice with a new context so we are able to send the request with the right information; that is, the correct ID Type whenever a NIF is not registered. Indeed, whenever the error code is related to the NIF, is is possible to send again a request without having the invoice defined as "duplicated". It will only go through the process "AceptadoConErrores". opw-2952108 closes odoo/odoo#104375 X-original-commit: 415d095cd418fd38d5749200724b6ce775ffa7f8 Signed-off-by: Josse Colpaert Signed-off-by: Yolann Sabaux (yosa) --- addons/l10n_es_edi_sii/models/account_edi_format.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/l10n_es_edi_sii/models/account_edi_format.py b/addons/l10n_es_edi_sii/models/account_edi_format.py index 552f63208f1..77d5ca9b9fe 100644 --- a/addons/l10n_es_edi_sii/models/account_edi_format.py +++ b/addons/l10n_es_edi_sii/models/account_edi_format.py @@ -228,6 +228,9 @@ class AccountEdiFormat(models.Model): if (not partner.country_id or partner.country_id.code == 'ES') and partner.vat: # ES partner with VAT. partner_info['NIF'] = partner.vat[2:] if partner.vat.startswith('ES') else partner.vat + if self.env.context.get('error_1117'): + partner_info['IDOtro'] = {'IDType': '07', 'ID': IDOtro_ID} + elif partner.country_id.code in eu_country_codes and partner.vat: # European partner. partner_info['IDOtro'] = {'IDType': '02', 'ID': IDOtro_ID} @@ -561,6 +564,11 @@ class AccountEdiFormat(models.Model): results[inv] = {'success': True} inv.message_post(body=_("We saw that this invoice was sent correctly before, but we did not treat " "the response. Make sure it is not because of a wrong configuration.")) + + elif respl.CodigoErrorRegistro == 1117 and not self.env.context.get('error_1117'): + return self.with_context(error_1117=True)._post_invoice_edi(invoices) + + else: results[inv] = { 'error': _("[%s] %s", respl.CodigoErrorRegistro, respl.DescripcionErrorRegistro),