From 46037edb3a9d897a0538d113847c8167e2841d51 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Chien Date: Tue, 2 Dec 2025 11:04:41 +0700 Subject: [PATCH 1/2] [UPD] foodcoop18: update to make it work with Lalouve db (by Hoang) --- .../account/14.0.1.1/post-migration.py | 10 +++++++-- .../scripts/account/14.0.1.1/pre-migration.py | 16 +++++++------- .../scripts/base/14.0.1.3/pre-migrate.py | 5 +++++ .../mass_mailing/14.0.2.2/pre-migration.py | 21 +++++++++++-------- .../scripts/project/14.0.1.1/pre-migration.py | 12 ++++++----- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py b/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py index 21c3a6079d42..a194b33353fb 100644 --- a/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py @@ -343,7 +343,8 @@ def post_statements(env): # instead, call it one by one. stmts = env["account.bank.statement"].browse(stmt_ids) for stmt in stmts: - stmt.button_post() + # trobz migrate: skip_check_constrains_account_id_journal_id + stmt.with_context(skip_check_constrains_account_id_journal_id=True).button_post() def pass_bank_statement_line_note_to_journal_entry_narration(env): @@ -710,7 +711,8 @@ def fill_account_payment_with_no_move(env): ) deprecated_accounts.deprecated = False try: - payment._synchronize_to_moves( + # trobz migrate: add context skip_check_constrains_account_id_journal_id to skip constraint + payment.with_context(skip_check_constrains_account_id_journal_id=True)._synchronize_to_moves( [ "date", "amount", @@ -930,12 +932,16 @@ def migrate(env, version): try_delete_noupdate_records(env) _create_hooks(env) fill_company_account_journal_suspense_account_id(env) + fill_statement_lines_with_no_move(env) + fill_account_journal_payment_credit_debit_account_id(env) create_new_counterpart_account_payment_transfer(env) map_account_payment_transfer(env) fill_account_payment_reconciliation(env) + fill_account_payment_with_no_move(env) + fill_account_bank_statement_line_reconciliation(env) post_statements(env) _delete_hooks(env) diff --git a/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py index 5dd940fef04e..62b6995d70c7 100644 --- a/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py @@ -677,22 +677,22 @@ def fill_partial_reconcile_currency(env): env.cr, """ UPDATE account_partial_reconcile apr - SET debit_currency_id = COALESCE(aml.currency_id, rc.currency_id) - FROM account_move_line aml, + SET debit_currency_id = COALESCE(am.currency_id, rc.currency_id) + FROM account_move am, res_company rc - WHERE aml.id = apr.debit_move_id - AND rc.id = aml.company_id + WHERE am.id = apr.debit_move_id + AND rc.id = am.company_id """, ) openupgrade.logged_query( env.cr, """ UPDATE account_partial_reconcile apr - SET credit_currency_id = COALESCE(aml.currency_id, rc.currency_id) - FROM account_move_line aml, + SET credit_currency_id = COALESCE(am.currency_id, rc.currency_id) + FROM account_move am, res_company rc - WHERE aml.id = apr.credit_move_id - AND rc.id = aml.company_id + WHERE am.id = apr.credit_move_id + AND rc.id = am.company_id """, ) diff --git a/openupgrade_scripts/scripts/base/14.0.1.3/pre-migrate.py b/openupgrade_scripts/scripts/base/14.0.1.3/pre-migrate.py index 0c5e41ea276c..e2afd839e187 100644 --- a/openupgrade_scripts/scripts/base/14.0.1.3/pre-migrate.py +++ b/openupgrade_scripts/scripts/base/14.0.1.3/pre-migrate.py @@ -145,6 +145,11 @@ def migrate(cr, version): if cr.fetchall(): merged_modules["edi"] = renamed_modules.pop("edi") + # Trobz, duplicate edi_storage_oca key when renaming + cr.execute("SELECT 1 FROM ir_module_module WHERE name='edi_storage_oca'") + if cr.fetchall(): + merged_modules["edi_storage"] = renamed_modules.pop("edi_storage") + openupgrade.update_module_names(cr, renamed_modules.items()) openupgrade.update_module_names(cr, merged_modules.items(), merge_modules=True) openupgrade.clean_transient_models(cr) diff --git a/openupgrade_scripts/scripts/mass_mailing/14.0.2.2/pre-migration.py b/openupgrade_scripts/scripts/mass_mailing/14.0.2.2/pre-migration.py index b6cf0b29d4d3..9ac812dbf1d3 100644 --- a/openupgrade_scripts/scripts/mass_mailing/14.0.2.2/pre-migration.py +++ b/openupgrade_scripts/scripts/mass_mailing/14.0.2.2/pre-migration.py @@ -42,15 +42,18 @@ def _assign_newsletter_xml_id(env): env.cr.execute("SELECT id FROM mailing_list WHERE name='Newsletter'") row = env.cr.fetchone() if row: - openupgrade.logged_query( - env.cr, - """INSERT INTO ir_model_data - (module, name, res_id, model, noupdate) - VALUES - ('mass_mailing', 'mailing_list_data', %s, 'mailing.list', True) - """, - (row[0],), - ) + # trobz migrate + env.cr.execute("SELECT id FROM ir_model_data WHERE module='mass_mailing' and name='mailing_list_data' and model='mailing.list' and res_id=%s" % row[0]) + if not env.cr.fetchone(): + openupgrade.logged_query( + env.cr, + """INSERT INTO ir_model_data + (module, name, res_id, model, noupdate) + VALUES + ('mass_mailing', 'mailing_list_data', %s, 'mailing.list', True) + """, + (row[0],), + ) @openupgrade.migrate() diff --git a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py index 1a01fc1cb990..f582a9d8125a 100644 --- a/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/project/14.0.1.1/pre-migration.py @@ -71,9 +71,11 @@ def migrate(env, version): """CREATE TABLE project_allowed_portal_users_rel (project_project_id INTEGER, res_users_id INTEGER)""", ) - openupgrade.logged_query( - env.cr, - """CREATE TABLE project_task_res_users_rel - (project_task_id INTEGER, res_users_id INTEGER)""", - ) + # trobz migrate: only create if project_task_res_users_rel not exist + if not openupgrade.table_exists(env.cr, 'project_task_res_users_rel'): + openupgrade.logged_query( + env.cr, + """CREATE TABLE project_task_res_users_rel + (project_task_id INTEGER, res_users_id INTEGER)""", + ) fast_fill_stored_calculated_fields(env) From c6cf8e2d4affd332a0a0e6c2d97d09a0588da40f Mon Sep 17 00:00:00 2001 From: Nguyen Minh Chien Date: Mon, 11 May 2026 16:59:03 +0700 Subject: [PATCH 2/2] [UPD] F#T67659 - Prepare data in foodcoop12 database to save migration time. --- .../account/14.0.1.1/post-migration.py | 34 +++++++++ .../scripts/account/14.0.1.1/pre-migration.py | 75 +++++++++++++++++++ .../purchase/14.0.1.2/pre-migration.py | 18 ++++- .../scripts/stock/14.0.1.1/post-migration.py | 3 +- .../scripts/stock/14.0.1.1/pre-migration.py | 2 +- 5 files changed, 128 insertions(+), 4 deletions(-) diff --git a/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py b/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py index a194b33353fb..07bc1dd6bb88 100644 --- a/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/account/14.0.1.1/post-migration.py @@ -582,6 +582,17 @@ def map_account_payment_transfer(env): def fill_account_payment_reconciliation(env): + env.cr.execute( + """ + SELECT 1 + FROM account_payment + WHERE is_matched IS NOT NULL OR is_reconciled IS NOT NULL + LIMIT 1 + """ + ) + has_prefilled_reconciliation = bool(env.cr.fetchone()) + if has_prefilled_reconciliation: + return openupgrade.logged_query( env.cr, """ @@ -747,6 +758,29 @@ def try_delete_noupdate_records(env): def fill_account_move_line_amounts(env): + legacy_amount_currency = openupgrade.get_legacy_name("amount_currency") + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_currency"): + if openupgrade.column_exists(env.cr, "account_move_line", "amount_currency") and not openupgrade.column_exists( + env.cr, "account_move_line", legacy_amount_currency + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN amount_currency TO {} + """.format(legacy_amount_currency), + ) + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_currency") and not openupgrade.column_exists( + env.cr, "account_move_line", "amount_currency" + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN mig18_amount_currency TO amount_currency + """, + ) + return openupgrade.logged_query( env.cr, """ diff --git a/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py index 62b6995d70c7..09978b172c90 100644 --- a/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/account/14.0.1.1/pre-migration.py @@ -297,6 +297,10 @@ def fill_empty_partner_type_account_payment(env): def fill_account_move_line_currency_id(env): + legacy_currency_id = openupgrade.get_legacy_name("currency_id") + legacy_amount_residual_currency = openupgrade.get_legacy_name( + "amount_residual_currency" + ) # Disappeared constraint openupgrade.logged_query( env.cr, @@ -308,6 +312,48 @@ def fill_account_move_line_currency_id(env): openupgrade.delete_records_safely_by_xml_id( env, ["account.constraint_account_move_line_check_amount_currency_balance_sign"] ) + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_currency_id"): + if openupgrade.column_exists(env.cr, "account_move_line", "currency_id") and not openupgrade.column_exists( + env.cr, "account_move_line", legacy_currency_id + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN currency_id TO {} + """.format(legacy_currency_id), + ) + if openupgrade.column_exists(env.cr, "account_move_line", "amount_residual_currency") and not openupgrade.column_exists( + env.cr, "account_move_line", legacy_amount_residual_currency + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN amount_residual_currency TO {} + """.format(legacy_amount_residual_currency), + ) + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_amount_residual_currency") and not openupgrade.column_exists( + env.cr, "account_move_line", "amount_residual_currency" + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN mig18_amount_residual_currency TO amount_residual_currency + """, + ) + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_currency_id") and not openupgrade.column_exists( + env.cr, "account_move_line", "currency_id" + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN mig18_currency_id TO currency_id + """, + ) + return openupgrade.logged_query( env.cr, """ @@ -320,6 +366,17 @@ def fill_account_move_line_currency_id(env): def fill_account_move_line_matching_number(env): + has_mig18_matching_number = openupgrade.column_exists( + env.cr, "account_move_line", "mig18_matching_number" + ) + if has_mig18_matching_number: + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move_line + RENAME COLUMN mig18_matching_number TO matching_number + """, + ) openupgrade.add_fields( env, [ @@ -333,6 +390,8 @@ def fill_account_move_line_matching_number(env): ), ], ) + if has_mig18_matching_number: + return openupgrade.logged_query( env.cr, """ @@ -470,6 +529,22 @@ def fill_account_payment_data(env): def create_account_payment_reconciliation(env): + if openupgrade.column_exists(env.cr, "account_payment", "mig18_is_reconciled"): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_payment + RENAME COLUMN mig18_is_reconciled TO is_reconciled + """, + ) + if openupgrade.column_exists(env.cr, "account_payment", "mig18_is_matched"): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_payment + RENAME COLUMN mig18_is_matched TO is_matched + """, + ) openupgrade.add_fields( env, [ diff --git a/openupgrade_scripts/scripts/purchase/14.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/purchase/14.0.1.2/pre-migration.py index a6d8df1b0111..d464e38f183e 100644 --- a/openupgrade_scripts/scripts/purchase/14.0.1.2/pre-migration.py +++ b/openupgrade_scripts/scripts/purchase/14.0.1.2/pre-migration.py @@ -4,13 +4,26 @@ def fill_purchase_order_line_qty_to_invoice(env): - if not openupgrade.column_exists(env.cr, "purchase_order_line", "qty_to_invoice"): + has_mig18_qty_to_invoice = openupgrade.column_exists( + env.cr, "purchase_order_line", "mig18_qty_to_invoice" + ) + if has_mig18_qty_to_invoice: + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE purchase_order_line + RENAME COLUMN mig18_qty_to_invoice TO qty_to_invoice + """, + ) + elif not openupgrade.column_exists(env.cr, "purchase_order_line", "qty_to_invoice"): openupgrade.logged_query( env.cr, """ ALTER TABLE purchase_order_line ADD COLUMN qty_to_invoice numeric""", ) + if has_mig18_qty_to_invoice: + return openupgrade.logged_query( env.cr, """ @@ -23,7 +36,8 @@ def fill_purchase_order_line_qty_to_invoice(env): ELSE 0 END FROM purchase_order po, product_product pp JOIN product_template pt ON pp.product_tmpl_id = pt.id - WHERE pol.order_id = po.id AND pol.product_id = pp.id""", + WHERE pol.order_id = po.id AND pol.product_id = pp.id + """, ) diff --git a/openupgrade_scripts/scripts/stock/14.0.1.1/post-migration.py b/openupgrade_scripts/scripts/stock/14.0.1.1/post-migration.py index 231f5b514f88..b26714de58e2 100644 --- a/openupgrade_scripts/scripts/stock/14.0.1.1/post-migration.py +++ b/openupgrade_scripts/scripts/stock/14.0.1.1/post-migration.py @@ -89,7 +89,8 @@ def delete_domain_from_view(env): @openupgrade.migrate() def migrate(env, version): - merge_priorities(env) + # priority has been updated in foodcoop_mig18_precompute_fields + # merge_priorities(env) delete_domain_from_view(env) openupgrade.load_data(env.cr, "stock", "14.0.1.1/noupdate_changes.xml") recompute_stock_picking_scheduled_date(env) diff --git a/openupgrade_scripts/scripts/stock/14.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/stock/14.0.1.1/pre-migration.py index efa6f062cd3e..44e19e321b7e 100644 --- a/openupgrade_scripts/scripts/stock/14.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/stock/14.0.1.1/pre-migration.py @@ -53,7 +53,7 @@ def fast_precreate_orderpoint_product_category_id(env): @openupgrade.migrate() def migrate(env, version): - openupgrade.copy_columns(env.cr, _column_copies) + # openupgrade.copy_columns(env.cr, _column_copies) openupgrade.rename_fields(env, _field_renames) openupgrade.rename_xmlids(env.cr, _xmlid_renames) openupgrade.add_fields(env, _field_additons)