| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo import fields, models |
| 4 |
|
| 5 |
|
| 6 |
class AccountMoveReversal(models.TransientModel): |
| 7 |
_inherit = "account.move.reversal" |
| 8 |
|
| 9 |
l10n_tw_edi_refund_agreement_type = fields.Selection( |
| 10 |
selection=[("offline", "Offline"), ("online", "Online")], |
| 11 |
string="Agreement Type", |
| 12 |
) |
| 13 |
l10n_tw_edi_allowance_notify_way = fields.Selection( |
| 14 |
selection=[("email", "Email"), ("phone", "Phone")], |
| 15 |
string="Allowance Notify Way", |
| 16 |
) |
| 17 |
l10n_tw_edi_ecpay_invoice_id = fields.Char(compute="_compute_from_moves") |
| 18 |
l10n_tw_edi_is_b2b = fields.Boolean(compute="_compute_from_moves") |
| 19 |
|
| 20 |
def _compute_from_moves(self): |
| 21 |
super()._compute_from_moves() |
| 22 |
for record in self: |
| 23 |
move_ids = record.move_ids._origin |
| 24 |
record.l10n_tw_edi_ecpay_invoice_id = len(move_ids) == 1 and move_ids.l10n_tw_edi_ecpay_invoice_id or False |
| 25 |
record.l10n_tw_edi_is_b2b = len(move_ids) == 1 and move_ids.l10n_tw_edi_is_b2b or False |
| 26 |
|
| 27 |
def _prepare_default_reversal(self, move): |
| 28 |
res = super()._prepare_default_reversal(move) |
| 29 |
res.update({ |
| 30 |
"l10n_tw_edi_ecpay_invoice_id": move.l10n_tw_edi_ecpay_invoice_id, |
| 31 |
"l10n_tw_edi_invoice_create_date": move.l10n_tw_edi_invoice_create_date, |
| 32 |
"l10n_tw_edi_refund_agreement_type": self.l10n_tw_edi_refund_agreement_type, |
| 33 |
"l10n_tw_edi_allowance_notify_way": self.l10n_tw_edi_allowance_notify_way, |
| 34 |
"l10n_tw_edi_invalidate_reason": self.reason, |
| 35 |
}) |
| 36 |
return res |
| 37 |
|
| 38 |
def reverse_moves(self, is_modify=False): |
| 39 |
moves = self.move_ids |
| 40 |
if is_modify: |
| 41 |
for move in moves.filtered(lambda m: m.l10n_tw_edi_ecpay_invoice_id): |
| 42 |
move.l10n_tw_edi_invalidate_reason = self.reason |
| 43 |
move._l10n_tw_edi_run_invoice_invalid() |
| 44 |
return super().reverse_moves(is_modify) |