forked from OCA/l10n-italy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.py
132 lines (119 loc) · 3.09 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright 2023 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade
from openupgradelib.openupgrade import logged_query
from odoo.tools import DotDict
NEW_MODULE_NAME = "l10n_it_financial_statements_report"
OLD_MODULE_NAME = "l10n_it_account_balance_report"
REMOVED_MODELS = [
"report_trial_balance_account",
"account_balance_report_partner",
"account_balance_report_account",
]
RENAMED_MODELS = [
(
"account_balance_report",
"report.l10n_it_financial_statements_report.report",
),
(
"report.l10n_it_a_b_r.account_balance_report_xlsx",
"report.l10n_it_financial_statements_report.report_xlsx",
),
]
RENAMED_FIELDS = [
(
"account.account.type",
"account_account_type",
"account_balance_report_section",
"financial_statements_report_section",
),
]
RENAMED_XMLIDS = [
(
"template_account_balance_report",
"template_financial_statements_report",
),
(
"account_balance_report",
"report",
),
(
"account_balance_report_base",
"financial_statements_report_base",
),
(
"account_balance_report_title",
"financial_statements_report_title",
),
(
"account_balance_report_filters",
"financial_statements_report_filters",
),
(
"account_balance_report_split_columns",
"financial_statements_report_split_columns",
),
(
"account_balance_report_lines_header",
"financial_statements_report_lines_header",
),
(
"account_balance_report_lines",
"financial_statements_report_lines",
),
(
"account_balance_report_partners",
"financial_statements_report_partners",
),
(
"account_balance_report_totals",
"financial_statements_report_totals",
),
]
def remove_models(cr, model_spec):
for name in model_spec:
logged_query(
cr,
"DELETE FROM ir_model WHERE model = %s",
(name,),
)
def migrate_old_module(cr):
remove_models(
cr,
REMOVED_MODELS,
)
openupgrade.rename_models(
cr,
RENAMED_MODELS,
)
openupgrade.rename_fields(
# The method only needs the cursor, not the whole Environment
DotDict(
cr=cr,
),
RENAMED_FIELDS,
# Prevent Environment usage
# whenever it will be implemented.
no_deep=True,
)
full_renamed_xmlids = [
(
".".join((NEW_MODULE_NAME, old_xmlid)),
".".join((NEW_MODULE_NAME, new_xmlid)),
)
for old_xmlid, new_xmlid in RENAMED_XMLIDS
]
openupgrade.rename_xmlids(
cr,
full_renamed_xmlids,
)
def pre_absorb_old_module(cr):
if openupgrade.is_module_installed(cr, OLD_MODULE_NAME):
openupgrade.update_module_names(
cr,
[
(OLD_MODULE_NAME, NEW_MODULE_NAME),
],
merge_modules=True,
)
migrate_old_module(cr)