From bb4ad752408779b8746177bcc15ce7faf79d0fae Mon Sep 17 00:00:00 2001 From: Cuauhtemoc Diaz Minor <cuauhtemoc.diaz@openpyme.mx> Date: Thu, 18 Oct 2018 17:31:08 -0500 Subject: [PATCH] feat(ir.attachment.facturae.mx): cancelacion cfdi 3.3 Se agrega el estado waiting, y se modifica `action_cancel` y `cancel_cfdi_sat` para la cancelacion de CFDI --- .../models/ir_attachment_facturae.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) 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 61758ad8..ade2bd95 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): -- GitLab