feat(base.cfdi.mixin): función para la cancelación y substitución

Se pone a qui la función para que se pueda ocupar tanto para los pagos y para las fucturas
parent e989a89d
Pipeline #8457 failed with stage
in 1 minute and 22 seconds
......@@ -9,3 +9,4 @@ from . import ir_attachment
from . import ir_attachment_facturae
from . import ir_attachment_facturae_config
from . import res_company_facturae_fiel
from . import cfdi_related
......@@ -3,6 +3,8 @@
import logging
from openerp import api, fields, models
from openerp.exceptions import ValidationError
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
......@@ -83,6 +85,7 @@ class BaseCfdi(models.AbstractModel):
"related_cfdi_id",
"original_cfdi_id",
"Refund invoices",
compute="_compute_related_cfdi_ids",
readonly=True,
copy=False,
help="Original CFDI to which this CFDI is referred to",
......@@ -95,6 +98,17 @@ class BaseCfdi(models.AbstractModel):
help="Select addendum node to use on this CFDI."
)
@api.multi
def _compute_related_cfdi_ids(self):
for record in self:
cfdi_related = self.env["cfdi.related"].search(
[
("related_cfdi_id", "=", record.id),
("type_attachment", "=", record._name),
]
)
record.update({"related_cfdi_ids": cfdi_related.original_cfdi_id})
@api.one
def create_cfdi(self):
"""Creates a new cfdi object related with current record"""
......@@ -134,3 +148,33 @@ class BaseCfdi(models.AbstractModel):
"""Consult the status cancel of the cfdi related"""
if self.cfdi_id and self.cfdi_id.state in ["waiting", "cancel"]:
return self.cfdi_id.action_consult_cancellation_status()
@api.multi
def _cancel_cfdi_related_document(self):
raise ValidationError(_("Cfdi was not canceled due to an internal problem"))
@api.multi
def _cancel_cfdi(self):
"""General steps needed for cancel a CFDI related to a record"""
# self._origin_cfdi_search()
self.ensure_one()
# Before cancel original voucher set relation to current related CFDI
self.write(
{"cfdi_relation_type": self.env.ref("l10n_mx.cfdi_relation_type_04").id}
)
self.env["cfdi.related"].search(
[("related_cfdi_id", "=", self.id), ("type_attachment", "=", self._name)]
).unlink()
self.env["cfdi.related"].create(
{
"related_cfdi_id": self.id,
"original_cfdi_id": self.cfdi_id.id,
"type_attachment": self._name,
}
)
# We also remove relation for attachments to avoid confusing situations
self.cfdi_id.file_xml_sign.res_id = None
if self.cfdi_id.file_pdf:
self.cfdi_id.file_pdf.res_id = None
# Actually cancel de related document
self._cancel_cfdi_related_document()
# -*- coding: utf-8 -*-
# Copyright 2019 OpenPyme
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
class CfdiRelated(models.Model):
_name = "cfdi.related"
_description = "Cfdi Related"
_table = "cfdis_related_rel"
related_cfdi_id = fields.Integer(help="Document related to cfdi")
original_cfdi_id = fields.Many2one(
"ir.attachment.facturae.mx", help="Original Cfdi replaced"
)
type_attachment = fields.Char(help="Type of document related")
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