diff --git a/l10n_mx_params_pac/models/params_pac.py b/l10n_mx_params_pac/models/params_pac.py index 3eccb90056aae31df7407e2b7a354b261fd0c8b1..369ead24ca4627cf8e0fe0bccb0e42022ec9b129 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()