From 2b6b63765fb9b245ceeba93cbcb547e559bc178c Mon Sep 17 00:00:00 2001 From: Cuauhtemoc Diaz Minor <cuauhtemoc.diaz@openpyme.mx> Date: Thu, 18 Oct 2018 16:56:46 -0500 Subject: [PATCH] feat(finkok): soporte para cancelacion CFDI 3.3 En la cancelacion de CFDIs se regresa la respuesta del PAC usando el objeto `PacCancelAnswer` con el estatus de cancelacion del CFDI y se agrega el error de cancelacion `no_cancelable` --- l10n_mx_params_pac/pacs/finfok.py | 43 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/l10n_mx_params_pac/pacs/finfok.py b/l10n_mx_params_pac/pacs/finfok.py index 7812281e..3b4555ff 100644 --- a/l10n_mx_params_pac/pacs/finfok.py +++ b/l10n_mx_params_pac/pacs/finfok.py @@ -2,12 +2,14 @@ import logging from suds.client import Client +from suds.client import WebFault, MethodNotFound, PortNotFound, ServiceNotFound, TypeNotFound, BuildError,SoapHeadersNotPermitted #noqa from openerp import api, fields, models from openerp.exceptions import Warning as UserError from openerp.tools.translate import _ from ..models import exceptions as pac_exceptions +from ..lib.pac_answer import PacCancelAnswer logger = logging.getLogger(__name__) @@ -27,6 +29,7 @@ _cancel_errors = { '711': 'Error con el certificado al cancelar', '712': 'El número de noCertificado es diferente al del número de' 'certificado del atributo certificado', + 'no_cancelable': 'El UUID contiene CFDI relacionados', } @@ -84,13 +87,12 @@ class ParamsPac(models.Model): # I thought it was necessary to create at first # a Soap request but only passing XML in base64 it works contenido = server.service.stamp(fdata, user, password) - # I do not know what are the error generated for Finkok - # that's why I catch all, in the other hand I do not expect - # to be here never - except: # noqa - # Send only a raise - # in order to allow higher levels catch errors - raise + # Exceptions could be MethodNotFound, PortNotFound + # ServiceNotFound, TypeNotFound, BuildError, SoapHeadersNotPermitted + # and WebFault, we only catch the generic one. + except (MethodNotFound, PortNotFound, ServiceNotFound, + TypeNotFound, BuildError, SoapHeadersNotPermitted, WebFault) as e: + raise UserError(e) # If there is Incidencias attribute it is because # process failed if contenido.Incidencias: @@ -143,19 +145,20 @@ class ParamsPac(models.Model): result = server.service.cancel( cfdis_list, user, password, company_rfc, cer_file, key_file, ) + # Exceptions could be MethodNotFound, PortNotFound + # ServiceNotFound, TypeNotFound, BuildError, SoapHeadersNotPermitted + # and WebFault, we only catch the generic one. + except (MethodNotFound, PortNotFound, ServiceNotFound, + TypeNotFound, BuildError, SoapHeadersNotPermitted, WebFault) as e: + logger.info(e.document) + raise UserError(e) # Get results, result is always in a list # but this list has only one value since we only send one # folio fiscal - folio = result.Folios.Folio[0] - result_status = str(folio.EstatusUUID) - if result_status not in ['200', '201', '202']: - raise pac_exceptions.CancelError( - result_status, _cancel_errors.get(result_status, ''), - ) - # I do not know what are the error generated for Finkok - # that's why I catch all, in the other hand I do not expect - # to be here never - except: # noqa - # Send only a raise - # in order to allow higher levels catch errors - raise + folio = result.Folios.Folio[0] + cancel_answer = PacCancelAnswer(folio.UUID, folio.EstatusUUID,folio.EstatusCancelacion) + if cancel_answer.estatus not in ['200', '201', '202']: + raise pac_exceptions.CancelError( + cancel_answer.estatus, _cancel_errors.get(cancel_answer.estatus, ''), + ) + return cancel_answer -- GitLab