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

perf(params.pac): Cambios necesarios para la cancelación del CFDI

Para que `fire_connection` reconozca las excepciones de cancelacion que regresan los PACS se agrega
`exceptions.CancelError`
 Si no se puede cancelar por detalles de los WS de los PAC, se agrupan los
mensajes de error y se muestran
  Si no hay excepciones entonces `cancel_cfid` regresa si se
cancela o no el cfdi.
parent 2b6b6376
......@@ -99,6 +99,7 @@ class ParamsPac(models.Model):
# the priority selected by the user
# If all PACs would fail this variable will recollect
# all error in order to display them at the end
pacs_errors = []
message_error = ''
for param_pac in self:
# Get all possible drivers to perform action
......@@ -109,8 +110,10 @@ class ParamsPac(models.Model):
# nevertheless you try with all PACs in the world
# CFDI would be failed
except (
exceptions.ValidationError, exceptions.PrimarySectorError
exceptions.ValidationError, exceptions.PrimarySectorError,
exceptions.CancelError
) as error:
logger.debug(_(repr(error)))
raise UserError(
_(repr(error)),
)
......@@ -120,11 +123,11 @@ class ParamsPac(models.Model):
except Exception as error:
# If something went wrong try with next PAC
message_error = '\n'.join(
[message_error, param_pac.name, repr(error)],
[param_pac.name, repr(error)],
)
pacs_errors.append(message_error.encode('UTF-8')+'\n')
logger.info(
param_pac.name.encode('UTF-8'),
repr(error).encode('UTF-8'),
message_error.encode('UTF-8'),
)
continue
# api.one decorator always returns a list
......@@ -135,12 +138,10 @@ class ParamsPac(models.Model):
break
try:
return result
except UnboundLocalError:
except UnboundLocalError as e:
# If result value does not exist
# it is because all PACs failed
raise UserError(
_(message_error),
)
raise UserError(repr(pacs_errors))
@api.multi
def sign_cfdi(self, data):
......@@ -170,8 +171,15 @@ class ParamsPac(models.Model):
and so on.
@param self : All possible PACs to be used
@param data (string): data to sign in base64 encoding
@return: Dictionary
@param uuid: uuid of cfdi to cancel
@return: Return true if the cfdi can be canceled or false if it must wait
to be canceled
"""
result = self.fire_connection(uuid, 'get_driver_fc_cancel')
return result
if not len(self):
raise ValidationError(
_('No PAC have being selected.\nGo to Configuration '
'>> Accounting >> Electronic invoicing (MX) and select '
'a PAC.'),
)
cancel_estatus = self.fire_connection(uuid, 'get_driver_fc_cancel')
return cancel_estatus.check_cancel_status()
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