mirror of
https://github.com/bringout/oca-ocb-l10n_asia-pacific.git
synced 2026-04-26 06:22:01 +02:00
19.0 vanilla
This commit is contained in:
parent
7dc55599c6
commit
7f43bbbfcc
650 changed files with 45260 additions and 33436 deletions
|
|
@ -1,6 +1,8 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.addons.account.models.chart_template import update_taxes_from_templates
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
update_taxes_from_templates(cr, 'l10n_id.l10n_id_chart')
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
for company in env['res.company'].search([('chart_template', '=', 'id')], order="parent_path"):
|
||||
env['account.chart.template'].try_loading('id', company, force_create=False)
|
||||
|
|
|
|||
|
|
@ -5,39 +5,36 @@ from odoo import api, SUPERUSER_ID
|
|||
def migrate(cr, version):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
# Tax groups to create in format of [(xml_id, name)]
|
||||
tax_group_info = [
|
||||
("l10n_id_tax_group_non_luxury_goods", "Non-luxury Good Taxes"),
|
||||
("l10n_id_tax_group_0", "Zero-rated Taxes"),
|
||||
("l10n_id_tax_group_exempt", "Tax Exempted"),
|
||||
]
|
||||
# Load the new tax groups if it doesn't exist yet
|
||||
ChartTemplate = env["account.chart.template"]
|
||||
companies = env['res.company'].search([('chart_template', '=', 'id')], order="parent_path")
|
||||
|
||||
for xmlid, name in tax_group_info:
|
||||
if not env.ref(f"l10n_id.{xmlid}", raise_if_not_found=False):
|
||||
env['ir.model.data'].create({
|
||||
"name": xmlid,
|
||||
"module": "l10n_id",
|
||||
"model": "account.tax.group",
|
||||
"res_id": env['account.tax.group'].create({'name': name, 'country_id': env.ref('base.id').id}).id,
|
||||
'noupdate': True
|
||||
})
|
||||
new_tax_groups = ["l10n_id_tax_group_non_luxury_goods", "l10n_id_tax_group_0", "l10n_id_tax_group_exempt"]
|
||||
|
||||
# For all taxes linked to the tax_ST1 and tax_PT1, set the tax group to non-luxury goods
|
||||
# if no changes to amount and tax group yet
|
||||
tax_group_id = env.ref("l10n_id.l10n_id_tax_group_non_luxury_goods")
|
||||
default_group = env['account.tax']._default_tax_group()
|
||||
id_chart = env.ref("l10n_id.l10n_id_chart", raise_if_not_found=False)
|
||||
tax_group_data = {
|
||||
xmlid: data
|
||||
for xmlid, data in ChartTemplate._get_account_tax_group('id').items()
|
||||
if xmlid in new_tax_groups
|
||||
}
|
||||
|
||||
if not id_chart:
|
||||
return
|
||||
|
||||
companies = env['res.company'].search([('chart_template_id', 'child_of', id_chart.id)])
|
||||
# For taxes: tax_ST1 and tax_PT1 which are non-luxury tax, if the amount and tax group
|
||||
# has not been changed yet by user, we update the tax group and description
|
||||
for company in companies:
|
||||
tax_xml_ids = [
|
||||
f"l10n_id.{company.id}_tax_ST1",
|
||||
f"l10n_id.{company.id}_tax_PT1",
|
||||
]
|
||||
for tax_xml_id in tax_xml_ids:
|
||||
tax = env.ref(tax_xml_id, raise_if_not_found=False)
|
||||
if tax and tax.amount == 11.0 and tax.tax_group_id == default_group:
|
||||
tax.update({"tax_group_id": tax_group_id.id, "description": "12%"})
|
||||
ChartTemplate.with_company(company)._load_data({
|
||||
"account.tax.group": tax_group_data,
|
||||
})
|
||||
tax_ST1 = ChartTemplate.with_company(company).ref("tax_ST1", raise_if_not_found=False)
|
||||
tax_PT1 = ChartTemplate.with_company(company).ref("tax_PT1", raise_if_not_found=False)
|
||||
|
||||
old_group = ChartTemplate.with_company(company).ref("default_tax_group", raise_if_not_found=False)
|
||||
new_group = ChartTemplate.with_company(company).ref("l10n_id_tax_group_non_luxury_goods")
|
||||
|
||||
if not old_group:
|
||||
continue
|
||||
|
||||
for tax in [tax_ST1, tax_PT1]:
|
||||
if tax and tax.amount == 11.0 and tax.tax_group_id == old_group:
|
||||
tax.write({
|
||||
"tax_group_id": new_group.id,
|
||||
"description": "12%",
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {"lang": "en_US"})
|
||||
|
||||
companies = env["res.company"].search([("chart_template", "=", "id"), ("parent_id", "=", False)])
|
||||
|
||||
new_tax_groups = ["l10n_id_tax_group_stlg", "l10n_id_tax_group_non_luxury_goods", "l10n_id_tax_group_luxury_goods", "l10n_id_tax_group_0"]
|
||||
new_taxes = [
|
||||
"tax_ST4", "tax_PT4",
|
||||
"tax_ST5", "tax_PT5",
|
||||
"tax_ST6", "tax_ST7",
|
||||
"tax_luxury_sales_pemungut_ppn",
|
||||
"tax_PT6", "tax_PT7",
|
||||
]
|
||||
|
||||
for company in companies:
|
||||
ChartTemplate = env["account.chart.template"].with_company(company)
|
||||
# =============================
|
||||
# Load new tax data
|
||||
tax_group_data = {
|
||||
xmlid: data
|
||||
for xmlid, data in ChartTemplate._get_account_tax_group("id").items()
|
||||
if xmlid in new_tax_groups
|
||||
}
|
||||
tax_data = {
|
||||
xmlid: data
|
||||
for xmlid, data in ChartTemplate._get_account_tax("id").items()
|
||||
if xmlid in new_taxes
|
||||
}
|
||||
new_tax_group_data = {}
|
||||
if (tax_group_data):
|
||||
new_tax_group_data = {
|
||||
g: data
|
||||
for g, data in tax_group_data.items()
|
||||
if not ChartTemplate.ref(g, raise_if_not_found=False)
|
||||
}
|
||||
|
||||
if new_tax_group_data:
|
||||
data = {"account.tax.group": new_tax_group_data}
|
||||
ChartTemplate._pre_reload_data(company, {}, data)
|
||||
ChartTemplate._load_data(data)
|
||||
if tax_data:
|
||||
data = {"account.tax": tax_data}
|
||||
ChartTemplate._pre_reload_data(company, {}, data)
|
||||
ChartTemplate._load_data(data)
|
||||
# =============================
|
||||
# Update existing tax description
|
||||
tax_map = {
|
||||
"tax_ST0": "VAT Not Collected",
|
||||
"tax_PT0": "Zero-Rated",
|
||||
"tax_ST2": "Exempt",
|
||||
"tax_PT2": "Exempt",
|
||||
"tax_ST3": "Taxable Luxury Goods",
|
||||
"tax_PT3": "Standard Rate for Luxury Goods & Services",
|
||||
}
|
||||
for xmlid, new_description in tax_map.items():
|
||||
tax = ChartTemplate.ref(xmlid, raise_if_not_found=False)
|
||||
if not tax:
|
||||
continue
|
||||
# Only update description if it hasn't been manually changed
|
||||
if tax.description == xmlid.replace("tax_", "").upper():
|
||||
tax.description = new_description
|
||||
|
||||
# =============================
|
||||
# Archive ST1 and PT1
|
||||
for xmlid in ["tax_ST1", "tax_PT1"]:
|
||||
tax = ChartTemplate.ref(xmlid, raise_if_not_found=False)
|
||||
if tax and not tax.active:
|
||||
continue
|
||||
if tax:
|
||||
tax.active = False
|
||||
|
||||
# =============================
|
||||
# Remove l10n_id.ppn_tag from specific taxes
|
||||
taxes_to_clean = [
|
||||
"tax_ST1", "tax_PT1",
|
||||
"tax_ST3", "tax_PT3",
|
||||
"tax_luxury_sales",
|
||||
]
|
||||
ppn_tag = env.ref("l10n_id.ppn_tag", raise_if_not_found=False)
|
||||
if ppn_tag:
|
||||
tax_records = env["account.tax"].browse([])
|
||||
for xmlid in taxes_to_clean:
|
||||
rec = ChartTemplate.ref(xmlid, raise_if_not_found=False)
|
||||
if rec:
|
||||
tax_records |= rec
|
||||
|
||||
if tax_records:
|
||||
repartition_lines = env["account.tax.repartition.line"].sudo().search([
|
||||
("tax_id", "in", tax_records.ids),
|
||||
("tag_ids", "in", [ppn_tag.id]),
|
||||
])
|
||||
if repartition_lines:
|
||||
repartition_lines.write({"tag_ids": [(3, ppn_tag.id)]})
|
||||
|
||||
# =============================
|
||||
# Update tax_luxury_sales group, description and invoice_label
|
||||
old_group = ChartTemplate.ref("l10n_id_tax_group_luxury_goods", raise_if_not_found=False)
|
||||
new_group = ChartTemplate.ref("l10n_id_tax_group_stlg", raise_if_not_found=False)
|
||||
tax_luxury_sales = ChartTemplate.ref("tax_luxury_sales", raise_if_not_found=False)
|
||||
if not (old_group and new_group and tax_luxury_sales):
|
||||
continue
|
||||
tax_luxury_sales_vals = {}
|
||||
if tax_luxury_sales.tax_group_id == old_group:
|
||||
tax_luxury_sales_vals['tax_group_id'] = new_group.id
|
||||
if tax_luxury_sales.description == "Luxury":
|
||||
tax_luxury_sales_vals['description'] = "Sales Tax on Luxury Goods (STLG)"
|
||||
if tax_luxury_sales.invoice_label == "Luxury Goods (ID)":
|
||||
tax_luxury_sales_vals['invoice_label'] = "20%"
|
||||
if tax_luxury_sales.name == "20%":
|
||||
tax_luxury_sales_vals['name'] = "20% (STLG)"
|
||||
if tax_luxury_sales.is_base_affected:
|
||||
tax_luxury_sales['is_base_affected'] = False
|
||||
tax_luxury_sales.write(tax_luxury_sales_vals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue