From 1bd788a71bb41d2848ef48508f3be5f3ce1c1cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Ra=C3=AFch?= Date: Thu, 24 Apr 2025 16:42:19 +0200 Subject: [PATCH 1/2] [OU-ADD] stock --- docsource/modules170-180.rst | 2 +- .../scripts/stock/18.0.1.1/post-migration.py | 94 ++++++++++++ .../scripts/stock/18.0.1.1/pre-migration.py | 81 ++++++++++ .../stock/18.0.1.1/upgrade_analysis_work.txt | 138 ++++++++++++++++++ 4 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/stock/18.0.1.1/post-migration.py create mode 100644 openupgrade_scripts/scripts/stock/18.0.1.1/pre-migration.py create mode 100644 openupgrade_scripts/scripts/stock/18.0.1.1/upgrade_analysis_work.txt diff --git a/docsource/modules170-180.rst b/docsource/modules170-180.rst index 1030d1d13ca7..ed5b0ac113f5 100644 --- a/docsource/modules170-180.rst +++ b/docsource/modules170-180.rst @@ -1024,7 +1024,7 @@ Module coverage 17.0 -> 18.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | spreadsheet_dashboard_website_sale_slides | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| stock | | | +| stock | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | stock_account | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/stock/18.0.1.1/post-migration.py b/openupgrade_scripts/scripts/stock/18.0.1.1/post-migration.py new file mode 100644 index 000000000000..7d4e6ea4944e --- /dev/null +++ b/openupgrade_scripts/scripts/stock/18.0.1.1/post-migration.py @@ -0,0 +1,94 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade, openupgrade_180 + + +def convert_company_dependent(env): + openupgrade_180.convert_company_dependent( + env, "product.template", "property_stock_inventory" + ) + openupgrade_180.convert_company_dependent( + env, "product.template", "property_stock_production" + ) + openupgrade_180.convert_company_dependent(env, "product.template", "responsible_id") + openupgrade_180.convert_company_dependent( + env, "res.partner", "property_stock_customer" + ) + openupgrade_180.convert_company_dependent( + env, "res.partner", "property_stock_supplier" + ) + + +def _create_default_new_types_for_all_warehouses(env): + # method mainly based on _create_or_update_sequences_and_picking_types() + all_warehouses = env["stock.warehouse"].with_context(active_test=False).search([]) + for wh in all_warehouses: + sequence_data = wh._get_sequence_values() + for field in ["qc_type_id", "store_type_id", "xdock_type_id"]: + # choose the next available color for the operation types of this warehouse + all_used_colors = [ + res["color"] + for res in env["stock.picking.type"] + .with_context(active_test=False) + .search_read( + [("warehouse_id", "!=", False), ("color", "!=", False)], + ["color"], + order="color", + ) + ] + available_colors = [ + zef for zef in range(0, 12) if zef not in all_used_colors + ] + color = available_colors[0] if available_colors else 0 + # suit for each warehouse: reception, internal, pick, pack, ship + max_sequence = ( + env["stock.picking.type"] + .with_context(active_test=False) + .search_read( + [("sequence", "!=", False)], + ["sequence"], + limit=1, + order="sequence desc", + ) + ) + max_sequence = max_sequence and max_sequence[0]["sequence"] or 0 + values = wh._get_picking_type_update_values()[field] + create_data, _ = wh._get_picking_type_create_values(max_sequence) + values.update(create_data[field]) + sequence = env["ir.sequence"].create(sequence_data[field]) + values.update( + warehouse_id=wh.id, + color=color, + sequence_id=sequence.id, + sequence=max_sequence + 1, + company_id=wh.company_id.id, + active=wh.active, + ) + # create return picking type + picking_type_id = env["stock.picking.type"].create(values).id + # update return picking type for warehouse + wh.write({field: picking_type_id}) + + +def _set_inter_company_locations(env): + """See https://github.com/odoo/odoo/commit/08536d687880ca6d9ad5c37b639c0ad4c2599d74""" + companies = env["res.company"].search([]) + if len(companies) > 1: + inter_company_location = env.ref("stock.stock_location_inter_company") + if not inter_company_location.active: + inter_company_location.sudo().write({"active": True}) + for company in companies: + company.sudo()._set_per_company_inter_company_locations( + inter_company_location + ) + + +@openupgrade.migrate() +def migrate(env, version): + convert_company_dependent(env) + _create_default_new_types_for_all_warehouses(env) + _set_inter_company_locations(env) + openupgrade.load_data(env, "stock", "18.0.1.1/noupdate_changes.xml") + openupgrade.delete_records_safely_by_xml_id( + env, ["stock.property_stock_customer", "stock.property_stock_supplier"] + ) diff --git a/openupgrade_scripts/scripts/stock/18.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/stock/18.0.1.1/pre-migration.py new file mode 100644 index 000000000000..5a95b0fd577b --- /dev/null +++ b/openupgrade_scripts/scripts/stock/18.0.1.1/pre-migration.py @@ -0,0 +1,81 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + +_field_renames = [ + ("stock.move", "stock_move", "location_dest_id", "location_final_id"), + ( + "stock.warehouse.orderpoint", + "stock_warehouse_orderpoint", + "qty_to_order", + "qty_to_order_manual", + ), +] + +_xmlid_renames = [ + ("stock.stock_location_inter_wh", "stock.stock_location_inter_company"), +] + +_new_columns = [ + ("product.template", "is_storable", "boolean", False), + ("stock.move", "location_dest_id", "many2one"), + ("stock.rule", "location_dest_from_rule", "boolean", False), + ("stock.picking.type", "move_type", "selection", "direct"), + ("stock.putaway.rule", "sublocation", "selection", "no"), +] + + +def fill_product_template_is_storable(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE product_template + SET is_storable = TRUE, type = 'consu' + WHERE type = 'product'""", + ) + + +def fill_stock_move_location_dest_id(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_move sm2 + SET location_dest_id = COALESCE(sp.location_dest_id, + spt.default_location_dest_id, sm.location_final_id) + FROM stock_move sm + LEFT JOIN stock_picking sp ON sm.picking_id = sp.id + LEFT JOIN stock_picking_type spt ON sm.picking_type_id = spt.id + WHERE sm2.id = sm.id + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_rule sr + SET location_dest_from_rule = TRUE + FROM stock_move sm + WHERE sm.rule_id = sr.id + AND sm.location_dest_id != sm.location_final_id + AND sr.action IN ('pull', 'pull_push') + """, + ) + + +def fill_stock_putaway_rule_sublocation(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_putaway_rule + SET sublocation = 'closest_location' + WHERE storage_category_id is not null""", + ) + + +@openupgrade.migrate() +def migrate(env, version=None): + openupgrade.rename_fields(env, _field_renames) + openupgrade.rename_xmlids(env.cr, _xmlid_renames) + openupgrade.add_columns(env, _new_columns) + fill_product_template_is_storable(env) + fill_stock_move_location_dest_id(env) + fill_stock_putaway_rule_sublocation(env) diff --git a/openupgrade_scripts/scripts/stock/18.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/stock/18.0.1.1/upgrade_analysis_work.txt new file mode 100644 index 000000000000..31a4d0194178 --- /dev/null +++ b/openupgrade_scripts/scripts/stock/18.0.1.1/upgrade_analysis_work.txt @@ -0,0 +1,138 @@ +---Models in module 'stock'--- +obsolete model stock.assign.serial [transient] +obsolete model stock.scheduler.compute [transient] +new model stock.lot.report [sql_view] +new model stock.replenish.mixin [abstract] +new model stock.scrap.reason.tag +# NOTHING TO DO + +---Fields in module 'stock'--- +stock / product.template / detailed_type (False) : DEL selection_keys: ['consu', 'product', 'service'], mode: modify +stock / product.template / type (False) : DEL selection_keys: ['consu', 'product', 'service'], mode: modify +stock / product.template / is_storable (boolean) : NEW hasdefault: default +# DONE: pre-migration:: pre-create and fill is_storable and move 'product' to 'consu' + +stock / product.template / route_from_categ_ids (many2many): table is now 'False' ('stock.route') +# NOTHING TO DO: related field + +stock / product.template / property_stock_inventory (many2one): needs conversion to v18-style company dependent +stock / product.template / property_stock_production (many2one): needs conversion to v18-style company dependent +stock / product.template / responsible_id (many2one) : needs conversion to v18-style company dependent +stock / res.partner / property_stock_customer (many2one): needs conversion to v18-style company dependent +stock / res.partner / property_stock_supplier (many2one): needs conversion to v18-style company dependent +# DONE: post-migration: used openupgrade_180.convert_company_dependent + +stock / stock.location / return_location (boolean) : DEL +stock / stock.picking.type / default_location_return_id (many2one): DEL relation: stock.location +# NOTHING TO DO: now is using _can_return() method instead + +stock / stock.move / location_dest_id (many2one) : now a function +stock / stock.move / location_final_id (many2one) : NEW relation: stock.location +stock / stock.rule / location_dest_from_rule (boolean): NEW hasdefault: default +# DONE: pre-migration: rename location_dest_id to location_final_id, pre-create and fill location_dest_id and location_dest_from_rule + +stock / stock.move / never_product_template_attribute_value_ids (many2many): NEW relation: product.template.attribute.value +# NOTHING TO DO: new technical feature + +stock / stock.move.line / product_category_name (char) : not stored anymore +# NOTHING TO DO + +stock / stock.picking / search_date_category (selection): NEW selection_keys: ['after', 'before', 'day_1', 'day_2', 'today', 'yesterday'] +stock / stock.picking / shipping_weight (float) : previously in module stock_delivery +stock / stock.picking / weight_bulk (float) : previously in module stock_delivery +# NOTHING TO DO: not stored + +stock / stock.picking.type / _order : _order is now 'is_favorite desc, sequence, id' ('sequence, id') +# NOTHING TO DO: is_favorite is not stored + +stock / stock.picking.type / default_location_dest_id (many2one): now required +stock / stock.picking.type / default_location_src_id (many2one): now required +# NOTHING TO DO? (not sure if we can assure it someway) + +stock / stock.picking.type / favorite_user_ids (many2many) : NEW relation: res.users +# NOTHING TO DO: new feature + +stock / stock.picking.type / move_type (selection) : NEW required, selection_keys: ['direct', 'one'], hasdefault: default +# DONE: pre-migration: pre-create and fill it with default 'direct' + +stock / stock.picking.type / show_reserved (boolean) : DEL +# NOTHING TO DO: obsolete, see https://github.com/odoo/odoo/commit/54a795bf11d1ef5d791e587b0c9e4d260b97a79d + +stock / stock.putaway.rule / sublocation (selection) : NEW selection_keys: ['closest_location', 'last_used', 'no'], hasdefault: default +# DONE: pre-migration: pre-create and fill it ('no' by default, 'closest_location' if storage_category_id is not null) + +stock / stock.quant.package / location_id (many2one) : not a function anymore +# NOTHING TO DO: not sure why marked this way, it's the same in both v17 and v18 + +stock / stock.quant.package / shipping_weight (float) : previously in module stock_delivery +# NOTHING TO DO + +stock / stock.rule / push_domain (char) : NEW +# NOTHING TO DO: new feature + +stock / stock.scrap / scrap_reason_tag_ids (many2many): NEW relation: stock.scrap.reason.tag +stock / stock.scrap.reason.tag / color (char) : NEW hasdefault: default +stock / stock.scrap.reason.tag / name (char) : NEW required +stock / stock.scrap.reason.tag / sequence (integer) : NEW hasdefault: default +# NOTHING TO DO: new feature + +stock / stock.warehouse / qc_type_id (many2one) : NEW relation: stock.picking.type +stock / stock.warehouse / store_type_id (many2one) : NEW relation: stock.picking.type +stock / stock.warehouse / xdock_type_id (many2one) : NEW relation: stock.picking.type +# DONE: post-migration: created / updated default return type for all warehouses + +stock / stock.warehouse.orderpoint / qty_to_order (float) : not stored anymore +stock / stock.warehouse.orderpoint / qty_to_order (float) : now a function +stock / stock.warehouse.orderpoint / qty_to_order_manual (float) : NEW +# DONE: pre-migration: rename qty_to_order to qty_to_order_manual + +---XML records in module 'stock'--- +NEW digest.tip: stock.digest_tip_stock_1 +NEW ir.actions.act_window: stock.action_get_picking_type_ready_moves +NEW ir.actions.act_window: stock.action_inventory_at_date +NEW ir.actions.act_window: stock.action_lot_report +NEW ir.actions.act_window: stock.action_picking_tree_graph +# NOTHING TO DO + +ir.actions.act_window: stock.stock_picking_action_picking_type (deleted domain) +# NOTHING TO DO: domain was already empty + +DEL ir.actions.act_window: stock.act_assign_serial_numbers +DEL ir.actions.act_window: stock.action_procurement_compute +NEW ir.actions.server: stock.action_install_barcode +NEW ir.actions.server: stock.action_print_labels +NEW ir.actions.server: stock.click_dashboard_graph +NEW ir.actions.server: stock.method_action_picking_tree_incoming +NEW ir.actions.server: stock.method_action_picking_tree_internal +NEW ir.actions.server: stock.method_action_picking_tree_outgoing +NEW ir.actions.server: stock.stock_split_picking +NEW ir.config_parameter: stock.barcode_separator (noupdate) +NEW ir.model.access: stock.access_stock_inventory_adjustment_name_manager +NEW ir.model.access: stock.access_stock_inventory_adjustment_name_user +NEW ir.model.access: stock.access_stock_location_all_user +NEW ir.model.access: stock.access_stock_lot_report +NEW ir.model.access: stock.access_stock_scrap_reason_tag_manager +NEW ir.model.access: stock.access_stock_scrap_reason_tag_user +NEW ir.model.access: stock.access_update_product_attribute_value_stock_manager +DEL ir.model.access: stock.access_stock_assign_serial +DEL ir.model.access: stock.access_stock_inventory_adjustment_name +DEL ir.model.access: stock.access_stock_scheduler_compute +NEW ir.model.constraint: stock.constraint_stock_scrap_reason_tag_name_uniq +DEL ir.ui.menu: stock.menu_reordering_rules_config +NEW ir.ui.view: stock.help_message_template +NEW ir.ui.view: stock.product_template_search_view_inherit_stock +NEW ir.ui.view: stock.search_customer_lot_filter +NEW ir.ui.view: stock.stock_lot_customer_report_view_list +DEL ir.ui.view: stock.view_assign_serial_numbers +DEL ir.ui.view: stock.view_procurement_compute_wizard +DEL res.groups: stock.group_stock_picking_wave +DEL res.groups: stock.group_stock_storage_categories +# NOTHING TO DO + +DEL ir.property: stock.property_stock_customer (noupdate) +DEL ir.property: stock.property_stock_supplier (noupdate) +# DONE: post-migration: safely delete records + +NEW stock.location: stock.stock_location_inter_company (noupdate) +DEL stock.location: stock.stock_location_inter_wh (noupdate) +# DONE: pre-migration: rename xmlid From f4e820417ebb61c343983bdd54f1f837c63e73b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Wed, 14 May 2025 09:07:32 +0000 Subject: [PATCH 2/2] [OU-ADD] mrp --- docsource/modules170-180.rst | 2 +- .../scripts/mrp/18.0.2.0/post-migration.py | 150 ++++++++++++++++++ .../scripts/mrp/18.0.2.0/pre-migration.py | 56 +++++++ .../mrp/18.0.2.0/upgrade_analysis_work.txt | 116 ++++++++++++++ 4 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/mrp/18.0.2.0/post-migration.py create mode 100644 openupgrade_scripts/scripts/mrp/18.0.2.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/mrp/18.0.2.0/upgrade_analysis_work.txt diff --git a/docsource/modules170-180.rst b/docsource/modules170-180.rst index ed5b0ac113f5..f3fa2a6d5d09 100644 --- a/docsource/modules170-180.rst +++ b/docsource/modules170-180.rst @@ -704,7 +704,7 @@ Module coverage 17.0 -> 18.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | microsoft_outlook | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| mrp | | | +| mrp | | Done | +---------------------------------------------------+----------------------+-------------------------------------------------+ | mrp_account | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/mrp/18.0.2.0/post-migration.py b/openupgrade_scripts/scripts/mrp/18.0.2.0/post-migration.py new file mode 100644 index 000000000000..cb1f08bcdc0b --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/18.0.2.0/post-migration.py @@ -0,0 +1,150 @@ +# Copyright 2025 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from openupgradelib import openupgrade + + +def _migrate_mrp_documents(env): + if not openupgrade.table_exists(env.cr, "product_document_mrp_legacy"): + return + + # Fetch old mrp_document data: ir_attachment_id, active, priority. + # `product_document_mrp_legacy` contains fields from old `mrp_document`. + # `ir_attachment_id` was M2O to `ir.attachment`. + # `id` was the own ID of the `mrp_document` record. + env.cr.execute( + """ + SELECT ir_attachment_id, active, priority + FROM product_document_mrp_legacy + WHERE ir_attachment_id IS NOT NULL + """ + ) + old_docs_data = env.cr.dictfetchall() + + if not old_docs_data: + openupgrade.drop_tables(env.cr, ["product_document_mrp_legacy"]) + return + + # Mapping from old priorities to new sequence values. + # Default sequence on product.document is 10. Lower sequence means higher priority. + priority_to_sequence = { + "0": 15, # Normal + "1": 20, # Low + "2": 10, # High + "3": 5, # Very High + } + + ProductDocument = env["product.document"] + attachment_ids_to_migrate = [ + r["ir_attachment_id"] for r in old_docs_data if r["ir_attachment_id"] + ] + + # Pre-fetch existing product.document records to avoid duplicates and update them. + # Handles cases where product module might have already created product.document. + existing_product_docs = ProductDocument.search( + [("ir_attachment_id", "in", attachment_ids_to_migrate)] + ) + attachments_to_existing_pd = { + pd.ir_attachment_id.id: pd for pd in existing_product_docs + } + + pd_vals_list_create = [] + updated_count = 0 + created_count = 0 + + for old_doc_data in old_docs_data: + ir_attachment_id = old_doc_data["ir_attachment_id"] + if not ir_attachment_id: + continue + + # Ensure priority key is a string for dict lookup + sequence_val = priority_to_sequence.get(str(old_doc_data["priority"]), 10) + active_val = old_doc_data["active"] + + existing_pd = attachments_to_existing_pd.get(ir_attachment_id) + + if existing_pd: + # Update existing product.document if necessary + write_vals = {} + # 'bom' takes precedence. If it was 'hidden' or not set, update to 'bom'. + if existing_pd.attached_on_mrp != "bom": + write_vals["attached_on_mrp"] = "bom" + + # Update sequence if it was the default (10) and new mapping + # suggests different, + # or if explicitly set priority implies a new sequence different + # from current. + if (existing_pd.sequence == 10 and sequence_val != 10) or ( + old_doc_data["priority"] is not None + and existing_pd.sequence != sequence_val + ): + write_vals["sequence"] = sequence_val + + if existing_pd.active != active_val: + write_vals["active"] = active_val + + if write_vals: + existing_pd.write(write_vals) + updated_count += 1 + else: + # Create new product.document + pd_vals_list_create.append( + { + "ir_attachment_id": ir_attachment_id, + "active": active_val, + "attached_on_mrp": "bom", # Assume all old docs are 'bom' relevant + "sequence": sequence_val, + } + ) + created_count += 1 + + if pd_vals_list_create: + ProductDocument.create(pd_vals_list_create) + + openupgrade.drop_tables(env.cr, ["product_document_mrp_legacy"]) + log_message = ( + f"Migrated mrp.document records to product.document: " + f"{created_count} created, {updated_count} updated." + ) + openupgrade.log(env.cr, "MRP", log_message) + + +def _set_mrp_bom_line_manual_consumption(env): + # Old logic for mrp.bom.line.manual_consumption (v17): + # line.manual_consumption = (line.tracking != 'none' or line.operation_id) + # `product_id.tracking` (on product.product) is related + # to `product_tmpl_id.tracking`. + # `product.template.tracking` depends on `is_storable` in v18. + # The `stock` module migration scripts handle `type` -> `is_storable` + # and adjusts `tracking`. So, reading `product_id.tracking` here should give + # the v18-compatible value. `mrp.bom.line` has a `tracking` field related to + # `product_id.tracking`. + openupgrade.logged_query( + env.cr, + """ + UPDATE mrp_bom_line + SET manual_consumption = TRUE + WHERE (tracking IS NOT NULL AND tracking != 'none') OR operation_id IS NOT NULL; + """, + reason=( + "Set manual_consumption on mrp.bom.line based on v17 logic " + "(tracked product or specific operation)." + ), + ) + + +@openupgrade.migrate() +def migrate(env, version): + _migrate_mrp_documents(env) + _set_mrp_bom_line_manual_consumption(env) + + xml_ids_to_delete = [ + "mrp.act_assign_serial_numbers_production", + "mrp.view_mrp_workorder_view_gantt", # Gantt views often refactored/removed + "mrp.view_assign_serial_numbers_production", + "mrp.view_document_file_kanban_mrp", # Replaced by product.document views + "mrp.view_mrp_document_form", # Replaced by product.document views + "mrp.workcenter_line_gantt_production", # Gantt views often refactored/removed + ] + openupgrade.delete_records_safely_by_xml_id(env, xml_ids_to_delete) diff --git a/openupgrade_scripts/scripts/mrp/18.0.2.0/pre-migration.py b/openupgrade_scripts/scripts/mrp/18.0.2.0/pre-migration.py new file mode 100644 index 000000000000..204df700ee01 --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/18.0.2.0/pre-migration.py @@ -0,0 +1,56 @@ +# Copyright 2025 Akretion +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from openupgradelib import openupgrade + +_renamed_fields = [ + ("mrp.production", "mrp_production", "date_planned_start", "date_start"), + ("mrp.production", "mrp_production", "date_planned_finished", "date_finished"), + ("mrp.workorder", "mrp_workorder", "date_planned_start", "date_start"), + ("mrp.workorder", "mrp_workorder", "date_planned_finished", "date_finished"), +] + + +@openupgrade.migrate() +def migrate(env, version): + # Handle mrp.document model removal and merge into product.document + # The old mrp_document model inherited ir.attachment via 'ir_attachment_id' M2O. + # The product_document_mrp_legacy table will contain fields specific + # to the old mrp_document. + if openupgrade.table_exists(env.cr, "mrp_document"): + openupgrade.rename_tables( + env.cr, [("mrp_document", "product_document_mrp_legacy")] + ) + + openupgrade.rename_fields(env, _renamed_fields) + + # Attempt to get column type for 'produce_delay' + # If get_pg_column_type is not available, this part might need adjustment + # based on your specific openupgradelib version or available helpers. + # For now, proceeding with a direct check and alter. + if openupgrade.column_exists(env.cr, "mrp_bom", "produce_delay"): + # A more robust check would be to inspect information_schema.columns.data_type + # but that's more complex without a helper. + # Assuming if it exists and needs conversion, it's likely 'double precision'. + try: + openupgrade.alter_column_type( + env.cr, + "mrp_bom", + "produce_delay", + "integer", + "USING ROUND(produce_delay)::integer", + ) + openupgrade.log( + env.cr, + "MRP", + "Altered column type of mrp_bom.produce_delay to integer.", + ) + except Exception as e: + openupgrade.log( + env.cr, + "MRP", + "Could not alter column type of mrp_bom.produce_delay: %s. " + "Manual check might be needed." % e, + level="warning", + ) diff --git a/openupgrade_scripts/scripts/mrp/18.0.2.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/mrp/18.0.2.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..8aa82fc0920e --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/18.0.2.0/upgrade_analysis_work.txt @@ -0,0 +1,116 @@ +---Models in module 'mrp'--- +obsolete model mrp.document (merged to product.document) +# DONE: pre-migration: renamed table `mrp_document` to `product_document_mrp_legacy`. +# DONE: post-migration: data from `product_document_mrp_legacy` (ir_attachment_id, active, priority as sequence) +# migrated to `product.document`, setting `attached_on_mrp` = 'bom'. +# Old table `product_document_mrp_legacy` is dropped. + +new model mrp.batch.produce [transient] +# NOTHING TO DO: New transient model. + +---Fields in module 'mrp'--- +mrp / mrp.document / _inherits : DEL _inherits: {'ir.attachment': 'ir_attachment_id'} +mrp / mrp.document / active (boolean) : DEL +mrp / mrp.document / ir_attachment_id (many2one) : DEL relation: ir.attachment, required +mrp / mrp.document / priority (selection) : DEL selection_keys: ['0', '1', '2', '3'] +# DONE: Fields of the deleted `mrp.document` model. Data migrated in post-migration. + +mrp / mrp.production / location_final_id (many2one) : NEW relation: stock.location +mrp / mrp.production / never_product_template_attribute_value_ids (many2many): NEW relation: product.template.attribute.value +mrp / mrp.production / search_date_category (selection): NEW selection_keys: ['after', 'before', 'day_1', 'day_2', 'today', 'yesterday'] +# NOTHING TO DO: New fields, new functionality. + +mrp / mrp.routing.workcenter / activity_ids (one2many) : NEW relation: mail.activity +mrp / mrp.routing.workcenter / message_follower_ids (one2many): NEW relation: mail.followers +mrp / mrp.routing.workcenter / message_ids (one2many) : NEW relation: mail.message +mrp / mrp.routing.workcenter / rating_ids (one2many) : NEW relation: rating.rating +mrp / mrp.routing.workcenter / website_message_ids (one2many): NEW relation: mail.message +# NOTHING TO DO: New mail-related fields due to inheritance changes. + +mrp / mrp.unbuild / bom_id (many2one) : now a function +mrp / mrp.unbuild / lot_id (many2one) : now a function +# NOTHING TO DO: Change from stored to compute. ORM will handle recomputation. + +mrp / mrp.workcenter / message_follower_ids (one2many): NEW relation: mail.followers +mrp / mrp.workcenter / message_ids (one2many) : NEW relation: mail.message +mrp / mrp.workcenter / rating_ids (one2many) : NEW relation: rating.rating +mrp / mrp.workcenter / website_message_ids (one2many): NEW relation: mail.message +# NOTHING TO DO: New mail-related fields due to inheritance changes. + +mrp / mrp.workorder / _order : _order is now 'sequence, leave_id, date_start, id' ('leave_id, date_start, id') +# NOTHING TO DO: Change in default sort order. + +mrp / mrp.workorder / production_date (datetime) : not related anymore +mrp / mrp.workorder / production_date (datetime) : now a function +# NOTHING TO DO: Change from related to compute. ORM will handle recomputation. + +mrp / mrp.workorder / sequence (integer) : NEW hasdefault: default +# NOTHING TO DO: New field with default. + +mrp / product.document / attached_on_mrp (selection) : NEW required, selection_keys: ['bom', 'hidden'], hasdefault: default +# DONE: New field on `product.document`. Populated in post-migration for migrated `mrp.document` records. + +mrp / stock.move / manual_consumption (boolean) : not a function anymore +# DONE: This field's computation now relies on `mrp.bom.line.manual_consumption`. +# The `mrp.bom.line.manual_consumption` field itself was a compute and is now stored; +# its value is set in post-migration script for `mrp.bom.line` based on old logic. +# The stock module migration will then correctly compute and store `stock.move.manual_consumption`. + +mrp / stock.picking.type / use_auto_consume_components_lots (boolean): DEL +# DONE: Field removed. The logic is now handled by `mrp.bom.line.manual_consumption`. No data migration needed for this field itself. + +mrp / mrp.production / date_planned_start (datetime) : RENAMED to date_start +mrp / mrp.production / date_planned_finished (datetime) : RENAMED to date_finished +mrp / mrp.workorder / date_planned_start (datetime) : RENAMED to date_start +mrp / mrp.workorder / date_planned_finished (datetime) : RENAMED to date_finished +# DONE: Renamed in pre-migration.py. + +mrp / mrp.bom / produce_delay (float) : type changed to integer +# DONE: Type changed from float to integer. Handled in pre-migration by rounding. + +mrp / mrp.bom.line / manual_consumption (boolean) : logic changed from compute to stored with default. +# DONE: Populated in post-migration based on v17 logic: (line.tracking != 'none' or line.operation_id). + +mrp / mrp.workorder / next_work_order_id (many2one) : DEL relation: mrp.workorder +# NOTHING TO DO: Field removed. Replaced by `blocked_by_workorder_ids` and `needed_by_workorder_ids`. Logic for linking workorders is in `mrp.production._link_workorders_and_moves`. + +---XML records in module 'mrp'--- +NEW ir.actions.act_window: mrp.action_mrp_batch_produce +NEW ir.actions.act_window: mrp.action_picking_tree_mrp_operation_graph +# NOTHING TO DO: New records. + +DEL ir.actions.act_window: mrp.act_assign_serial_numbers_production +# DONE: Deleted in post-migration. + +NEW ir.actions.server: mrp.action_pause_workorders +NEW ir.actions.server: mrp.action_print_labels +NEW ir.actions.server: mrp.action_production_order_lock_unlock +NEW ir.actions.server: mrp.action_production_order_scrap +NEW ir.actions.server: mrp.action_start_workorders +NEW ir.model.access: mrp.access_mrp_batch_produce +NEW ir.model.access: mrp.access_stock_move_mrp_user +NEW ir.ui.view: mrp.mrp_production_workorder_tree_editable_view_mo_form +NEW ir.ui.view: mrp.product_document_form +NEW ir.ui.view: mrp.product_view_search_catalog +NEW ir.ui.view: mrp.view_mrp_batch_produce_form +NEW ir.ui.view: mrp.view_mrp_stock_move_operations +NEW ir.ui.view: mrp.view_stock_rule_form +# NOTHING TO DO: New records. + +DEL ir.ui.view: mrp.mrp_workorder_view_gantt +DEL ir.ui.view: mrp.view_assign_serial_numbers_production +# DONE: Deleted in post-migration. + +DEL ir.ui.view: mrp.view_document_file_kanban_mrp +DEL ir.ui.view: mrp.view_mrp_document_form +# DONE: Related to `mrp.document` removal. Deleted in post-migration. + +DEL ir.ui.view: mrp.workcenter_line_gantt_production +# DONE: Deleted in post-migration. + +NEW mail.message.subtype: mrp.mrp_mo_in_cancelled (noupdate) +NEW mail.message.subtype: mrp.mrp_mo_in_confirmed (noupdate) +NEW mail.message.subtype: mrp.mrp_mo_in_done (noupdate) +NEW mail.message.subtype: mrp.mrp_mo_in_progress (noupdate) +NEW mail.message.subtype: mrp.mrp_mo_in_to_close (noupdate) +# NOTHING TO DO: New records.