Commit 2b6b6376 authored by Cuauhtémoc Díaz Minor's avatar Cuauhtémoc Díaz Minor

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`
parent c1728853
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import logging import logging
from suds.client import Client 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 import api, fields, models
from openerp.exceptions import Warning as UserError from openerp.exceptions import Warning as UserError
from openerp.tools.translate import _ from openerp.tools.translate import _
from ..models import exceptions as pac_exceptions from ..models import exceptions as pac_exceptions
from ..lib.pac_answer import PacCancelAnswer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -27,6 +29,7 @@ _cancel_errors = { ...@@ -27,6 +29,7 @@ _cancel_errors = {
'711': 'Error con el certificado al cancelar', '711': 'Error con el certificado al cancelar',
'712': 'El número de noCertificado es diferente al del número de' '712': 'El número de noCertificado es diferente al del número de'
'certificado del atributo certificado', 'certificado del atributo certificado',
'no_cancelable': 'El UUID contiene CFDI relacionados',
} }
...@@ -84,13 +87,12 @@ class ParamsPac(models.Model): ...@@ -84,13 +87,12 @@ class ParamsPac(models.Model):
# I thought it was necessary to create at first # I thought it was necessary to create at first
# a Soap request but only passing XML in base64 it works # a Soap request but only passing XML in base64 it works
contenido = server.service.stamp(fdata, user, password) contenido = server.service.stamp(fdata, user, password)
# I do not know what are the error generated for Finkok # Exceptions could be MethodNotFound, PortNotFound
# that's why I catch all, in the other hand I do not expect # ServiceNotFound, TypeNotFound, BuildError, SoapHeadersNotPermitted
# to be here never # and WebFault, we only catch the generic one.
except: # noqa except (MethodNotFound, PortNotFound, ServiceNotFound,
# Send only a raise TypeNotFound, BuildError, SoapHeadersNotPermitted, WebFault) as e:
# in order to allow higher levels catch errors raise UserError(e)
raise
# If there is Incidencias attribute it is because # If there is Incidencias attribute it is because
# process failed # process failed
if contenido.Incidencias: if contenido.Incidencias:
...@@ -143,19 +145,20 @@ class ParamsPac(models.Model): ...@@ -143,19 +145,20 @@ class ParamsPac(models.Model):
result = server.service.cancel( result = server.service.cancel(
cfdis_list, user, password, company_rfc, cer_file, key_file, 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 # Get results, result is always in a list
# but this list has only one value since we only send one # but this list has only one value since we only send one
# folio fiscal # folio fiscal
folio = result.Folios.Folio[0] folio = result.Folios.Folio[0]
result_status = str(folio.EstatusUUID) cancel_answer = PacCancelAnswer(folio.UUID, folio.EstatusUUID,folio.EstatusCancelacion)
if result_status not in ['200', '201', '202']: if cancel_answer.estatus not in ['200', '201', '202']:
raise pac_exceptions.CancelError( raise pac_exceptions.CancelError(
result_status, _cancel_errors.get(result_status, ''), cancel_answer.estatus, _cancel_errors.get(cancel_answer.estatus, ''),
) )
# I do not know what are the error generated for Finkok return cancel_answer
# 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment