Debian Codegraph @

addons/l10n_tw_edi_ecpay/models/account_tax.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import api, fields, models
4 from odoo.exceptions import UserError
5
6
7 class AccountTax(models.Model):
8 _inherit = "account.tax"
9
10 l10n_tw_edi_tax_type = fields.Selection(
11 string="Ecpay Tax Type",
12 selection=[
13 ("1", "Taxable"),
14 ("2", "Zero tax rate"),
15 ("3", "Duty free"),
16 ("4", "Taxable (special tax rate)"),
17 ],
18 store=True,
19 readonly=False,
20 compute="_compute_l10n_tw_edi_tax_type",
21 )
22 l10n_tw_edi_special_tax_type = fields.Selection(
23 string="Ecpay Special Tax Type",
24 selection=[
25 ("1", "Saloons and tea rooms, coffee shops and bars offering companionship services: Tax rate is 25%"),
26 ("2", "Night clubs or restaurants providing entertaining show programs: Tax rate is 15%"),
27 ("3", "Banking businesses, insurance businesses, trust investment businesses, securities businesses, "
28 "futures businesses, commercial paper businesses and pawn-broking businesses: Tax rate is 2%"),
29 ("4", "The sales amounts from reinsurance premiums shall be taxed at 1%"),
30 ("5", "Banking businesses, insurance businesses, trust investment businesses, securities businesses, "
31 "futures businesses, commercial paper businesses and pawn-broking businesses: Tax rate is 5%"),
32 ("6", "Core business revenues from the banking and insurance business of the banking and insurance "
33 "industries (Applicable to sales after July 2014): Tax rate is 5%"),
34 ("7", "Core business revenues from the banking and insurance business of the banking and insurance "
35 "industries (Applicable to sales after June 2014): Tax rate is 5%"),
36 ("8", "Duty free or non-output data"),
37 ],
38 )
39
40 @api.depends("country_id", "amount")
41 def _compute_l10n_tw_edi_tax_type(self):
42 for tax in self:
43 if tax.country_id.code == "TW":
44 tax.l10n_tw_edi_tax_type = "2" if tax.amount == 0 else "1"
45 else:
46 tax.l10n_tw_edi_tax_type = False
47
48 @api.onchange('l10n_tw_edi_tax_type')
49 def _onchange_l10n_tw_edi_tax_type(self):
50 for tax in self:
51 if tax.l10n_tw_edi_tax_type not in ["3", "4"]:
52 tax.l10n_tw_edi_special_tax_type = False
53
54 @api.constrains('l10n_tw_edi_tax_type', 'l10n_tw_edi_special_tax_type')
55 def _check_special_tax_type_constrains(self):
56 for tax in self:
57 if tax.l10n_tw_edi_tax_type == "3" and tax.l10n_tw_edi_special_tax_type in ['1', '2', '3', '4', '5', '6', '7']:
58 raise UserError(self.env._("Invalid special tax type for Duty free tax type."))
59 if tax.l10n_tw_edi_tax_type in ["2", "3"] and tax.amount != 0:
60 raise UserError(self.env._("Zero tax rate and Duty free tax type must have a tax amount of 0."))