| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
from odoo import api, SUPERUSER_ID |
| 3 |
|
| 4 |
|
| 5 |
def migrate(cr, version): |
| 6 |
env = api.Environment(cr, SUPERUSER_ID, {}) |
| 7 |
|
| 8 |
# Load the new tax groups if it doesn't exist yet |
| 9 |
ChartTemplate = env["account.chart.template"] |
| 10 |
companies = env['res.company'].search([('chart_template', '=', 'id')], order="parent_path") |
| 11 |
|
| 12 |
new_tax_groups = ["l10n_id_tax_group_non_luxury_goods", "l10n_id_tax_group_0", "l10n_id_tax_group_exempt"] |
| 13 |
|
| 14 |
tax_group_data = { |
| 15 |
xmlid: data |
| 16 |
for xmlid, data in ChartTemplate._get_account_tax_group('id').items() |
| 17 |
if xmlid in new_tax_groups |
| 18 |
} |
| 19 |
|
| 20 |
# For taxes: tax_ST1 and tax_PT1 which are non-luxury tax, if the amount and tax group |
| 21 |
# has not been changed yet by user, we update the tax group and description |
| 22 |
for company in companies: |
| 23 |
ChartTemplate.with_company(company)._load_data({ |
| 24 |
"account.tax.group": tax_group_data, |
| 25 |
}) |
| 26 |
tax_ST1 = ChartTemplate.with_company(company).ref("tax_ST1", raise_if_not_found=False) |
| 27 |
tax_PT1 = ChartTemplate.with_company(company).ref("tax_PT1", raise_if_not_found=False) |
| 28 |
|
| 29 |
old_group = ChartTemplate.with_company(company).ref("default_tax_group", raise_if_not_found=False) |
| 30 |
new_group = ChartTemplate.with_company(company).ref("l10n_id_tax_group_non_luxury_goods") |
| 31 |
|
| 32 |
if not old_group: |
| 33 |
continue |
| 34 |
|
| 35 |
for tax in [tax_ST1, tax_PT1]: |
| 36 |
if tax and tax.amount == 11.0 and tax.tax_group_id == old_group: |
| 37 |
tax.write({ |
| 38 |
"tax_group_id": new_group.id, |
| 39 |
"description": "12%", |
| 40 |
}) |