From 67e01a67639504202a41fcfe70f5ae38abe6bd76 Mon Sep 17 00:00:00 2001 From: tranngocson1996 Date: Wed, 5 Jan 2022 14:13:46 +0700 Subject: [PATCH] [MIG] account_check_printing: Migration script --- docsource/modules130-140.rst | 2 +- .../14.0.1.0/post-migration.py | 8 ++++ .../14.0.1.0/pre-migration.py | 48 +++++++++++++++++++ .../14.0.1.0/upgrade_analysis_work.txt | 20 ++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/account_check_printing/14.0.1.0/post-migration.py create mode 100644 openupgrade_scripts/scripts/account_check_printing/14.0.1.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/account_check_printing/14.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules130-140.rst b/docsource/modules130-140.rst index 924173823e79..d918c4d2c84f 100644 --- a/docsource/modules130-140.rst +++ b/docsource/modules130-140.rst @@ -16,7 +16,7 @@ Module coverage 13.0 -> 14.0 +--------------------------------------------+-------------------------------------------------+ | |del| account_bank_statement_import | Adopted in OCA as account_statement_import | +--------------------------------------------+-------------------------------------------------+ -|account_check_printing | | +|account_check_printing | Done | +--------------------------------------------+-------------------------------------------------+ |account_debit_note | | +--------------------------------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/post-migration.py b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/post-migration.py new file mode 100644 index 000000000000..b20a66c2bdd2 --- /dev/null +++ b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/post-migration.py @@ -0,0 +1,8 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data( + env.cr, "account_check_printing", "14.0.1.0/noupdate_changes.xml" + ) diff --git a/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/pre-migration.py new file mode 100644 index 000000000000..381bdeb6a067 --- /dev/null +++ b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/pre-migration.py @@ -0,0 +1,48 @@ +from openupgradelib import openupgrade + + +def add_preferred_payment_method_id_field_account_move(env): + if not openupgrade.column_exists( + env.cr, "account_move", "preferred_payment_method_id" + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_move + ADD COLUMN preferred_payment_method_id integer + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE account_move am + SET preferred_payment_method_id = CAST( + SPLIT_PART(ip.value_reference, ',', 2) AS int) + FROM ir_property ip + WHERE ip.company_id = am.company_id AND + ip.res_id = CONCAT('res.partner,', am.partner_id) AND + ip.name = 'property_payment_method_id' + """, + ) + + +def fill_res_company_account_check_printing_layout(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE res_company + SET account_check_printing_layout = 'disabled' + WHERE account_check_printing_layout != 'disabled' AND + account_check_printing_layout IS NOT NULL + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.copy_columns( + env.cr, + {"res_company": [("account_check_printing_layout", None, None)]}, + ) + add_preferred_payment_method_id_field_account_move(env) + fill_res_company_account_check_printing_layout(env) diff --git a/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..86414b1f6e38 --- /dev/null +++ b/openupgrade_scripts/scripts/account_check_printing/14.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,20 @@ +---Models in module 'account_check_printing'--- +---Fields in module 'account_check_printing'--- +account_check_printing / account.move / preferred_payment_method_id (many2one): NEW relation: account.payment.method, isfunction: function, stored +# DONE: pre-migration: created preferred_payment_method_id column and set the value + +account_check_printing / account.payment / check_amount_in_words (char) : now a function +account_check_printing / account.payment / check_number (char) : now a function +# NOTHING TO DO: automated field filling + +account_check_printing / res.company / account_check_printing_layout (selection): selection_keys is now '['disabled']' ('['action_print_check_bottom', 'action_print_check_middle', 'action_print_check_top', 'disabled']') +# DONE: pre-migration: ensuring records are filled with default value ('disabled') + +account_check_printing / res.partner / property_payment_method_id (many2one): NEW relation: account.payment.method, hasdefault +# NOTHING TO DO + +---XML records in module 'account_check_printing'--- +NEW ir.model.access: account_check_printing.access_print_prenumbered_checks +NEW ir.ui.view: account_check_printing.view_account_invoice_filter +NEW ir.ui.view: account_check_printing.view_partner_property_form +# NOTHING TO DO: noupdate="0" records