diff --git a/l10n_mx_ir_attachment_facturae/models/ir_attachment_facturae.py b/l10n_mx_ir_attachment_facturae/models/ir_attachment_facturae.py index 61758ad85fe9ffa998da15a8eb6fc1b6e504d70c..ade2bd952f158ca6134edad72869dd6c2b3debe2 100644 --- a/l10n_mx_ir_attachment_facturae/models/ir_attachment_facturae.py +++ b/l10n_mx_ir_attachment_facturae/models/ir_attachment_facturae.py @@ -127,6 +127,7 @@ class IrAttachmentFacturaeMx(models.Model): ('draft', _('Draft')), ('signed', _('Signed')), ('done', _('Done')), + ('waiting', _('To cancel')), ('cancel', _('Cancelled')), ] @@ -530,7 +531,14 @@ class IrAttachmentFacturaeMx(models.Model): self.ensure_one() if self.cfdi_type == 'incoming' and self.state in ('signed', 'done'): - self.cancel_cfdi_sat() + cancel_answer = self.cancel_cfdi_sat()[0] + if cancel_answer: + self.cancel_cfdi() + else: + self.write({ + 'state':'waiting', + }) + return cancel_answer def sign_xml(self, xml_data): # Get current certificate for current company @@ -694,6 +702,7 @@ class IrAttachmentFacturaeMx(models.Model): value = result.attrib[attrib] return value + @api.multi def create_report(self, attach_id, report_name, model): """ Create report @@ -796,11 +805,19 @@ class IrAttachmentFacturaeMx(models.Model): # the problem is that each PAC request CFDI information # in different way in order to cancel CFDI # Call function which connects with PACs - params_pacs.cancel_cfdi(uuid=self.uuid) + cancel_answer = params_pacs.cancel_cfdi(uuid=self.uuid) + return cancel_answer + + @api.model + def cancel_cfdi(self): + ''' Cancel CFDI and rewrite PDF + + Since we do not generate a new XML + Only generate PDF file + the idea is to overwrite the existing one + ''' + record = self.env[self.type_attachment].browse(self.res_id) - # Since we do not generate a new XML - # Only generate PDF file - # the idea is to overwrite the existing one data = self.create_report( record.id, self.config_id.template_pdf_sign, model=record._name, ) @@ -811,7 +828,6 @@ class IrAttachmentFacturaeMx(models.Model): 'cfdi_fecha_cancelado': fields.Datetime.now(), 'state': 'cancel', }) - return @api.one def validate_cfdi_folio_fiscal(self):