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.
Files changed (16) hide show
  1. odoo/addons/openupgrade_scripts/apriori.py +2 -0
  2. odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/noupdate_changes_work.xml +157 -0
  3. odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/post-migration.py +544 -0
  4. odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py +291 -0
  5. odoo/addons/openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt +498 -0
  6. odoo/addons/openupgrade_scripts/scripts/account/tests/data_account_migration.py +20 -0
  7. odoo/addons/openupgrade_scripts/scripts/account/tests/test_account_migration.py +34 -0
  8. odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/post-migration.py +90 -0
  9. odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py +43 -0
  10. odoo/addons/openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt +163 -0
  11. odoo/addons/openupgrade_scripts/scripts/stock/tests/data_stock_migration.py +16 -0
  12. odoo/addons/openupgrade_scripts/scripts/stock/tests/test_stock_migration.py +31 -0
  13. {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
  14. {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
  15. {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
  16. {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,291 @@
1
+ # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2
+ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3
+ from openupgradelib import openupgrade
4
+
5
+ from odoo.tools.sql import convert_column_translatable
6
+
7
+ _fields_renames = [
8
+ (
9
+ "res.company",
10
+ "res_company",
11
+ "invoice_is_print",
12
+ "invoice_is_download",
13
+ ),
14
+ ]
15
+
16
+ _l10n_generic_coa_tax_group_xmlid = [
17
+ "l10n_generic_coa.tax_group_15",
18
+ ]
19
+
20
+ _l10n_generic_coa_tax_xmlid = [
21
+ "l10n_generic_coa.sale_tax_template",
22
+ "l10n_generic_coa.purchase_tax_template",
23
+ ]
24
+
25
+
26
+ def _map_account_report_filter_account_type(env):
27
+ openupgrade.rename_columns(
28
+ env.cr, {"account_report": [("filter_account_type", None)]}
29
+ )
30
+ openupgrade.logged_query(
31
+ env.cr,
32
+ """
33
+ ALTER TABLE account_report
34
+ ADD COLUMN filter_account_type character varying;
35
+ """,
36
+ )
37
+ openupgrade.logged_query(
38
+ env.cr,
39
+ f"""
40
+ UPDATE account_report
41
+ SET filter_account_type = CASE
42
+ WHEN {openupgrade.get_legacy_name('filter_account_type')} THEN 'both'
43
+ ELSE 'disabled'
44
+ END
45
+ """,
46
+ )
47
+
48
+
49
+ def _generic_coa_rename_xml_id(env):
50
+ """
51
+ Since the removal of account.chart.template
52
+ we need to rename some xml_id like tax or tax.group
53
+ in order to avoid duplication
54
+ """
55
+ _dummy, template_id = env["ir.model.data"]._xmlid_to_res_model_res_id(
56
+ "l10n_generic_coa.configurable_chart_template",
57
+ )
58
+ if not template_id:
59
+ return
60
+ env.cr.execute(
61
+ f"""
62
+ SELECT id FROM res_company
63
+ WHERE chart_template_id={template_id}
64
+ """
65
+ )
66
+ xmlids_renames = []
67
+ for (company_id,) in env.cr.fetchall():
68
+ for tax_group_xmlid in _l10n_generic_coa_tax_group_xmlid:
69
+ new_xmlid = f"account.{company_id}_" + tax_group_xmlid.split(".")[1]
70
+ xmlids_renames.append((tax_group_xmlid, new_xmlid))
71
+ for tax_xmlid in _l10n_generic_coa_tax_xmlid:
72
+ old_xmlid = f"l10n_generic_coa.{company_id}_" + tax_xmlid.split(".")[1]
73
+ new_xmlid = f"account.{company_id}_" + tax_xmlid.split(".")[1]
74
+ xmlids_renames.append((old_xmlid, new_xmlid))
75
+ openupgrade.rename_xmlids(env.cr, xmlids_renames)
76
+
77
+
78
+ def _convert_account_tax_description(env):
79
+ openupgrade.rename_columns(
80
+ env.cr, {"account_tax": [("description", "invoice_label")]}
81
+ )
82
+ convert_column_translatable(env.cr, "account_tax", "invoice_label", "jsonb")
83
+
84
+
85
+ def _am_create_delivery_date_column(env):
86
+ """
87
+ Create column then in module need them like l10n_de and sale_stock will fill value,
88
+ https://github.com/odoo/odoo/pull/116643
89
+ """
90
+ openupgrade.logged_query(
91
+ env.cr,
92
+ """
93
+ ALTER TABLE account_move
94
+ ADD COLUMN IF NOT EXISTS delivery_date DATE
95
+ """,
96
+ )
97
+
98
+
99
+ def _am_create_incoterm_location_column(env):
100
+ """
101
+ Create column then in sale_stock and purchase_stock will fill it in pre,
102
+ pr: https://github.com/odoo/odoo/pull/118954
103
+ """
104
+ openupgrade.logged_query(
105
+ env.cr,
106
+ """
107
+ ALTER TABLE account_move
108
+ ADD COLUMN IF NOT EXISTS incoterm_location CHARACTER VARYING
109
+ """,
110
+ )
111
+
112
+
113
+ def _am_uniquify_name(env):
114
+ """
115
+ Make move names unique per journal to satisfy the constraint v17 creates
116
+ """
117
+ openupgrade.logged_query(
118
+ env.cr,
119
+ """
120
+ UPDATE account_move SET name=name || ' [' || id || ']'
121
+ FROM (
122
+ SELECT array_agg(id) ids FROM account_move
123
+ GROUP BY journal_id, name HAVING COUNT(id)>1
124
+ ) duplicate_names
125
+ WHERE account_move.id=ANY(duplicate_names.ids);
126
+ """,
127
+ )
128
+
129
+
130
+ def _account_report_update_figure_type(env):
131
+ openupgrade.copy_columns(
132
+ env.cr,
133
+ {
134
+ "account_report_column": [("figure_type", None, None)],
135
+ "account_report_expression": [("figure_type", None, None)],
136
+ },
137
+ )
138
+ old_column = openupgrade.get_legacy_name("figure_type")
139
+ openupgrade.map_values(
140
+ env.cr,
141
+ old_column,
142
+ "figure_type",
143
+ [("none", "string")],
144
+ False,
145
+ "account_report_column",
146
+ )
147
+ openupgrade.map_values(
148
+ env.cr,
149
+ old_column,
150
+ "figure_type",
151
+ [("none", "string")],
152
+ False,
153
+ "account_report_expression",
154
+ )
155
+
156
+
157
+ def _account_tax_repartition_line_merge_repartition_lines_m2o(env):
158
+ openupgrade.logged_query(
159
+ env.cr,
160
+ """
161
+ ALTER TABLE account_tax_repartition_line
162
+ ADD COLUMN IF NOT EXISTS document_type VARCHAR,
163
+ ADD COLUMN IF NOT EXISTS tax_id INTEGER;
164
+ """,
165
+ )
166
+ openupgrade.logged_query(
167
+ env.cr,
168
+ """
169
+ UPDATE account_tax_repartition_line
170
+ SET document_type = CASE
171
+ WHEN invoice_tax_id IS NOT NULL THEN 'invoice'
172
+ WHEN refund_tax_id IS NOT NULL THEN 'refund'
173
+ END,
174
+ tax_id = CASE
175
+ WHEN invoice_tax_id IS NOT NULL THEN invoice_tax_id
176
+ WHEN refund_tax_id IS NOT NULL THEN refund_tax_id
177
+ END
178
+ """,
179
+ )
180
+
181
+
182
+ def _pre_create_early_pay_discount_computation(env):
183
+ """Avoid triggering the computed method and fill the corresponding value from
184
+ companies.
185
+ """
186
+ openupgrade.logged_query(
187
+ env.cr,
188
+ """
189
+ ALTER TABLE account_payment_term
190
+ ADD COLUMN IF NOT EXISTS early_pay_discount_computation VARCHAR
191
+ """,
192
+ )
193
+ openupgrade.logged_query(
194
+ env.cr,
195
+ """
196
+ UPDATE account_payment_term apt
197
+ SET early_pay_discount_computation = rc.early_pay_discount_computation
198
+ FROM res_company rc
199
+ WHERE apt.company_id = rc.id
200
+ AND apt.early_pay_discount_computation IS NULL
201
+ AND rc.early_pay_discount_computation IS NOT NULL
202
+ """,
203
+ )
204
+
205
+
206
+ def _decouple_obsolete_tables(env):
207
+ """
208
+ Remove all foreign keys held by and pointed to template tables
209
+ """
210
+ obsolete_tables = [
211
+ "account_account_template",
212
+ "account_fiscal_position_account_template",
213
+ "account_fiscal_position_tax_template",
214
+ "account_fiscal_position_template",
215
+ "account_group_template",
216
+ "account_reconcile_model_line_template",
217
+ "account_reconcile_model_template",
218
+ "account_tax_repartition_line_template",
219
+ "account_tax_template",
220
+ ]
221
+ openupgrade.remove_tables_fks(env.cr, obsolete_tables)
222
+ env.cr.execute(
223
+ """
224
+ SELECT tc.table_name, tc.constraint_name
225
+ FROM information_schema.table_constraints tc
226
+ JOIN information_schema.constraint_table_usage ctu
227
+ ON tc.constraint_name=ctu.constraint_name
228
+ WHERE ctu.table_name in %s
229
+ AND tc.constraint_type='FOREIGN KEY'
230
+ """,
231
+ (tuple(obsolete_tables),),
232
+ )
233
+ for table, constraint in env.cr.fetchall():
234
+ openupgrade.logged_query(
235
+ env.cr, f"ALTER TABLE {table} DROP CONSTRAINT {constraint}"
236
+ )
237
+
238
+
239
+ def _pre_create_account_report_active(env):
240
+ """
241
+ Precreate column with default value true, then switch back to false
242
+ """
243
+ env.cr.execute(
244
+ """
245
+ ALTER TABLE account_report ADD COLUMN active boolean DEFAULT true
246
+ """
247
+ )
248
+ env.cr.execute(
249
+ """
250
+ ALTER TABLE account_report ALTER COLUMN active SET DEFAULT false
251
+ """
252
+ )
253
+
254
+
255
+ def _remove_obsolete_constraints(env):
256
+ """
257
+ Remove constraints that will be deleted at the end of the migration
258
+ """
259
+ table2constraints = {
260
+ "account_account": ["code_company_uniq"],
261
+ "account_fiscal_position_account": ["account_src_dest_uniq"],
262
+ "account_tax": ["name_company_uniq", "template_name_company_uniq"],
263
+ }
264
+ for table, constraints in table2constraints.items():
265
+ for constraint in constraints:
266
+ openupgrade.delete_sql_constraint_safely(env, "account", table, constraint)
267
+
268
+
269
+ @openupgrade.migrate()
270
+ def migrate(env, version):
271
+ _map_account_report_filter_account_type(env)
272
+ _generic_coa_rename_xml_id(env)
273
+ # Drop triagram index on name column of account.account
274
+ # to avoid error when loading registry, it will be recreated
275
+ openupgrade.logged_query(
276
+ env.cr,
277
+ """
278
+ DROP INDEX IF EXISTS account_account_name_index;
279
+ """,
280
+ )
281
+ openupgrade.rename_fields(env, _fields_renames)
282
+ _convert_account_tax_description(env)
283
+ _am_create_delivery_date_column(env)
284
+ _am_create_incoterm_location_column(env)
285
+ _am_uniquify_name(env)
286
+ _account_report_update_figure_type(env)
287
+ _account_tax_repartition_line_merge_repartition_lines_m2o(env)
288
+ _pre_create_early_pay_discount_computation(env)
289
+ _decouple_obsolete_tables(env)
290
+ _pre_create_account_report_active(env)
291
+ _remove_obsolete_constraints(env)