| 1 | from odoo import SUPERUSER_ID, api |
| 2 | |
| 3 | |
| 4 | def migrate(cr, version): |
| 5 | """ Remove the tags on these taxes to avoid having clearly misconfigured ones """ |
| 6 | tax_xmlid_regex = "_sa_(?:local_sales_tax_0|export_sales_tax_0|exempt_sales_tax_0|purchases_tax_0|exempt_purchases_tax|rcp_tax_15)$" |
| 7 | cr.execute( |
| 8 | """ |
| 9 | WITH tags_to_delete AS ( |
| 10 | SELECT tag_rel.* |
| 11 | FROM account_account_tag_account_tax_repartition_line_rel AS tag_rel |
| 12 | JOIN account_tax_repartition_line AS rep_line |
| 13 | ON rep_line.id = tag_rel.account_tax_repartition_line_id |
| 14 | JOIN account_tax AS tax |
| 15 | ON tax.id = rep_line.tax_id |
| 16 | JOIN ir_model_data AS imd_taxes |
| 17 | ON imd_taxes.res_id = tax.id |
| 18 | AND imd_taxes.model = 'account.tax' |
| 19 | AND imd_taxes.module = 'account' |
| 20 | JOIN res_company company |
| 21 | ON company.chart_template = 'sa' |
| 22 | WHERE rep_line.repartition_type = 'tax' |
| 23 | AND imd_taxes.name ~ ('^' || company.id || %s) |
| 24 | ) |
| 25 | DELETE |
| 26 | FROM account_account_tag_account_tax_repartition_line_rel AS tag_rel |
| 27 | USING tags_to_delete t |
| 28 | WHERE tag_rel.account_tax_repartition_line_id = t.account_tax_repartition_line_id |
| 29 | AND tag_rel.account_account_tag_id = t.account_account_tag_id; |
| 30 | """, |
| 31 | [tax_xmlid_regex], |
| 32 | ) |
| 33 | |
| 34 | env = api.Environment(cr, SUPERUSER_ID, {}) |
| 35 | for company in env["res.company"].search([("chart_template", "=", "sa")], order="parent_path"): |
| 36 | env["account.chart.template"].try_loading("sa", company) |