diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 4151dd68d739..878fbe63ac64 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -838,7 +838,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | spreadsheet_dashboard_website_sale_slides | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| stock | | | +| stock | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | stock_account | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/stock/17.0.1.1/post-migration.py b/openupgrade_scripts/scripts/stock/17.0.1.1/post-migration.py new file mode 100644 index 000000000000..8eaf0e5c8ae8 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/17.0.1.1/post-migration.py @@ -0,0 +1,87 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +def _stock_scrap_convert_move_id_m2o_to_o2m(env): + """ + Convert m2o to o2m in 'stock.scrap' + """ + openupgrade.m2o_to_x2m( + env.cr, env["stock.scrap"], "stock_scrap", "move_ids", "move_id" + ) + + +def fix_move_quantity(env): + """ + Recompute move quantity for move lines that have been changed in pre-migration + """ + env.cr.execute( + """ + SELECT DISTINCT move_id FROM stock_move_line + WHERE + state IN ('assigned', 'partially_available') + AND reserved_qty <> 0 + """ + ) + moves = env["stock.move"].browse(_id for (_id,) in env.cr.fetchall()) + env.add_to_compute(moves._fields["quantity"], moves) + moves._recompute_recordset(["quantity"]) + + +def link_returned_pickings(env): + """ + Link pickings containing returned moves to the pickings containing the moves + being returned + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_picking + SET + return_id = returned_move.picking_id + FROM + stock_move + JOIN stock_move returned_move + ON stock_move.origin_returned_move_id = returned_move.id + WHERE + stock_move.picking_id = stock_picking.id + """, + ) + + +def set_picking_type_return_location(env): + """ + Set default_location_return_id on picking types from the destination location + of the warehouse's return picking type + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_picking_type + SET + default_location_return_id = COALESCE( + picking_return_type.default_location_dest_id, + warehouse_return_type.default_location_dest_id + ) + FROM + stock_picking_type self + JOIN stock_warehouse + ON self.warehouse_id=stock_warehouse.id + LEFT JOIN stock_picking_type picking_return_type + ON self.return_picking_type_id=picking_return_type.id + LEFT JOIN stock_picking_type warehouse_return_type + ON stock_warehouse.return_type_id=warehouse_return_type.id + WHERE + stock_picking_type.id=self.id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env, "stock", "17.0.1.1/noupdate_changes.xml") + _stock_scrap_convert_move_id_m2o_to_o2m(env) + fix_move_quantity(env) + link_returned_pickings(env) + set_picking_type_return_location(env) diff --git a/openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py new file mode 100644 index 000000000000..82bf533645a9 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/17.0.1.1/pre-migration.py @@ -0,0 +1,43 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + +_field_renames = [ + ("stock.move", "stock_move", "quantity_done", "quantity"), +] + +_column_copies = { + "stock_move_line": [ + ("qty_done", "quantity", None), + ] +} + + +def fix_move_line_quantity(env): + """ + v17 combines what used to be reserved_qty and qty_done. + We assume that we shouldn't touch an original qty_done on + done moves, but that we can best reflect the v16 state of + lines being worked on by adding reserved_qty to the new + quantity column, which was qty_done in v16 + + In post-migration, we'll recompute the quantity field of + moves affected. + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_move_line + SET quantity = quantity + reserved_qty + WHERE + state IN ('assigned', 'partially_available') + AND reserved_qty <> 0 + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_fields(env, _field_renames) + openupgrade.copy_columns(env.cr, _column_copies) + fix_move_line_quantity(env) diff --git a/openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt new file mode 100644 index 000000000000..3a2d1088c355 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/17.0.1.1/upgrade_analysis_work.txt @@ -0,0 +1,159 @@ +---Models in module 'stock'--- +obsolete model report.stock.report_product_product_replenishment [abstract] +obsolete model report.stock.report_product_template_replenishment [abstract] +obsolete model stock.immediate.transfer [transient] +obsolete model stock.immediate.transfer.line [transient] +new model stock.forecasted_product_product [abstract] +new model stock.forecasted_product_template [abstract] +new model stock.quant.relocate [transient] +# NOTHING TO DO + +---Fields in module 'stock'--- +stock / product.category / filter_for_stock_putaway_rule (boolean): NEW +stock / product.product / lot_properties_definition (properties_definition): NEW +# NOTHING TO DO: fields in new model + +stock / product.product / sale_delay (float) : type is now 'integer' ('float') +stock / product.template / sale_delay (float) : type is now 'integer' ('float') +# NOTHING TO DO + +stock / stock.lot / activity_user_id (many2one) : not related anymore +stock / stock.lot / activity_user_id (many2one) : now a function +stock / stock.lot / location_id (many2one) : NEW relation: stock.location, isfunction: function, stored +stock / stock.lot / lot_properties (properties) : NEW hasdefault: compute +stock / stock.lot / message_main_attachment_id (many2one): DEL relation: ir.attachment +stock / stock.lot / rating_ids (one2many) : NEW relation: rating.rating +# NOTHING TO DO + +stock / stock.move / move_line_nosuggest_ids (one2many): DEL relation: stock.move.line +stock / stock.move / picked (boolean) : NEW isfunction: function, stored +stock / stock.move / picking_type_id (many2one) : not a function anymore +# NOTHING TO DO + +stock / stock.move / quantity (float) : NEW isfunction: function, stored +stock / stock.move / quantity_done (float) : DEL +# DONE: renamed in pre-migration + +stock / stock.move / scrap_id (many2one) : NEW relation: stock.scrap +stock / stock.move / scrap_ids (one2many) : DEL relation: stock.scrap +stock / stock.scrap / move_id (many2one) : DEL relation: stock.move +stock / stock.scrap / move_ids (one2many) : NEW relation: stock.move +# DONE post-migration: convert data many2one to one2many + +stock / stock.move.line / qty_done (float) : DEL +stock / stock.move.line / quantity (float) : NEW hasdefault: compute +# DONE: pre-migration + +stock / stock.move.line / picked (boolean) : NEW hasdefault: compute +stock / stock.move.line / quant_id (many2one) : NEW relation: stock.quant +stock / stock.move.line / quantity_product_uom (float) : NEW isfunction: function, stored +# NOTHING TO DO + +stock / stock.move.line / reserved_qty (float) : DEL +stock / stock.move.line / reserved_uom_qty (float) : DEL required +# DONE: added to quantity in pre-migration, recompute stock.move#quantity in post-migration + + +stock / stock.package.type / height (integer) : type is now 'float' ('integer') +stock / stock.package.type / packaging_length (integer) : type is now 'float' ('integer') +stock / stock.package.type / width (integer) : type is now 'float' ('integer') +# NOTHING TO DO + +stock / stock.picking / activity_user_id (many2one) : not related anymore +stock / stock.picking / activity_user_id (many2one) : now a function +stock / stock.picking / immediate_transfer (boolean) : DEL +stock / stock.picking / message_main_attachment_id (many2one): DEL relation: ir.attachment +stock / stock.picking / move_ids_without_package (one2many): is now stored +stock / stock.picking / move_ids_without_package (one2many): not a function anymore +stock / stock.picking / move_line_nosuggest_ids (one2many): DEL relation: stock.move.line +stock / stock.picking / picking_properties (properties): NEW hasdefault: compute +stock / stock.picking / rating_ids (one2many) : NEW relation: rating.rating +stock / stock.picking / show_operations (boolean) : not a function anymore +stock / stock.picking / show_operations (boolean) : now related +# NOTHING TO DO + +stock / stock.picking / return_id (many2one) : NEW relation: stock.picking +stock / stock.picking / return_ids (one2many) : NEW relation: stock.picking +# DONE filled from returned moves in post-migration + +stock / stock.picking.type / auto_print_delivery_slip (boolean): NEW +stock / stock.picking.type / auto_print_lot_labels (boolean): NEW +stock / stock.picking.type / auto_print_package_label (boolean): NEW +stock / stock.picking.type / auto_print_packages (boolean) : NEW +stock / stock.picking.type / auto_print_product_labels (boolean): NEW +stock / stock.picking.type / auto_print_reception_report (boolean): NEW +stock / stock.picking.type / auto_print_reception_report_labels (boolean): NEW +stock / stock.picking.type / auto_print_return_slip (boolean): NEW +stock / stock.picking.type / lot_label_format (selection) : NEW selection_keys: ['4x12_lots', '4x12_units', 'zpl_lots', 'zpl_units'], hasdefault: default +stock / stock.picking.type / package_label_to_print (selection): NEW selection_keys: ['pdf', 'zpl'], hasdefault: default +stock / stock.picking.type / picking_properties_definition (properties_definition): NEW +stock / stock.picking.type / product_label_format (selection): NEW selection_keys: ['2x7xprice', '4x12', '4x12xprice', '4x7xprice', 'dymo', 'zpl', 'zplxprice'], hasdefault: default +stock / stock.picking.type / show_reserved (boolean) : now a function +# NOTHING TO DO: fields in new model + +stock / stock.picking.type / default_location_return_id (many2one): NEW relation: stock.location +# DONE set from warehouse's previous return picking type's destination location + +stock / stock.scrap / message_main_attachment_id (many2one): DEL relation: ir.attachment +stock / stock.scrap / rating_ids (one2many) : NEW relation: rating.rating +stock / stock.scrap / should_replenish (boolean) : NEW +stock / stock.warehouse / return_type_id (many2one) : DEL relation: stock.picking.type +# NOTHING TO DO + +---XML records in module 'stock'--- +NEW ir.actions.act_window: stock.action_picking_tree_incoming +NEW ir.actions.act_window: stock.action_picking_tree_internal +NEW ir.actions.act_window: stock.action_picking_tree_outgoing +NEW ir.actions.act_window: stock.action_product_production_lot_form +# NOTHING TO DO + +NEW ir.actions.client: stock.stock_forecasted_product_product_action +NEW ir.actions.client: stock.stock_forecasted_product_template_action +DEL ir.actions.client: stock.stock_replenishment_product_product_action +DEL ir.actions.client: stock.stock_replenishment_product_template_action + +NEW ir.actions.report: stock.return_label_report +NEW ir.actions.server: stock.action_scrap +NEW ir.actions.server: stock.action_toggle_is_locked +NEW ir.actions.server: stock.action_view_set_to_zero_quants_tree +DEL ir.actions.server: stock.stock_quant_stock_move_line_desynchronization +# NOTHING TO DO + +NEW ir.model.access: stock.access_stock_quant_relocate +DEL ir.model.access: stock.access_stock_immediate_transfer +DEL ir.model.access: stock.access_stock_immediate_transfer_line +# NOTHING TO DO: new feature + +ir.model.constraint: stock.constraint_stock_package_type_positive_height (changed definition: is now 'check(height>=0.0)' ('check(height>=0)')) +ir.model.constraint: stock.constraint_stock_package_type_positive_length (changed definition: is now 'check(packaging_length>=0.0)' ('check(packaging_length>=0)')) +ir.model.constraint: stock.constraint_stock_package_type_positive_width (changed definition: is now 'check(width>=0.0)' ('check(width>=0)')) +# NOTHING TO DO + +NEW ir.ui.menu: stock.in_picking +NEW ir.ui.menu: stock.int_picking +NEW ir.ui.menu: stock.menu_stock_adjustments +NEW ir.ui.menu: stock.menu_stock_procurement +NEW ir.ui.menu: stock.menu_stock_transfers +NEW ir.ui.menu: stock.out_picking +DEL ir.ui.menu: stock.all_picking +# NOTHING TO DO: new feature + +NEW ir.ui.view: stock.product_view_kanban_catalog +NEW ir.ui.view: stock.report_return_slip +NEW ir.ui.view: stock.stock_picking_view_activity +NEW ir.ui.view: stock.stock_quant_relocate_view_form +NEW ir.ui.view: stock.view_production_lot_kanban +NEW ir.ui.view: stock.view_stock_move_line_pivot +NEW ir.ui.view: stock.view_stock_quant_form +NEW ir.ui.view: stock.view_stock_quant_tree_simple +DEL ir.ui.view: stock.report_mrp_line +DEL ir.ui.view: stock.report_product_product_replenishment +DEL ir.ui.view: stock.report_product_template_replenishment +DEL ir.ui.view: stock.report_replenishment_header +DEL ir.ui.view: stock.report_stock_inventory +DEL ir.ui.view: stock.view_immediate_transfer +DEL ir.ui.view: stock.view_stock_move_nosuggest_operations +# NOTHING TO DO + +NEW product.removal: stock.removal_least_packages +# NOTHING TO DO diff --git a/openupgrade_scripts/scripts/stock/tests/data_stock_migration.py b/openupgrade_scripts/scripts/stock/tests/data_stock_migration.py new file mode 100644 index 000000000000..8df13d427755 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/tests/data_stock_migration.py @@ -0,0 +1,16 @@ +env = locals().get("env") +# return a picking so that we have something to migrate +picking = env.ref("stock.outgoing_shipment_main_warehouse1") +return_wizard = ( + env["stock.return.picking"] + .with_context( + active_id=picking.id, + active_ids=picking.ids, + active_model=picking._name, + ) + .create({}) +) +return_wizard._onchange_picking_id() +return_wizard._create_returns() + +env.cr.commit() diff --git a/openupgrade_scripts/scripts/stock/tests/test_stock_migration.py b/openupgrade_scripts/scripts/stock/tests/test_stock_migration.py new file mode 100644 index 000000000000..6465b41398b4 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/tests/test_stock_migration.py @@ -0,0 +1,31 @@ +from odoo.tests import TransactionCase + +from odoo.addons.openupgrade_framework import openupgrade_test + + +@openupgrade_test +class TestStockMigration(TransactionCase): + def test_move_quantity(self): + """ + Test that we add reserved_qty to quantity for assigned moves + """ + picking = self.env.ref("stock.outgoing_shipment_main_warehouse4") + self.assertEqual(picking.move_ids.quantity, 16) + picking = self.env.ref("stock.incomming_shipment2") + self.assertEqual(picking.move_ids.quantity, 125) + + def test_returned_picking(self): + """ + Test that we correctly link returned pickings to their origin picking + """ + returned_picking = self.env.ref("stock.outgoing_shipment_main_warehouse1") + self.assertTrue(returned_picking.return_ids) + + def test_return_location(self): + """ + Test that we set the default return location for pickings from the warehouse's + return picking type from v16 + """ + picking_type = self.env.ref("stock.picking_type_in") + stock_location = self.env.ref("stock.stock_location_stock") + self.assertEqual(picking_type.default_location_return_id, stock_location)