From 73c696fcbac29c3dc1b7c5410880b8f5c983b8e7 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 9 Oct 2024 21:42:41 -0400 Subject: [PATCH] [17.0][OU-ADD] stock_delivery: Migration to 17.0 --- docsource/modules160-170.rst | 2 +- .../delivery/17.0.1.0/post-migration.py | 9 ++ .../delivery/17.0.1.0/pre-migration.py | 76 +++++++++++++++ .../17.0.1.0/upgrade_analysis_work.txt | 95 +++++++++++++++++++ 4 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/delivery/17.0.1.0/post-migration.py create mode 100644 openupgrade_scripts/scripts/delivery/17.0.1.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/delivery/17.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 0ae89b703492..4da972e5ccd0 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -116,7 +116,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | data_recycle | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| delivery | | | +| delivery | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | delivery_mondialrelay | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/delivery/17.0.1.0/post-migration.py b/openupgrade_scripts/scripts/delivery/17.0.1.0/post-migration.py new file mode 100644 index 000000000000..c5e9af994bc3 --- /dev/null +++ b/openupgrade_scripts/scripts/delivery/17.0.1.0/post-migration.py @@ -0,0 +1,9 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env, "delivery", "17.0.1.0/noupdate_changes.xml") diff --git a/openupgrade_scripts/scripts/delivery/17.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/delivery/17.0.1.0/pre-migration.py new file mode 100644 index 000000000000..c427c8b7df11 --- /dev/null +++ b/openupgrade_scripts/scripts/delivery/17.0.1.0/pre-migration.py @@ -0,0 +1,76 @@ +from openupgradelib import openupgrade + +_new_fields = [ + ( + "carrier_id", # Field name + "stock.move.line", # Model name + "stock_move_line", # Table name + "many2one", # Odoo Field type (in lower case) + False, # [Optional] SQL type (if custom fields) + "delivery", # Module name + False, # [Optional] Default value + ) +] + +_xmlids_renames = [ + ( + "delivery.act_delivery_trackers_url", + "stock_delivery.act_delivery_trackers_url", + ), + ( + "delivery.access_choose_delivery_package", + "stock_delivery.access_choose_delivery_package", + ), + ( + "delivery.access_delivery_carrier_stock_user", + "stock_delivery.access_delivery_carrier_stock_user", + ), + ( + "delivery.access_delivery_carrier_stock_manager", + "stock_delivery.access_delivery_carrier_stock_manager", + ), + ( + "delivery.access_delivery_price_rule_stock_manager", + "stock_delivery.access_delivery_price_rule_stock_manager", + ), + ( + "delivery.access_delivery_zip_prefix_stock_manager", + "stock_delivery.access_delivery_zip_prefix_stock_manager", + ), + ( + "delivery.menu_action_delivery_carrier_form", + "stock_delivery.menu_action_delivery_carrier_form", + ), + ( + "delivery.menu_delivery_zip_prefix", + "stock_delivery.menu_delivery_zip_prefix", + ), +] + + +def _delete_sql_constraints(env): + # Delete constraints to recreate it + openupgrade.delete_sql_constraint_safely( + env, "delivery", "delivery_carrier", "margin_not_under_100_percent" + ) + + +def _fill_stock_move_line_carrier_id(env): + """Field `carrier_id` on stock.move.line is now a stored field.""" + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_move_line sml + SET carrier_id = sp.carrier_id + FROM stock_picking sp + WHERE sml.picking_id = sp.id; + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_xmlids(env, _xmlids_renames) + openupgrade.add_fields(env, _new_fields) + _delete_sql_constraints(env) + _fill_stock_move_line_carrier_id(env) diff --git a/openupgrade_scripts/scripts/delivery/17.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/delivery/17.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..fbbca27a74ce --- /dev/null +++ b/openupgrade_scripts/scripts/delivery/17.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,95 @@ +---Models in module 'delivery'--- +model choose.delivery.package (moved to stock_delivery) [column['model_type']] +# DONE: in migration script of module stock_delivery + +---Fields in module 'delivery'--- +delivery / delivery.carrier / fixed_margin (float) : NEW +delivery / delivery.carrier / invoice_policy (selection) : selection_keys is now '['estimated']' ('['estimated', 'real']') +# NOTHING TO DO: + +delivery / sale.order / shipping_weight (float) : NEW hasdefault: compute +# NOTHING TO DO: new features + +delivery / stock.move.line / carrier_id (many2one) : is now stored +# DONE: pre-migration: Add new column & set value for it + +delivery / stock.move.line / carrier_name (char) : DEL +# NOTHING TO DO: + +delivery / product.product / country_of_origin (many2one) : module is now 'stock_delivery' ('delivery') +delivery / product.product / hs_code (char) : module is now 'stock_delivery' ('delivery') +delivery / product.template / country_of_origin (many2one) : module is now 'stock_delivery' ('delivery') +delivery / product.template / hs_code (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.move / weight (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.move.line / carrier_id (many2one) : module is now 'stock_delivery' ('delivery') +delivery / stock.move.line / destination_country_code (char): module is now 'stock_delivery' ('delivery') +delivery / stock.move.line / sale_price (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.package.type / package_carrier_type (selection): module is now 'stock_delivery' ('delivery') +delivery / stock.package.type / shipper_package_code (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / carrier_id (many2one) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / carrier_price (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / carrier_tracking_ref (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / carrier_tracking_url (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / delivery_type (selection) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / destination_country_code (char): module is now 'stock_delivery' ('delivery') +delivery / stock.picking / is_return_picking (boolean) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / package_ids (many2many) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / return_label_ids (one2many) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / shipping_weight (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / weight (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / weight_bulk (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.picking / weight_uom_name (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.quant.package / shipping_weight (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.quant.package / weight (float) : module is now 'stock_delivery' ('delivery') +delivery / stock.quant.package / weight_is_kg (boolean) : module is now 'stock_delivery' ('delivery') +delivery / stock.quant.package / weight_uom_name (char) : module is now 'stock_delivery' ('delivery') +delivery / stock.quant.package / weight_uom_rounding (float) : module is now 'stock_delivery' ('delivery') +# NOTHING TO DO: Handled by ORM + +---XML records in module 'delivery'--- +DEL ir.actions.act_window: delivery.act_delivery_trackers_url [renamed to stock_delivery module] +# DONE: pre-migration: moved to stock_delivery + +NEW ir.model.access: delivery.access_delivery_price_rule_sale_manager +NEW ir.model.access: delivery.access_delivery_zip_prefix_sale_manager +DEL ir.model.access: delivery.access_choose_delivery_carrier_salesman +# NOTHING TO DO + +DEL ir.model.access: delivery.access_choose_delivery_package [renamed to stock_delivery module] +DEL ir.model.access: delivery.access_delivery_carrier_stock_manager [renamed to stock_delivery module] +DEL ir.model.access: delivery.access_delivery_carrier_stock_user [renamed to stock_delivery module] +DEL ir.model.access: delivery.access_delivery_price_rule_stock_manager [renamed to stock_delivery module] +DEL ir.model.access: delivery.access_delivery_zip_prefix_stock_manager [renamed to stock_delivery module] +# DONE: pre-migration: moved to stock_delivery + +ir.model.constraint: delivery.constraint_delivery_carrier_margin_not_under_100_percent (changed definition: is now 'check(margin >= -1)' ('check(margin >= -100)')) +# DONE pre-migration: safely delete constraint to recreate it + +DEL ir.ui.menu: delivery.menu_action_delivery_carrier_form [renamed to stock_delivery module] +DEL ir.ui.menu: delivery.menu_delivery_zip_prefix [renamed to stock_delivery module] +# DONE: pre-migration: moved to stock_delivery + +DEL ir.ui.view: delivery.choose_delivery_package_view_form +DEL ir.ui.view: delivery.delivery_stock_report_delivery_no_package_section_line +DEL ir.ui.view: delivery.delivery_tracking_url_warning_form +DEL ir.ui.view: delivery.label_package_template_view_delivery +DEL ir.ui.view: delivery.product_template_hs_code +DEL ir.ui.view: delivery.report_delivery_document2 +DEL ir.ui.view: delivery.report_package_barcode_delivery +DEL ir.ui.view: delivery.report_package_barcode_small_delivery +DEL ir.ui.view: delivery.report_shipping2 +DEL ir.ui.view: delivery.sale_order_portal_content_inherit_sale_stock_inherit_website_sale_delivery +DEL ir.ui.view: delivery.stock_move_line_view_search_delivery +DEL ir.ui.view: delivery.stock_package_type_form_delivery +DEL ir.ui.view: delivery.stock_package_type_tree_delivery +DEL ir.ui.view: delivery.stock_report_delivery_aggregated_move_lines_inherit_delivery +DEL ir.ui.view: delivery.stock_report_delivery_has_serial_move_line_inherit_delivery +DEL ir.ui.view: delivery.stock_report_delivery_package_section_line_inherit_delivery +DEL ir.ui.view: delivery.view_move_line_tree_detailed_delivery +DEL ir.ui.view: delivery.view_picking_type_form_delivery +DEL ir.ui.view: delivery.view_picking_withcarrier_out_form +DEL ir.ui.view: delivery.view_picking_withweight_internal_move_form +DEL ir.ui.view: delivery.view_quant_package_weight_form +DEL ir.ui.view: delivery.view_stock_rule_form_delivery +DEL ir.ui.view: delivery.vpicktree_view_tree +# NOTHING TO DO