style(finkok): isort y black

parent 2f1d5c96
# -*- coding: utf-8 -*-
import logging
from requests import Request, Session
from suds.client import (
BuildError,
Client,
......@@ -11,17 +12,16 @@ from suds.client import (
TypeNotFound,
WebFault,
)
import requests
from requests import Request, Session
import xmltodict
from openerp import api, fields, models
from openerp.exceptions import Warning as UserError
from openerp.tools.translate import _
from ..lib.pac_answer import PacCancelAnswer
from ..models import exceptions as pac_exceptions
from ..lib import finkok_envelopes
from ..lib.pac_answer import PacCancelAnswer, PacConsultAnswer
from ..models import exceptions as pac_exceptions
_logger = logging.getLogger(__name__)
......@@ -32,21 +32,18 @@ _logger = logging.getLogger(__name__)
# described in its manual
_cancel_errors = {
"300": "Usuario y contraseña inválidos",
"203": "No corresponde el RFC del Emisor y de quien solicita "
"la cancelación",
"203": "No corresponde el RFC del Emisor y de quien solicita la cancelación",
"205": "UUID No existe",
"704": "Error con la contraseña de la llave Privada",
"708": "No se pudo conectar al SAT",
"'711": "Error con el certificado al cancelar",
"712": "El número de noCertificado es diferente al del número de"
"certificado del atributo certificado",
"certificado del atributo certificado",
}
TIMEOUT = 60
_ACTIONS = {"timbrar": "",
"cancelar": "",
"consultar": "\"get_sat_status\""
}
_ACTIONS = {"timbrar": "", "cancelar": "", "consultar": '"get_sat_status"'}
class ParamsPac(models.Model):
_inherit = "params.pac"
......@@ -97,13 +94,10 @@ class ParamsPac(models.Model):
return factura_mx_type__fc
def create_header(self, method):
return {"SOAPAction": "%s" % (_ACTIONS[method]),
# "Accept-Encoding": "gzip,deflate",
"Content-Type": "text/xml; charset=utf-8"
# "Connection": "Keep-Alive"
# "charset": "utf-8"
}
return {
"SOAPAction": "%s" % (_ACTIONS[method]),
"Content-Type": "text/xml; charset=utf-8"
}
def sign_cfdi_finkok(self, fdata):
"""Function uses to sign CFDIs in Finkok webservices
......@@ -144,7 +138,7 @@ class ParamsPac(models.Model):
code_error = incidencia.CodigoError
if code_error in pac_exceptions.validation_error_list:
raise pac_exceptions.ValidationError(
code=code_error, message=menssage_error,
code=code_error, message=menssage_error
)
else:
raise Exception(" ".join([code_error, menssage_error]))
......@@ -187,7 +181,7 @@ class ParamsPac(models.Model):
cfdis_list = server.factory.create("UUIDS")
cfdis_list.uuids.string = cfdis
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
......@@ -209,14 +203,14 @@ class ParamsPac(models.Model):
cancel_answer = PacCancelAnswer(
folio.UUID, folio.EstatusUUID, folio.EstatusCancelacion
)
if cancel_answer.estatus not in ["200", "201", "202","no_cancelable"]:
if cancel_answer.estatus not in ["200", "201", "202", "no_cancelable"]:
raise pac_exceptions.CancelError(
cancel_answer.estatus, _cancel_errors.get(cancel_answer.estatus, ""),
cancel_answer.estatus, _cancel_errors.get(cancel_answer.estatus, "")
)
return cancel_answer
def consult_cfdi_finkok_2(self, uuid):
cfdi = self.env['ir.attachment.facturae.mx'].search([["uuid", "=", uuid]])
cfdi = self.env["ir.attachment.facturae.mx"].search([["uuid", "=", uuid]])
username = self.user.encode("utf-8")
password = self.password.encode("utf-8")
emisor = cfdi.rfc_emisor.encode("utf-8")
......@@ -224,12 +218,15 @@ class ParamsPac(models.Model):
# uuid = cfdi.uuid.encode("utf-8")
total = cfdi.total
client = Client(self.url_webservice_cancel, cache=None)
res = client.service.get_sat_status(username,password,emisor, receptor, uuid, total)
_logger.info(res)
res = client.service.get_sat_status(
username, password, emisor, receptor, uuid, total
)
_logger.info(res)
folio = res.sat
try:
estatus_cancelacion = folio["EstatusCancelacion"]
except Exception as e:
_logger.info(e)
estatus_cancelacion = ""
estado_cfdi = folio["Estado"]
consult_answer = PacConsultAnswer(uuid, estado_cfdi, estatus_cancelacion)
......@@ -241,7 +238,7 @@ class ParamsPac(models.Model):
:param uuid: UUID of CFDI to consult
"""
method = "consultar"
cfdi = self.env['ir.attachment.facturae.mx'].search([["uuid", "=", uuid]])
cfdi = self.env["ir.attachment.facturae.mx"].search([["uuid", "=", uuid]])
url1 = "http://demo-facturacion.finkok.com/servicios/soap/cancel"
try:
data = finkok_envelopes._SOAPENV_CONSULTAR % (
......@@ -253,15 +250,15 @@ class ParamsPac(models.Model):
cfdi.total,
)
except Exception as e:
e.message="Error al crear ENVELOPE"
e.message = "Error al crear ENVELOPE"
_logger.info(e)
raise e
else:
data = data.encode("utf-8")
_logger.debug(data)
headers =self.create_header(method)
headers = self.create_header(method)
s = Session()
#req = Request("POST", self.url_webservice_cancel, data=data, headers=headers)
# req = Request("POST", self.url_webservice_cancel, data=data, headers=headers)
req = Request("POST", url1, data=data, headers=headers)
prepped = s.prepare_request(req)
try:
......@@ -275,10 +272,15 @@ class ParamsPac(models.Model):
raise e
# Procesar los resultados obtenidos del PAC
try:
resultado = res["soapenv:Envelope"]["soapenv:Body"]["ns2:consultarCfdiResponse"][
"ns2:consultarCfdiResponse"] # noqa
resultado = res["soapenv:Envelope"]["soapenv:Body"][
"ns2:consultarCfdiResponse"
][
"ns2:consultarCfdiResponse"
] # noqa
except KeyError as e:
resultado = res["soapenv:Envelope"]["soapenv:Body"]["ns2:consultarCfdiResponse"][
resultado = res["soapenv:Envelope"]["soapenv:Body"][
"ns2:consultarCfdiResponse"
][
"ns2:consultarCfdiResponse"
] # noqa
_logger.debug(e)
......@@ -289,9 +291,9 @@ class ParamsPac(models.Model):
res = resultado["ns2:responseGenericoQr"]["ns2:servicio"]
res = res.popitem(True)
res = res[1]
res = xmltodict.parse(res.encode("utf-8"))
res = xmltodict.parse(res.encode("utf-8"))
resultado = res["s:Envelope"]["s:Body"]["ConsultaResponse"]["ConsultaResult"]
estatus_cancelacion = resultado["a:EstatusCancelacion"]
estado_cfdi = resultado["a:Estado"]
consult_answer = PacConsultAnswer(uuid, estado_cfdi, estatus_cancelacion)
return consult_answer
\ No newline at end of file
return consult_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