| 1 |
|
| 2 |
|
| 3 |
from odoo import models, fields |
| 4 |
from odoo.exceptions import UserError |
| 5 |
|
| 6 |
|
| 7 |
class L10nTwEDIInvoiceCancel(models.TransientModel): |
| 8 |
_name = "l10n_tw_edi.invoice.cancel" |
| 9 |
_description = "Implements cancelling an ecpay invoice." |
| 10 |
|
| 11 |
invoice_id = fields.Many2one( |
| 12 |
comodel_name="account.move", |
| 13 |
string="Document To Cancel", |
| 14 |
required=True, |
| 15 |
readonly=True, |
| 16 |
) |
| 17 |
reason = fields.Char( |
| 18 |
help="Reason for cancelling the document.", |
| 19 |
required=True, |
| 20 |
) |
| 21 |
|
| 22 |
def button_request_cancel(self): |
| 23 |
self.ensure_one() |
| 24 |
if not self.reason.strip(): |
| 25 |
raise UserError(self.env._("You must provide a reason for canceling the invoice.")) |
| 26 |
|
| 27 |
self.invoice_id.l10n_tw_edi_invalidate_reason = self.reason |
| 28 |
self.invoice_id._l10n_tw_edi_run_invoice_invalid() |
| 29 |
self.invoice_id.button_cancel() |