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

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
parent c3934ab5
......@@ -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):
......
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