Skip to content

Commit 1360408

Browse files
authored
Merge pull request #5534 from Tecnativa/17.0-ou-add-l10n_mx
[17.0][OU-ADD] l10n_mx: Migration scripts
2 parents c53b4b7 + e5fc004 commit 1360408

4 files changed

Lines changed: 1306 additions & 1 deletion

File tree

docsource/modules160-170.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ Module coverage 16.0 -> 17.0
518518
+---------------------------------------------------+----------------------+-------------------------------------------------+
519519
| |del| l10n_multilang | Done |Merged into account. |
520520
+---------------------------------------------------+----------------------+-------------------------------------------------+
521-
| l10n_mx | | |
521+
| l10n_mx | Done | |
522522
+---------------------------------------------------+----------------------+-------------------------------------------------+
523523
| l10n_mx_hr | |No DB layout changes. |
524524
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2026 Tecnativa - David Bañón Gil
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade
4+
5+
6+
def _compute_new_tax_type(env):
7+
openupgrade.logged_query(
8+
env.cr,
9+
"""
10+
UPDATE account_tax t
11+
SET l10n_mx_tax_type =
12+
CASE
13+
WHEN c.code = 'MX' THEN 'iva'
14+
ELSE NULL
15+
END
16+
FROM res_country c
17+
WHERE t.country_id = c.id;
18+
""",
19+
)
20+
21+
22+
def _delete_analytic_tags(env):
23+
l10n_mx_xmlids = [
24+
"tag_diot_0",
25+
"tag_diot_16",
26+
"tag_diot_16_imp",
27+
"tag_diot_16_non_cre",
28+
"tag_diot_8",
29+
"tag_diot_8_non_cre",
30+
"tag_diot_exento",
31+
"tag_diot_ret",
32+
"tag_ieps",
33+
"tag_isr",
34+
"tag_iva",
35+
]
36+
openupgrade.delete_records_safely_by_xml_id(
37+
env, [f"l10n_mx.{x}" for x in l10n_mx_xmlids]
38+
)
39+
40+
41+
@openupgrade.migrate()
42+
def migrate(env, version):
43+
_delete_analytic_tags(env)
44+
_compute_new_tax_type(env)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2026 Tecnativa - David Bañón Gil
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade
4+
5+
6+
def _backup_tax_type(env):
7+
# l10n_mx_tax_type is now a different field
8+
# old l10n_mx_tax_type is renamed to l10n_mx_factor_type
9+
openupgrade.copy_columns(
10+
env.cr,
11+
{"account_tax": [("l10n_mx_tax_type", "l10n_mx_factor_type", None)]},
12+
)
13+
14+
15+
def _remove_xml_id_account_fiscal_position(env):
16+
"""In 17.0 account.fiscal.position.tax and account.fiscal.position.account don't
17+
have xml_id, so let's remove it for companies with this CoA.
18+
"""
19+
for company in (
20+
env["res.company"]
21+
.with_context(active_test=False)
22+
.search([("chart_template", "=", "mx")])
23+
):
24+
openupgrade.logged_query(
25+
env.cr,
26+
f"""
27+
DELETE FROM ir_model_data
28+
WHERE module='l10n_mx'
29+
AND model IN (
30+
'account.fiscal.position.tax', 'account.fiscal.position.account'
31+
) AND name LIKE '{company.id}_%'
32+
""",
33+
)
34+
# Also remove xmlids for fiscal position templates
35+
openupgrade.logged_query(
36+
env.cr,
37+
"""
38+
DELETE FROM ir_model_data
39+
WHERE module='l10n_mx'
40+
AND model IN (
41+
'account.fiscal.position.template', 'account.fiscal.position.tax.template'
42+
)
43+
""",
44+
)
45+
46+
47+
@openupgrade.migrate()
48+
def migrate(env, version):
49+
_backup_tax_type(env)
50+
_remove_xml_id_account_fiscal_position(env)

0 commit comments

Comments
 (0)