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 @@
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
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