From 5f93a9168e578ed0e3077adce526122c1f68622b Mon Sep 17 00:00:00 2001 From: hieu Date: Mon, 20 Jun 2022 16:40:52 +0700 Subject: [PATCH 1/2] [OU-ADD] delivery: Migration scripts --- docsource/modules140-150.rst | 2 +- .../delivery/15.0.1.0/post-migration.py | 41 +++++++++++++++++++ .../15.0.1.0/upgrade_analysis_work.txt | 23 +++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py create mode 100644 openupgrade_scripts/scripts/delivery/15.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules140-150.rst b/docsource/modules140-150.rst index 8df6ab2355eb..e965cae98280 100644 --- a/docsource/modules140-150.rst +++ b/docsource/modules140-150.rst @@ -124,7 +124,7 @@ Module coverage 14.0 -> 15.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | crm_sms | Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| delivery | | | +| delivery |Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | |new| delivery_mondialrelay | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py b/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py new file mode 100644 index 000000000000..0583455a1940 --- /dev/null +++ b/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py @@ -0,0 +1,41 @@ +from openupgradelib import openupgrade + + +def _move_data_from_product_packaging_to_stock_package_type(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE stock_package_type + ADD COLUMN IF NOT EXISTS old_product_packaging_id INTEGER; + INSERT INTO stock_package_type(old_product_packaging_id, + name, sequence, height, width, + shipper_package_code, package_carrier_type, + packaging_length, max_weight, barcode, company_id, + create_uid, create_date, write_uid, write_date) + SELECT id, + name, sequence, height, width, + shipper_package_code, package_carrier_type, + packaging_length, max_weight, barcode, company_id, + create_uid, create_date, write_uid, write_date + FROM product_packaging + WHERE product_id IS NULL; + """, + ) + + +def _fill_stock_quant_package_package_type_id(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_quant_package sqp + SET package_type_id = spt.id + FROM stock_package_type spt + WHERE spt.old_product_packaging_id = sqp.packaging_id; + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _move_data_from_product_packaging_to_stock_package_type(env) + _fill_stock_quant_package_package_type_id(env) diff --git a/openupgrade_scripts/scripts/delivery/15.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/delivery/15.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..0c04847e6360 --- /dev/null +++ b/openupgrade_scripts/scripts/delivery/15.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,23 @@ +---Models in module 'delivery'--- +---Fields in module 'delivery'--- +delivery / product.packaging / height (integer) : DEL +delivery / product.packaging / max_weight (float) : DEL +delivery / product.packaging / package_carrier_type (selection): DEL selection_keys: ['none'] +delivery / product.packaging / packaging_length (integer) : DEL +delivery / product.packaging / shipper_package_code (char) : DEL +delivery / product.packaging / width (integer) : DEL +delivery / stock.package.type / package_carrier_type (selection): NEW selection_keys: ['none'], hasdefault +delivery / stock.package.type / shipper_package_code (char) : NEW +# DONE: post-migration: move data from product_packaging table to stock_package_type + +---XML records in module 'delivery'--- +DEL ir.actions.act_window: delivery.action_delivery_packaging_view +DEL ir.ui.menu: delivery.menu_delivery [renamed to stock module] +DEL ir.ui.menu: delivery.menu_delivery_packagings +NEW ir.ui.view: delivery.stock_package_type_form_delivery +NEW ir.ui.view: delivery.stock_package_type_tree_delivery +NEW ir.ui.view: delivery.view_move_line_tree_detailed_delivery +DEL ir.ui.view: delivery.product_packaging_delivery_form +DEL ir.ui.view: delivery.product_packaging_delivery_tree +DEL ir.ui.view: delivery.view_quant_package_packaging_tree +# NOTHING TO DO: noupdate="0" records From 8b31964ad05032ef611cffec1049a0d5286b5e8f Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 11 Mar 2023 12:09:56 +0100 Subject: [PATCH 2/2] [OU-IMP] delivery: Scripts adjustments --- docsource/modules140-150.rst | 2 +- .../scripts/delivery/15.0.1.0/post-migration.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docsource/modules140-150.rst b/docsource/modules140-150.rst index e965cae98280..efcd7ce84c4f 100644 --- a/docsource/modules140-150.rst +++ b/docsource/modules140-150.rst @@ -124,7 +124,7 @@ Module coverage 14.0 -> 15.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | crm_sms | Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| delivery |Done | | +| delivery | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | |new| delivery_mondialrelay | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py b/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py index 0583455a1940..d155245659eb 100644 --- a/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/delivery/15.0.1.0/post-migration.py @@ -2,11 +2,14 @@ def _move_data_from_product_packaging_to_stock_package_type(env): + openupgrade.logged_query( + env.cr, + """ALTER TABLE stock_package_type + ADD COLUMN IF NOT EXISTS old_product_packaging_id INTEGER""", + ) openupgrade.logged_query( env.cr, """ - ALTER TABLE stock_package_type - ADD COLUMN IF NOT EXISTS old_product_packaging_id INTEGER; INSERT INTO stock_package_type(old_product_packaging_id, name, sequence, height, width, shipper_package_code, package_carrier_type, @@ -18,19 +21,16 @@ def _move_data_from_product_packaging_to_stock_package_type(env): packaging_length, max_weight, barcode, company_id, create_uid, create_date, write_uid, write_date FROM product_packaging - WHERE product_id IS NULL; + WHERE product_id IS NULL """, ) - - -def _fill_stock_quant_package_package_type_id(env): openupgrade.logged_query( env.cr, """ UPDATE stock_quant_package sqp SET package_type_id = spt.id FROM stock_package_type spt - WHERE spt.old_product_packaging_id = sqp.packaging_id; + WHERE spt.old_product_packaging_id = sqp.packaging_id """, ) @@ -38,4 +38,3 @@ def _fill_stock_quant_package_package_type_id(env): @openupgrade.migrate() def migrate(env, version): _move_data_from_product_packaging_to_stock_package_type(env) - _fill_stock_quant_package_package_type_id(env)