Commit 98181ff8 authored by Ricardo Adolfo Mendoza Escobedo's avatar Ricardo Adolfo Mendoza Escobedo Committed by Carlos Antonio Pérez Felipe

Problema con la variable cancelación dentro del ciclo for en la funcion l10n_mx_action_cancel

parent c4db8b68
Pipeline #22794 failed with stage
in 43 seconds
This diff is collapsed.
......@@ -320,42 +320,6 @@ class AccountMove(models.Model):
# Create new CFDI object for this invoice
account_invoice.create_cfdi()
def action_cancel(self):
"""Extend `AccountMove.action_cancel()`; Cancels the CFDI related to the
invoice
"""
# Get only invoices with related cfdi to cancel cfdi before cancel invoice
cfdis = self.filtered(
lambda i:
i.journal_id.sign_sat
and i.cfdi_id
and i.cfdi_id.state not in ["draft", "cancel"]
)
for invoice in cfdis:
# Ensure we can cancel this invoice
invoice.check_if_can_cancel()
# If l10n_mx_edi_original_invoice is set save uuid to send info to PAC
# while cancel invoice
invoice.cfdi_id.substitute_cfdi_uuid = (
invoice.l10n_mx_edi_original_invoice.cfdi_id.uuid
)
cancelacion = invoice.cancel_cfdi()[0]
if cancelacion:
# CFDI cancelled (cancelacion == True) must cancel invoice too
super(AccountMove, invoice).action_cancel()
elif cancelacion is None:
# CFDI set to approval (cancelacion == None) must set invoice
# to waiting too
invoice.write({"state": "waiting"})
elif cancelacion is False:
# CFDI cancel denied (cancelacion == False) must get back invoice
# to open state
self.undo_waiting_state()
# Call super only with invoices without CFDI
invoices = self - cfdis
return super(AccountMove, invoices).action_cancel()
def undo_waiting_state(self):
"""When cancel is negate revert invoice to open and post account_move"""
for record in self:
......@@ -525,12 +489,11 @@ class AccountMove(models.Model):
return res
def l10n_mx_action_cancel(self):
"""Cancels the CFDI related to the invoice"""
# Call write() to update the is_cancelable field
self.write({'is_cancelable': True})
# Get only invoices with related cfdi to cancel cfdi before cancel invoice
"""Extend `AccountInvoice.action_cancel()`; Cancels the CFDI related to the
invoice
"""
self.write({"is_cancelable": True})
# Get only invoices with related cfdi to cancel cfdi before cancel invoice
cfdis = self.filtered(
lambda i:
......@@ -538,30 +501,12 @@ class AccountMove(models.Model):
and i.cfdi_id
and i.cfdi_id.state not in ["draft", "cancel"]
)
for invoice in cfdis:
# Ensure we can cancel this invoice
invoice.check_if_can_cancel()
# If l10n_mx_edi_original_invoice is set save uuid to send info to PAC
# while cancel invoice
invoice.cfdi_id.substitute_cfdi_uuid = (
invoice.l10n_mx_edi_original_invoice.cfdi_id.uuid
)
invoice.message_post(
body=_("Cancellation request sent")
)
cancelacion = invoice.cancel_cfdi()[0]
if cancelacion:
# CFDI cancelled (cancelacion == True) must cancel invoice too
invoice.button_draft()
invoice.button_cancel()
elif cancelacion is None:
# CFDI set to approval (cancelacion == None) must set invoice
# to waiting too
invoice.write({"state": "waiting"})
elif cancelacion is False:
# CFDI cancel denied (cancelacion == False) must get back invoice
# to open state
self.undo_waiting_state()
class AccountMoveLine(models.Model):
......
......@@ -36,6 +36,7 @@
type="object"
class="btn-primary"
attrs="{'invisible': [
'&',
('state', '!=', 'posted'),
('cfdi_state', '!=', 'done')
]}"/>
......
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