Skip to content

Commit 3e483a4

Browse files
authored
Merge pull request #5465 from royle-vietnam/v17_imp_account_oca
[PERF] account: optimize migration performance by pre-creating column and bulk transferring invoice_date
2 parents 7b0ce92 + 4a07782 commit 3e483a4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

openupgrade_scripts/scripts/account/17.0.1.2/pre-migration.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ def _pre_create_early_pay_discount_computation(env):
195195
)
196196

197197

198+
def _pre_account_move_line_invoice_date_computation(env):
199+
"""Avoid triggering the computed method"""
200+
openupgrade.logged_query(
201+
env.cr,
202+
"""
203+
ALTER TABLE account_move_line
204+
ADD COLUMN IF NOT EXISTS invoice_date DATE;
205+
""",
206+
)
207+
openupgrade.logged_query(
208+
env.cr,
209+
"""
210+
UPDATE account_move_line aml
211+
SET invoice_date = am.invoice_date
212+
FROM account_move am
213+
WHERE am.invoice_date IS NOT NULL AND aml.move_id = am.id;
214+
""",
215+
)
216+
217+
198218
def _decouple_obsolete_tables(env):
199219
"""
200220
Remove all foreign keys held by and pointed to template tables
@@ -280,6 +300,7 @@ def migrate(env, version):
280300
_account_report_update_figure_type(env)
281301
_account_tax_repartition_line_merge_repartition_lines_m2o(env)
282302
_pre_create_early_pay_discount_computation(env)
303+
_pre_account_move_line_invoice_date_computation(env)
283304
_decouple_obsolete_tables(env)
284305
_pre_create_account_report_active(env)
285306
_remove_obsolete_constraints(env)

openupgrade_scripts/scripts/account/17.0.1.2/upgrade_analysis_work.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ account / account.move.line / display_type (selection) : select
167167
# NOTHING TO DO: new feature "Discount allocation" https://github.com/odoo/odoo/pull/133286
168168

169169
account / account.move.line / invoice_date (date) : NEW isrelated: related, stored
170-
# NOTHING TO DO: ORM resolves by SQL this filling being a direct related field with 1 level depth.
170+
# DONE: pre-migration: Pre-create the column for avoiding triggering the compute and transfer data from account moves to all the account move lines.
171171

172172
account / account.move.line / tax_audit (char) : DEL
173173
# NOTHING TO DO: deprecated

0 commit comments

Comments
 (0)