account_move_reversal.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, api
  4. from odoo.exceptions import UserError
  5. class AccountMoveReversal(models.TransientModel):
  6. _inherit = 'account.move.reversal'
  7. l10n_es_tbai_is_required = fields.Boolean(
  8. compute="_compute_l10n_es_tbai_is_required", readonly=True,
  9. string="Is TicketBai required for this reversal",
  10. )
  11. l10n_es_tbai_refund_reason = fields.Selection(
  12. selection=[
  13. ('R1', "R1: Art. 80.1, 80.2, 80.6 and rights founded error"),
  14. ('R2', "R2: Art. 80.3"),
  15. ('R3', "R3: Art. 80.4"),
  16. ('R4', "R4: Art. 80 - other"),
  17. ('R5', "R5: Factura rectificativa en facturas simplificadas"),
  18. ],
  19. string="Invoice Refund Reason Code (TicketBai)",
  20. help="BOE-A-1992-28740. Ley 37/1992, de 28 de diciembre, del Impuesto sobre el "
  21. "Valor Añadido. Artículo 80. Modificación de la base imponible.",
  22. )
  23. @api.depends('move_ids')
  24. def _compute_l10n_es_tbai_is_required(self):
  25. for wizard in self:
  26. moves_tbai_required = set(m.l10n_es_tbai_is_required for m in wizard.move_ids)
  27. if len(moves_tbai_required) > 1:
  28. raise UserError("Reversals mixing invoices with and without TicketBAI are not allowed.")
  29. wizard.l10n_es_tbai_is_required = moves_tbai_required.pop()
  30. def _prepare_default_reversal(self, move):
  31. # OVERRIDE
  32. values = super()._prepare_default_reversal(move)
  33. if move.company_id.country_id.code == "ES" and move.l10n_es_tbai_is_required:
  34. values.update({
  35. 'l10n_es_tbai_refund_reason': self.l10n_es_tbai_refund_reason,
  36. })
  37. return values