account_move.py 1015 B

12345678910111213141516171819202122232425262728
  1. from odoo import api, fields, models
  2. class AccountMove(models.Model):
  3. _inherit = "account.move"
  4. cfdi_id = fields.Many2one(comodel_name="account.cfdi", string="CFDI")
  5. x_uuid = fields.Char(string="CFDI UIID", related="cfdi_id.uuid", store=True)
  6. x_delivery_number = fields.Char(string="No. Entrega")
  7. x_invoice_qty = fields.Integer(string="Unidades facturadas")
  8. #Eliminar relacion con el cfdi si se cancela el movimiento
  9. def button_cancel(self):
  10. res = super(AccountMove, self).button_cancel()
  11. for rec in self:
  12. if rec.cfdi_id:
  13. rec.cfdi_id.attachment_id.write({
  14. 'res_model': 'account.cfdi',
  15. 'res_id': rec.cfdi_id.id,
  16. })
  17. rec.cfdi_id.write({
  18. "state": "draft",
  19. "move_id": False
  20. })
  21. rec.write({
  22. 'cfdi_id': False,
  23. 'x_uuid': False
  24. })
  25. return res