From c3934ab5b985f074c98149bf6eeb230dc1375db2 Mon Sep 17 00:00:00 2001 From: Cuauhtemoc Diaz Minor <cuauhtemoc.diaz@openpyme.mx> Date: Thu, 18 Oct 2018 17:22:09 -0500 Subject: [PATCH] =?UTF-8?q?perf(params.pac):=20Cambios=20necesarios=20para?= =?UTF-8?q?=20la=20cancelaci=C3=B3n=20del=20CFDI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- l10n_mx_params_pac/models/params_pac.py | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/l10n_mx_params_pac/models/params_pac.py b/l10n_mx_params_pac/models/params_pac.py index 3eccb900..369ead24 100644 --- a/l10n_mx_params_pac/models/params_pac.py +++ b/l10n_mx_params_pac/models/params_pac.py @@ -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() -- GitLab