odoo-addon-openupgrade-scripts 17.0.1.0.1.75__py3-none-any.whl → 17.0.1.0.1.85__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odoo/addons/openupgrade_scripts/apriori.py +2 -0
- odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml +157 -0
- odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py +544 -0
- odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py +291 -0
- odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt +498 -0
- odoo/addons/openupgrade_scripts/scripts/account/tests/data_account_migration.py +20 -0
- odoo/addons/openupgrade_scripts/scripts/account/tests/test_account_migration.py +34 -0
- odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/post-migration.py +90 -0
- odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py +43 -0
- odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt +163 -0
- odoo/addons/openupgrade_scripts/scripts/stock/tests/data_stock_migration.py +16 -0
- odoo/addons/openupgrade_scripts/scripts/stock/tests/test_stock_migration.py +31 -0
- {odoo_addon_openupgrade_scripts-17.0.1.0.1.75.dist-info → odoo_addon_openupgrade_scripts-17.0.1.0.1.85.dist-info}/METADATA +1 -1
- {odoo_addon_openupgrade_scripts-17.0.1.0.1.75.dist-info → odoo_addon_openupgrade_scripts-17.0.1.0.1.85.dist-info}/RECORD +16 -5
- {odoo_addon_openupgrade_scripts-17.0.1.0.1.75.dist-info → odoo_addon_openupgrade_scripts-17.0.1.0.1.85.dist-info}/WHEEL +0 -0
- {odoo_addon_openupgrade_scripts-17.0.1.0.1.75.dist-info → odoo_addon_openupgrade_scripts-17.0.1.0.1.85.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,544 @@
|
|
1
|
+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
|
2
|
+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
3
|
+
|
4
|
+
from openupgradelib import openupgrade
|
5
|
+
|
6
|
+
from odoo.addons.base.models.ir_property import TYPE2FIELD as ir_property_TYPE2FIELD
|
7
|
+
|
8
|
+
_deleted_xml_records = [
|
9
|
+
"account.tax_group_taxes",
|
10
|
+
"account.account_invoice_send_rule_group_invoice",
|
11
|
+
"account.sequence_reconcile_seq",
|
12
|
+
]
|
13
|
+
|
14
|
+
|
15
|
+
COA_MAPPING = {
|
16
|
+
"l10n_ae.uae_chart_template_standard": "ae",
|
17
|
+
"l10n_ar.l10nar_base_chart_template": "ar_base",
|
18
|
+
"l10n_ar.l10nar_ex_chart_template": "ar_ex",
|
19
|
+
"l10n_ar.l10nar_ri_chart_template": "ar_ri",
|
20
|
+
"l10n_at.l10n_at_chart_template": "at",
|
21
|
+
"l10n_au.l10n_au_chart_template": "au",
|
22
|
+
"l10n_be.l10nbe_chart_template": "be_comp",
|
23
|
+
"l10n_bg.l10n_bg_chart_template": "bg",
|
24
|
+
"l10n_bo.bo_chart_template": "bo",
|
25
|
+
"l10n_br.l10n_br_account_chart_template": "br",
|
26
|
+
"l10n_ca.ca_en_chart_template_en": "ca_2023",
|
27
|
+
"l10n_ch.l10nch_chart_template": "ch",
|
28
|
+
"l10n_cl.cl_chart_template": "cl",
|
29
|
+
"l10n_cn.l10n_chart_china_small_business": "cn",
|
30
|
+
"l10n_co.l10n_co_chart_template_generic": "co",
|
31
|
+
"l10n_cr.account_chart_template_0": "cr",
|
32
|
+
"l10n_cz.cz_chart_template": "cz",
|
33
|
+
"l10n_de.l10n_de_chart_template": "de_skr03",
|
34
|
+
"l10n_de.l10n_chart_de_skr04": "de_skr04",
|
35
|
+
"l10n_de_skr03.l10n_de_chart_template": "de_skr03",
|
36
|
+
"l10n_de_skr04.l10n_chart_de_skr04": "de_skr04",
|
37
|
+
"l10n_dk.dk_chart_template": "dk",
|
38
|
+
"l10n_do.do_chart_template": "do",
|
39
|
+
"l10n_dz.l10n_dz_pcg_chart_template": "dz",
|
40
|
+
"l10n_ec.l10n_ec_ifrs": "ec",
|
41
|
+
"l10n_ee.l10nee_chart_template": "ee",
|
42
|
+
"l10n_eg.egypt_chart_template_standard": "eg",
|
43
|
+
"l10n_es.account_chart_template_assoc": "es_assec",
|
44
|
+
"l10n_es.account_chart_template_common": "es_common",
|
45
|
+
"l10n_es.account_chart_template_full": "es_full",
|
46
|
+
"l10n_es.account_chart_template_pymes": "es_pymes",
|
47
|
+
"l10n_et.l10n_et": "et",
|
48
|
+
"l10n_fi.fi_chart_template": "fi",
|
49
|
+
"l10n_fr.l10n_fr_pcg_chart_template": "fr",
|
50
|
+
"l10n_generic_coa.configurable_chart_template": "generic_coa",
|
51
|
+
"l10n_gr.l10n_gr_chart_template": "gr",
|
52
|
+
"l10n_gt.cuentas_plantilla": "gt",
|
53
|
+
"l10n_hk.l10n_hk_chart_template": "hk",
|
54
|
+
"l10n_hn.cuentas_plantilla": "hn",
|
55
|
+
"l10n_hr.l10n_hr_chart_template_rrif": "hr",
|
56
|
+
"l10n_hr.l10n_hr_euro_chart_template": "hr",
|
57
|
+
"l10n_hr_kuna.l10n_hr_kuna_chart_template_rrif": "hr_kuna",
|
58
|
+
"l10n_hu.hungarian_chart_template": "hu",
|
59
|
+
"l10n_id.l10n_id_chart": "id",
|
60
|
+
"l10n_ie.l10n_ie": "ie",
|
61
|
+
"l10n_il.il_chart_template": "il",
|
62
|
+
"l10n_in.indian_chart_template_standard": "in",
|
63
|
+
"l10n_it.l10n_it_chart_template_generic": "it",
|
64
|
+
"l10n_jp.l10n_jp1": "jp",
|
65
|
+
"l10n_jp.l10n_jp_chart_template": "jp",
|
66
|
+
"l10n_ke.l10nke_chart_template": "ke",
|
67
|
+
"l10n_kz.l10nkz_chart_template": "kz",
|
68
|
+
"l10n_lt.account_chart_template_lithuania": "lt",
|
69
|
+
"l10n_lu.lu_2011_chart_1": "lu",
|
70
|
+
"l10n_lv.chart_template_latvia": "lv",
|
71
|
+
"l10n_ma.l10n_ma_chart_template": "ma",
|
72
|
+
"l10n_mn.mn_chart_1": "mn",
|
73
|
+
"l10n_mx.mx_coa": "mx",
|
74
|
+
"l10n_my.l10n_my_chart_template": "my",
|
75
|
+
"l10n_mz.l10n_mz_chart_template": "mz",
|
76
|
+
"l10n_nl.l10nnl_chart_template": "nl",
|
77
|
+
"l10n_no.no_chart_template": "no",
|
78
|
+
"l10n_nz.l10n_nz_chart_template": "nz",
|
79
|
+
"l10n_pa.l10npa_chart_template": "pa",
|
80
|
+
"l10n_pe.pe_chart_template": "pe",
|
81
|
+
"l10n_ph.l10n_ph_chart_template": "ph",
|
82
|
+
"l10n_pk.l10n_pk_chart_template": "pk",
|
83
|
+
"l10n_pl.pl_chart_template": "pl",
|
84
|
+
"l10n_pt.pt_chart_template": "pt",
|
85
|
+
"l10n_ro.ro_chart_template": "ro",
|
86
|
+
"l10n_rs.l10n_rs_chart_template": "rs",
|
87
|
+
"l10n_sa.sa_chart_template_standard": "sa",
|
88
|
+
"l10n_se.l10nse_chart_template": "se",
|
89
|
+
"l10n_se.l10nse_chart_template_K2": "se_K2",
|
90
|
+
"l10n_se.l10nse_chart_template_K3": "se_K3",
|
91
|
+
"l10n_sg.sg_chart_template": "sg",
|
92
|
+
"l10n_si.gd_chart": "si",
|
93
|
+
"l10n_sk.sk_chart_template": "sk",
|
94
|
+
"l10n_syscohada.syscohada_chart_template": "syscohada",
|
95
|
+
"l10n_th.chart": "th",
|
96
|
+
"l10n_tr.chart_template_common": "tr",
|
97
|
+
"l10n_tr.l10n_tr_chart_template": "tr",
|
98
|
+
"l10n_tw.l10n_tw_chart_template": "tw",
|
99
|
+
"l10n_ua.l10n_ua_ias_chart_template": "ua_ias",
|
100
|
+
"l10n_ua.l10n_ua_psbo_chart_template": "ua_psbo",
|
101
|
+
"l10n_uk.l10n_uk": "uk",
|
102
|
+
"l10n_uy.uy_chart_template": "uy",
|
103
|
+
"l10n_ve.ve_chart_template_amd": "ve",
|
104
|
+
"l10n_vn.vn_template": "vn",
|
105
|
+
"l10n_za.default_chart_template": "za",
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
def _am_update_invoice_pdf_report_file(env):
|
110
|
+
openupgrade.logged_query(
|
111
|
+
env.cr,
|
112
|
+
"""
|
113
|
+
UPDATE ir_attachment ia
|
114
|
+
SET res_field = 'invoice_pdf_report_file',
|
115
|
+
res_id = am.id
|
116
|
+
FROM account_move am
|
117
|
+
WHERE am.message_main_attachment_id = ia.id
|
118
|
+
""",
|
119
|
+
)
|
120
|
+
|
121
|
+
|
122
|
+
def _onboarding_state_migration(env):
|
123
|
+
"""
|
124
|
+
Following pr: https://github.com/odoo/odoo/pull/104223/
|
125
|
+
"""
|
126
|
+
env.cr.execute(
|
127
|
+
"""
|
128
|
+
SELECT id, account_onboarding_create_invoice_state_flag,
|
129
|
+
account_onboarding_invoice_layout_state,
|
130
|
+
account_onboarding_sale_tax_state, account_setup_bank_data_state,
|
131
|
+
account_setup_bill_state, account_setup_coa_state, account_setup_fy_data_state,
|
132
|
+
account_setup_taxes_state FROM res_company
|
133
|
+
"""
|
134
|
+
)
|
135
|
+
for (
|
136
|
+
company_id,
|
137
|
+
account_onboarding_create_invoice_state_flag,
|
138
|
+
account_onboarding_invoice_layout_state,
|
139
|
+
account_onboarding_sale_tax_state,
|
140
|
+
account_setup_bank_data_state,
|
141
|
+
account_setup_bill_state,
|
142
|
+
account_setup_coa_state,
|
143
|
+
account_setup_fy_data_state,
|
144
|
+
account_setup_taxes_state,
|
145
|
+
) in env.cr.fetchall():
|
146
|
+
OnboardingStep = env["onboarding.onboarding.step"].with_company(company_id)
|
147
|
+
company = env["res.company"].browse(company_id)
|
148
|
+
if company.street and company.street.strip():
|
149
|
+
# Same behaviour for this base setup company data in v16
|
150
|
+
# Check method 'action_save_onboarding_company_step' in v16
|
151
|
+
# Note in v17 you only need to save it then it will be done
|
152
|
+
OnboardingStep.action_validate_step(
|
153
|
+
"account.onboarding_onboarding_step_company_data"
|
154
|
+
)
|
155
|
+
if account_onboarding_create_invoice_state_flag:
|
156
|
+
step = env.ref(
|
157
|
+
"account.onboarding_onboarding_step_create_invoice",
|
158
|
+
raise_if_not_found=False,
|
159
|
+
)
|
160
|
+
if step and step.current_step_state == "not_done":
|
161
|
+
if env["account.move"].search(
|
162
|
+
[
|
163
|
+
("company_id", "=", company_id),
|
164
|
+
("move_type", "=", "out_invoice"),
|
165
|
+
],
|
166
|
+
limit=1,
|
167
|
+
):
|
168
|
+
step.with_company(company_id).action_set_just_done()
|
169
|
+
if account_onboarding_invoice_layout_state in ("just_done", "done"):
|
170
|
+
step = env.ref(
|
171
|
+
"account.onboarding_onboarding_step_base_document_layout",
|
172
|
+
raise_if_not_found=False,
|
173
|
+
)
|
174
|
+
if step:
|
175
|
+
step.with_company(company_id).action_set_just_done()
|
176
|
+
if account_onboarding_sale_tax_state in ("just_done", "done"):
|
177
|
+
OnboardingStep.action_validate_step(
|
178
|
+
"account.onboarding_onboarding_step_sales_tax"
|
179
|
+
)
|
180
|
+
if account_setup_bank_data_state in ("just_done", "done"):
|
181
|
+
OnboardingStep.action_validate_step(
|
182
|
+
"account.onboarding_onboarding_step_bank_account"
|
183
|
+
)
|
184
|
+
if account_setup_bill_state in ("just_done", "done"):
|
185
|
+
OnboardingStep.action_validate_step(
|
186
|
+
"account.onboarding_onboarding_step_setup_bill"
|
187
|
+
)
|
188
|
+
if account_setup_coa_state in ("just_done", "done"):
|
189
|
+
OnboardingStep.action_validate_step(
|
190
|
+
"account.onboarding_onboarding_step_chart_of_accounts"
|
191
|
+
)
|
192
|
+
if account_setup_fy_data_state in ("just_done", "done"):
|
193
|
+
OnboardingStep.action_validate_step(
|
194
|
+
"account.onboarding_onboarding_step_fiscal_year"
|
195
|
+
)
|
196
|
+
if account_setup_taxes_state in ("just_done", "done"):
|
197
|
+
OnboardingStep.action_validate_step(
|
198
|
+
"account.onboarding_onboarding_step_default_taxes"
|
199
|
+
)
|
200
|
+
|
201
|
+
|
202
|
+
def _account_payment_term_migration(env):
|
203
|
+
"""
|
204
|
+
Switch balance lines to percent and compute the remaining percentage, and convert
|
205
|
+
old multiple column system to the new delay_type + nb_days.
|
206
|
+
|
207
|
+
https://github.com/odoo/odoo/pull/110274
|
208
|
+
"""
|
209
|
+
openupgrade.logged_query(
|
210
|
+
env.cr,
|
211
|
+
"""
|
212
|
+
UPDATE account_payment_term_line
|
213
|
+
SET value = 'percent',
|
214
|
+
value_amount = 100.0 - COALESCE(percentages.percentage, 0)
|
215
|
+
FROM (
|
216
|
+
SELECT
|
217
|
+
payment_id,
|
218
|
+
SUM(
|
219
|
+
CASE WHEN l.value='percent' THEN l.value_amount
|
220
|
+
ELSE 0 END
|
221
|
+
) percentage
|
222
|
+
FROM account_payment_term_line l
|
223
|
+
GROUP BY payment_id
|
224
|
+
) percentages
|
225
|
+
WHERE
|
226
|
+
value = 'balance' AND
|
227
|
+
percentages.payment_id = account_payment_term_line.payment_id
|
228
|
+
""",
|
229
|
+
)
|
230
|
+
openupgrade.logged_query(
|
231
|
+
env.cr,
|
232
|
+
"""
|
233
|
+
UPDATE account_payment_term_line
|
234
|
+
SET delay_type = CASE
|
235
|
+
WHEN end_month AND COALESCE(months, 0) = 0
|
236
|
+
AND COALESCE(days, 0) = 0
|
237
|
+
THEN 'days_after_end_of_month'
|
238
|
+
WHEN end_month AND months = 1 AND COALESCE(days, 0) = 0
|
239
|
+
THEN 'days_after_end_of_next_month'
|
240
|
+
WHEN end_month AND COALESCE(months, 0) <= 1 AND days > 0
|
241
|
+
THEN 'days_end_of_month_on_the'
|
242
|
+
ELSE 'days_after'
|
243
|
+
END,
|
244
|
+
nb_days = CASE
|
245
|
+
WHEN end_month AND months <= 1
|
246
|
+
THEN COALESCE(days, 0) + COALESCE(days_after, 0)
|
247
|
+
ELSE
|
248
|
+
COALESCE(months, 0)*30 + COALESCE(days, 0) +
|
249
|
+
COALESCE(days_after, 0)
|
250
|
+
END
|
251
|
+
""",
|
252
|
+
)
|
253
|
+
|
254
|
+
|
255
|
+
def _account_payment_term_early_payment_discount(env):
|
256
|
+
"""Only payment terms with one line and the early payment discount activated are
|
257
|
+
valid now, so we are going to discard other previous configurations.
|
258
|
+
"""
|
259
|
+
openupgrade.logged_query(
|
260
|
+
env.cr,
|
261
|
+
"""
|
262
|
+
WITH sub AS (
|
263
|
+
SELECT * FROM (
|
264
|
+
SELECT *,
|
265
|
+
row_number() over (partition BY payment_id ORDER BY id) AS rnum
|
266
|
+
FROM account_payment_term_line
|
267
|
+
) t
|
268
|
+
WHERE t.rnum = 1
|
269
|
+
AND t.discount_days IS NOT NULL
|
270
|
+
AND t.discount_percentage > 0
|
271
|
+
)
|
272
|
+
UPDATE account_payment_term apt
|
273
|
+
SET early_discount = True,
|
274
|
+
discount_days = sub.discount_days,
|
275
|
+
discount_percentage = sub.discount_percentage
|
276
|
+
FROM sub
|
277
|
+
WHERE sub.payment_id = apt.id
|
278
|
+
""",
|
279
|
+
)
|
280
|
+
|
281
|
+
|
282
|
+
def convert_from_company_dependent(
|
283
|
+
env,
|
284
|
+
model_name,
|
285
|
+
origin_field_name,
|
286
|
+
destination_field_name,
|
287
|
+
origin_id_column_name,
|
288
|
+
model_table_name=None,
|
289
|
+
):
|
290
|
+
"""
|
291
|
+
Move a company-dependent field back to the model table.
|
292
|
+
|
293
|
+
The usual setting is: A model didn't have a company_id field in version
|
294
|
+
(n-1), but got company-aware in version (n). Then company-dependent fields
|
295
|
+
don't make sense, and are replaced with plain database columns.
|
296
|
+
|
297
|
+
You're responsible for duplicating records for all companies in whatever way
|
298
|
+
makes sense for the model before calling this function, and link the
|
299
|
+
duplicate to the original record in column `origin_id_column_name`, which
|
300
|
+
you have to create yourself beforehand.
|
301
|
+
|
302
|
+
:param model_name: Name of the model.
|
303
|
+
:param origin_field_name: Name of the company-dependent field
|
304
|
+
:param destination_field_name: Name of plain field
|
305
|
+
:param origin_id_column_name: Name of the column you created to link record
|
306
|
+
duplicates to the record they were duplicated from
|
307
|
+
:param model_table_name: Name of the table. Optional. If not provided
|
308
|
+
the table name is taken from the model (so the model must be
|
309
|
+
registered previously).
|
310
|
+
"""
|
311
|
+
# If you want to recycle this function for your own migration, better
|
312
|
+
# add it to openupgradelib
|
313
|
+
table_name = model_table_name or env[model_name]._table
|
314
|
+
|
315
|
+
env.cr.execute(
|
316
|
+
"SELECT id, ttype FROM ir_model_fields "
|
317
|
+
f"WHERE model='{model_name}' AND name='{origin_field_name}'"
|
318
|
+
)
|
319
|
+
field_id, field_type = env.cr.fetchone()
|
320
|
+
|
321
|
+
value_expression = ir_property_TYPE2FIELD.get(field_type)
|
322
|
+
if value_expression == "value_reference":
|
323
|
+
value_expression = "SPLIT_PART(ip.value_reference, ',', 2)::integer"
|
324
|
+
|
325
|
+
return openupgrade.logged_query(
|
326
|
+
env.cr,
|
327
|
+
f"""
|
328
|
+
UPDATE {table_name}
|
329
|
+
SET {destination_field_name} = (
|
330
|
+
SELECT {value_expression}
|
331
|
+
FROM ir_property ip
|
332
|
+
WHERE ip.fields_id={field_id} --- {origin_field_name}
|
333
|
+
AND (
|
334
|
+
ip.res_id = '{model_name}.' || COALESCE(
|
335
|
+
{table_name}.{origin_id_column_name}, {table_name}.id
|
336
|
+
)
|
337
|
+
OR ip.res_id IS NULL
|
338
|
+
)
|
339
|
+
AND (
|
340
|
+
ip.company_id = {table_name}.company_id
|
341
|
+
OR ip.company_id IS NULL
|
342
|
+
)
|
343
|
+
ORDER BY ip.company_id NULLS LAST, ip.res_id NULLS LAST
|
344
|
+
LIMIT 1
|
345
|
+
)
|
346
|
+
""",
|
347
|
+
)
|
348
|
+
|
349
|
+
|
350
|
+
def _account_tax_group_migration(env):
|
351
|
+
"""
|
352
|
+
In v17 tax groups are company-aware (company_id added):
|
353
|
+
|
354
|
+
- Find which tax groups have accounts with different companies,
|
355
|
+
duplicate them for each of that company
|
356
|
+
- Update accounts to point to the newly created groups for their
|
357
|
+
companies
|
358
|
+
- Rename ir model data (xml_id), the format will be
|
359
|
+
"{module_name}.{company_id}_xml_id"
|
360
|
+
- Fill new fields tax_receivable_account_id, tax_payable_account_id,
|
361
|
+
advance_tax_payment_account_id with the value of the properties
|
362
|
+
they replace
|
363
|
+
|
364
|
+
Example in v16:
|
365
|
+
2 VN CoA company: tax 0, tax 5, tax 10
|
366
|
+
2 Generic CoA company tax 15
|
367
|
+
1 Belgium CoA company tax 6, 12, 21
|
368
|
+
|
369
|
+
-> After migration we will have 2 tax 0, 2 tax 5, 2 tax 10
|
370
|
+
and 2 tax 15 of course with only different company_id
|
371
|
+
Also the new one will have their own xml_id using create method
|
372
|
+
of ir.model.data
|
373
|
+
And then in each l10n module, only need to perform rename xml_id like
|
374
|
+
https://github.com/Viindoo/OpenUpgrade/pull/655
|
375
|
+
"""
|
376
|
+
origin_id_column = "original_tax_group_id"
|
377
|
+
openupgrade.logged_query(
|
378
|
+
env.cr,
|
379
|
+
f"""
|
380
|
+
ALTER TABLE account_tax_group
|
381
|
+
ADD COLUMN IF NOT EXISTS {origin_id_column} INTEGER;
|
382
|
+
""",
|
383
|
+
)
|
384
|
+
|
385
|
+
env.cr.execute(
|
386
|
+
"""
|
387
|
+
SELECT tax_group_id, array_agg(DISTINCT(company_id))
|
388
|
+
FROM account_tax
|
389
|
+
GROUP BY tax_group_id
|
390
|
+
HAVING COUNT(DISTINCT company_id) > 1
|
391
|
+
"""
|
392
|
+
)
|
393
|
+
|
394
|
+
for tax_group_id, company_ids in env.cr.fetchall():
|
395
|
+
tax_group = env["account.tax.group"].browse(tax_group_id)
|
396
|
+
first_company_id = min(company_ids)
|
397
|
+
tax_group.company_id = first_company_id
|
398
|
+
|
399
|
+
imd = env["ir.model.data"].search(
|
400
|
+
[("res_id", "=", tax_group.id), ("model", "=", "account.tax.group")],
|
401
|
+
limit=1,
|
402
|
+
)
|
403
|
+
tax_group_name = imd.name
|
404
|
+
imd.write({"name": f"{first_company_id}_{imd.name}"})
|
405
|
+
|
406
|
+
for company_id in company_ids:
|
407
|
+
if company_id == first_company_id:
|
408
|
+
continue
|
409
|
+
new_tax_group = tax_group.copy({"company_id": company_id})
|
410
|
+
|
411
|
+
openupgrade.logged_query(
|
412
|
+
env.cr,
|
413
|
+
f"""
|
414
|
+
UPDATE account_tax_group
|
415
|
+
SET {origin_id_column} = {tax_group.id}
|
416
|
+
WHERE id = {new_tax_group.id}
|
417
|
+
""",
|
418
|
+
)
|
419
|
+
|
420
|
+
if tax_group_name:
|
421
|
+
new_imd = imd.copy({"res_id": new_tax_group.id})
|
422
|
+
new_imd.write({"name": f"{company_id}_{tax_group_name}"})
|
423
|
+
|
424
|
+
openupgrade.logged_query(
|
425
|
+
env.cr,
|
426
|
+
f"""
|
427
|
+
UPDATE account_tax
|
428
|
+
SET tax_group_id = {new_tax_group.id}
|
429
|
+
WHERE tax_group_id = {tax_group.id} AND company_id = {company_id}
|
430
|
+
""",
|
431
|
+
)
|
432
|
+
|
433
|
+
convert_from_company_dependent(
|
434
|
+
env,
|
435
|
+
"account.tax.group",
|
436
|
+
"property_tax_receivable_account_id",
|
437
|
+
"tax_receivable_account_id",
|
438
|
+
origin_id_column,
|
439
|
+
)
|
440
|
+
convert_from_company_dependent(
|
441
|
+
env,
|
442
|
+
"account.tax.group",
|
443
|
+
"property_tax_payable_account_id",
|
444
|
+
"tax_payable_account_id",
|
445
|
+
origin_id_column,
|
446
|
+
)
|
447
|
+
convert_from_company_dependent(
|
448
|
+
env,
|
449
|
+
"account.tax.group",
|
450
|
+
"property_advance_tax_payment_account_id",
|
451
|
+
"advance_tax_payment_account_id",
|
452
|
+
origin_id_column,
|
453
|
+
)
|
454
|
+
|
455
|
+
|
456
|
+
def _force_install_account_payment_term_module_module(env):
|
457
|
+
"""
|
458
|
+
Force install account_payment_term if we need
|
459
|
+
key 'days_end_of_month_on_the' of it
|
460
|
+
it has already merged in odoo master
|
461
|
+
"""
|
462
|
+
account_payment_term_module = env["ir.module.module"].search(
|
463
|
+
[("name", "=", "account_payment_term")], limit=1
|
464
|
+
)
|
465
|
+
needs_account_payment_term = bool(
|
466
|
+
env["account.payment.term.line"].search(
|
467
|
+
[("delay_type", "=", "days_end_of_month_on_the")], limit=1
|
468
|
+
)
|
469
|
+
)
|
470
|
+
if needs_account_payment_term and account_payment_term_module:
|
471
|
+
account_payment_term_module.state = "to install"
|
472
|
+
openupgrade.copy_columns(
|
473
|
+
env.cr,
|
474
|
+
{
|
475
|
+
"account_payment_term_line": [
|
476
|
+
("days_after", "days_next_month", "CHARACTER VARYING")
|
477
|
+
]
|
478
|
+
},
|
479
|
+
)
|
480
|
+
openupgrade.logged_query(
|
481
|
+
env.cr,
|
482
|
+
"""
|
483
|
+
UPDATE account_payment_term_line
|
484
|
+
SET
|
485
|
+
nb_days = nb_days - days_after,
|
486
|
+
days_next_month = days_after
|
487
|
+
WHERE delay_type = 'days_end_of_month_on_the'
|
488
|
+
""",
|
489
|
+
)
|
490
|
+
|
491
|
+
|
492
|
+
def _map_chart_template_id_to_chart_template(
|
493
|
+
env, model_table, coa_m2o="chart_template_id", coa_name_column="chart_template"
|
494
|
+
):
|
495
|
+
"""
|
496
|
+
In tables that used to refer to a chart template in the database, set the new
|
497
|
+
column identitying the COA by the name of its localization module with the
|
498
|
+
`l10n_` prefix removed (usually the country's iso code)
|
499
|
+
"""
|
500
|
+
env.cr.execute(
|
501
|
+
f"""SELECT m.id, CONCAT(imd.module, '.', imd.name)
|
502
|
+
FROM {model_table} m
|
503
|
+
JOIN ir_model_data imd
|
504
|
+
ON imd.model='account.chart.template'
|
505
|
+
AND m.{coa_m2o} = imd.res_id
|
506
|
+
WHERE m.{coa_m2o} IS NOT NULL
|
507
|
+
AND CONCAT(imd.module, '.', imd.name) IN %s
|
508
|
+
""",
|
509
|
+
(tuple(COA_MAPPING),),
|
510
|
+
)
|
511
|
+
chart_id2name = [(_id, COA_MAPPING[xmlid]) for _id, xmlid in env.cr.fetchall()]
|
512
|
+
openupgrade.map_values(
|
513
|
+
env.cr,
|
514
|
+
coa_m2o,
|
515
|
+
coa_name_column,
|
516
|
+
chart_id2name,
|
517
|
+
table=model_table,
|
518
|
+
)
|
519
|
+
|
520
|
+
|
521
|
+
@openupgrade.migrate()
|
522
|
+
def migrate(env, version):
|
523
|
+
_account_payment_term_migration(env)
|
524
|
+
_account_payment_term_early_payment_discount(env)
|
525
|
+
_force_install_account_payment_term_module_module(env)
|
526
|
+
openupgrade.load_data(env, "account", "17.0.1.2/noupdate_changes_work.xml")
|
527
|
+
openupgrade.delete_record_translations(
|
528
|
+
env.cr,
|
529
|
+
"account",
|
530
|
+
(
|
531
|
+
"email_template_edi_credit_note",
|
532
|
+
"email_template_edi_invoice",
|
533
|
+
"mail_template_data_payment_receipt",
|
534
|
+
),
|
535
|
+
)
|
536
|
+
openupgrade.delete_records_safely_by_xml_id(
|
537
|
+
env,
|
538
|
+
_deleted_xml_records,
|
539
|
+
)
|
540
|
+
_am_update_invoice_pdf_report_file(env)
|
541
|
+
_onboarding_state_migration(env)
|
542
|
+
_account_tax_group_migration(env)
|
543
|
+
_map_chart_template_id_to_chart_template(env, "res_company")
|
544
|
+
_map_chart_template_id_to_chart_template(env, "account_report")
|