from odoo import api, fields, models class AccountMove(models.Model): _inherit = "account.move" cfdi_id = fields.Many2one(comodel_name="account.cfdi", string="CFDI") x_uuid = fields.Char(string="CFDI UIID", related="cfdi_id.uuid", store=True) x_delivery_number = fields.Char(string="No. Entrega") x_invoice_qty = fields.Integer(string="Unidades facturadas") #Eliminar relacion con el cfdi si se cancela el movimiento def button_cancel(self): res = super(AccountMove, self).button_cancel() for rec in self: if rec.cfdi_id: rec.cfdi_id.attachment_id.write({ 'res_model': 'account.cfdi', 'res_id': rec.cfdi_id.id, }) rec.cfdi_id.write({ "state": "draft", "move_id": False }) rec.write({ 'cfdi_id': False, 'x_uuid': False }) return res