Skip to content

Commit

Permalink
[17.0][FIX] l10n_es_vat_prorate: load prorate taxes in py file
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelregidor committed May 21, 2024
1 parent 104df46 commit 34d5509
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 74 deletions.
42 changes: 0 additions & 42 deletions l10n_es_vat_prorate/data/template/account.tax-es_common.csv

This file was deleted.

1 change: 1 addition & 0 deletions l10n_es_vat_prorate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import res_company
from . import account_move
from . import account_tax
from . import prorate_taxes
43 changes: 11 additions & 32 deletions l10n_es_vat_prorate/models/account_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# Copyright 2024 Sygel - Manuel Regidor
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import csv

from odoo import api, fields, models
from odoo.tools import file_open


class AccountTax(models.Model):
Expand All @@ -29,39 +27,20 @@ class AccountTax(models.Model):

@api.depends("company_id.with_vat_prorate")
def _compute_with_vat_prorate(self):
template_data = []
if any(tax.company_with_vat_prorate for tax in self):
with file_open(
"l10n_es_vat_prorate/data/template/account.tax-es_common.csv"
) as template_file:
template_data = [
(
record["id"],
record["template_with_vat_prorate"],
record["prorate_account_template_ids"],
)
for record in csv.DictReader(template_file)
]
prorate_taxes = []
for tax in self:
with_vat_prorate = False
prorate_account_ids = []
if tax.company_with_vat_prorate:
company = tax.company_id
for template in template_data:
tax_from_tmpl = company._get_tax_id_from_xmlid(template[0])
if tax_from_tmpl == tax.id:
with_vat_prorate = template[1]
if template[2]:
prorate_account_ids = [(5, 0, 0)]
account_tmpls = template[2].split(",")
for account_tmpl in account_tmpls:
account_from_tmpl_id = (
company._get_account_id_from_xmlid(account_tmpl)
)
if account_from_tmpl_id:
prorate_account_ids.append(
(4, account_from_tmpl_id)
)
break
prorate_taxes = self.company_id._get_prorate_taxes()
if prorate_taxes.get(tax.id):
with_vat_prorate = prorate_taxes.get(tax.id)[
"template_with_vat_prorate"
]
prorate_account_ids = [(5, 0, 0)]
for account_from_tmpl_id in prorate_taxes.get(tax.id).get(
"prorate_account_ids"
):
prorate_account_ids.append((4, account_from_tmpl_id))
tax.with_vat_prorate = with_vat_prorate
tax.prorate_account_ids = prorate_account_ids
166 changes: 166 additions & 0 deletions l10n_es_vat_prorate/models/prorate_taxes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
PRORATE_TAXES = {
"account_tax_template_p_iva21_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva21_sc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva4_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva4_sc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva21_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva4_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_sc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva105_gan": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva12_agr": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva4_ibc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva21_ibc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva21_ibi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva4_ibi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_ibc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_ibi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva21_sp_in": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva21_ic_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva21_ic_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_sp_ex": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva10_sp_ex": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva21_sp_ex": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_ic_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_ic_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva10_ic_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva10_ic_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva5_ic_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva5_ic_sc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva5_ibc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva5_isc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva5_bc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva5_sc": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": [],
},
"account_tax_template_p_iva10_sp_in": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_sp_in": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_isp": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva10_isp": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva21_isp": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva4_isp_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva10_isp_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
"account_tax_template_p_iva21_isp_bi": {
"template_with_vat_prorate": True,
"prorate_account_template_ids": ["account_common_472"],
},
}
22 changes: 22 additions & 0 deletions l10n_es_vat_prorate/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import ormcache

from .prorate_taxes import PRORATE_TAXES


class ResCompany(models.Model):
Expand All @@ -14,6 +17,25 @@ class ResCompany(models.Model):
"res.company.vat.prorate", inverse_name="company_id"
)

@ormcache("self")
def _get_prorate_taxes(self):
prorate_taxes_mapping = {}
for tax_tmpl in PRORATE_TAXES:
vals = PRORATE_TAXES.get(tax_tmpl)
tax_from_tmpl = self._get_tax_id_from_xmlid(tax_tmpl)
if tax_from_tmpl:
template_with_vat_prorate = vals["template_with_vat_prorate"]
prorate_account_ids = []
for account_tmpl in vals.get("prorate_account_template_ids"):
account_from_tmpl_id = self._get_account_id_from_xmlid(account_tmpl)
if account_from_tmpl_id:
prorate_account_ids.append(account_from_tmpl_id)
prorate_taxes_mapping[tax_from_tmpl] = {
"template_with_vat_prorate": template_with_vat_prorate,
"prorate_account_ids": prorate_account_ids,
}
return prorate_taxes_mapping

def get_prorate(self, date):
self.ensure_one()
prorate = self.env["res.company.vat.prorate"].search(
Expand Down

0 comments on commit 34d5509

Please sign in to comment.