diff --git a/docsource/modules130-140.rst b/docsource/modules130-140.rst index 60666719a40d..584b57a39ca8 100644 --- a/docsource/modules130-140.rst +++ b/docsource/modules130-140.rst @@ -452,7 +452,7 @@ Module coverage 13.0 -> 14.0 +--------------------------------------------+-------------------------------------------------+ | |new| microsoft_calendar | | +--------------------------------------------+-------------------------------------------------+ -|mrp | | +|mrp | Done | +--------------------------------------------+-------------------------------------------------+ |mrp_account | | +--------------------------------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml b/openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml index 40e581faefcb..a0c7c162ccea 100644 --- a/openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml @@ -1,30 +1,30 @@ - + - + - + - + - + - + - + - + - + diff --git a/openupgrade_scripts/scripts/mrp/14.0.2.0/post-migration.py b/openupgrade_scripts/scripts/mrp/14.0.2.0/post-migration.py new file mode 100644 index 000000000000..55403f593e7b --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/14.0.2.0/post-migration.py @@ -0,0 +1,56 @@ +# Copyright 2021 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +def merge_priorities(env): + openupgrade.map_values( + env.cr, + openupgrade.get_legacy_name("priority"), + "priority", + [("1", "0"), ("2", "1"), ("3", "1")], + table="mrp_production", + ) + + +def map_stock_move_line_lot_produced_ids(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_move_line sml + SET lot_id = rel.stock_production_lot_id + FROM stock_move_line_stock_production_lot_rel rel + JOIN stock_move_line_consume_rel rel2 + ON rel2.produce_line_id = rel.stock_move_line_id + WHERE sml.lot_id IS NULL AND rel2.consume_line_id = sml.id""", + ) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO stock_move_line_consume_rel ( + produce_line_id, consume_line_id) + SELECT rel.stock_move_line_id, sml.id + FROM stock_move_line_stock_production_lot_rel rel + JOIN stock_move_line sml ON ( + sml.lot_id = rel.stock_production_lot_id + AND rel.stock_move_line_id != sml.id) + LEFT JOIN stock_move_line_consume_rel rel2 ON ( + rel2.produce_line_id = rel.stock_move_line_id + AND rel2.consume_line_id = sml.id) + WHERE rel2.produce_line_id IS NULL""", + ) + + +def map_mrp_production_state_planned(env): + env["mrp.production"].search([("state", "=", "planned")])._compute_state() + + +@openupgrade.migrate() +def migrate(env, version): + merge_priorities(env) + map_stock_move_line_lot_produced_ids(env) + map_mrp_production_state_planned(env) + openupgrade.load_data(env.cr, "mrp", "14.0.2.0/noupdate_changes.xml") + openupgrade.delete_records_safely_by_xml_id( + env, ["mrp.mrp_routing_rule", "mrp.sequence_mrp_route"] + ) diff --git a/openupgrade_scripts/scripts/mrp/14.0.2.0/pre-migration.py b/openupgrade_scripts/scripts/mrp/14.0.2.0/pre-migration.py new file mode 100644 index 000000000000..e2f42d3f7c03 --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/14.0.2.0/pre-migration.py @@ -0,0 +1,107 @@ +# Copyright 2021 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_column_copies = { + "mrp_production": [ + ("priority", None, None), + ("state", None, None), + ], +} + + +def fill_mrp_routing_workcenter_bom_id(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE mrp_routing_workcenter + ADD COLUMN bom_id integer""", + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE mrp_routing_workcenter + ADD COLUMN old_routing_workcenter_id integer""", + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE mrp_routing_workcenter + ALTER COLUMN routing_id DROP NOT NULL""", + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE mrp_routing_workcenter + ALTER COLUMN batch DROP NOT NULL""", + ) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO mrp_routing_workcenter (name, workcenter_id, sequence, + company_id, worksheet_type, note, worksheet_google_slide, time_mode, + time_mode_batch, time_cycle_manual, create_uid, write_uid, + create_date, write_date, bom_id, routing_id, + old_routing_workcenter_id) + SELECT mrw.name, mrw.workcenter_id, mrw.sequence, mrw.company_id, + mrw.worksheet_type, mrw.note, mrw.worksheet_google_slide, + mrw.time_mode, mrw.time_mode_batch, mrw.time_cycle_manual, + mrw.create_uid, mb.write_uid, mb.create_date, mb.create_date, + mb.id, mrw.routing_id, mrw.id + FROM mrp_routing_workcenter mrw + JOIN mrp_bom mb ON mb.routing_id = mrw.routing_id""", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE mrp_bom_line mbl + SET operation_id = mrw.id + FROM mrp_bom mb + JOIN mrp_routing_workcenter mrw ON mrw.bom_id = mb.id + JOIN mrp_routing_workcenter mrw2 ON mrw.old_routing_workcenter_id = mrw2.id + WHERE mbl.bom_id = mb.id AND mbl.operation_id = mrw2.id""", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE mrp_bom_byproduct mbp + SET operation_id = mrw.id + FROM mrp_bom mb + JOIN mrp_routing_workcenter mrw ON mrw.bom_id = mb.id + JOIN mrp_routing_workcenter mrw2 ON mrw.old_routing_workcenter_id = mrw2.id + WHERE mbp.bom_id = mb.id AND mbp.operation_id = mrw2.id""", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE mrp_workorder mw + SET operation_id = mrw.id + FROM mrp_production mp + JOIN mrp_bom mb ON mp.bom_id = mb.id + JOIN mrp_routing_workcenter mrw ON mrw.bom_id = mb.id + JOIN mrp_routing_workcenter mrw2 ON mrw.old_routing_workcenter_id = mrw2.id + WHERE mw.production_id = mp.id AND mw.operation_id = mrw2.id""", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE stock_move sm + SET operation_id = mrw.id + FROM mrp_production mp + JOIN mrp_bom mb ON mp.bom_id = mb.id + JOIN mrp_routing_workcenter mrw ON mrw.bom_id = mb.id + JOIN mrp_routing_workcenter mrw2 ON mrw.old_routing_workcenter_id = mrw2.id + WHERE sm.raw_material_production_id = mp.id AND sm.operation_id = mrw2.id""", + ) + openupgrade.logged_query( + env.cr, + """ + DELETE FROM mrp_routing_workcenter + WHERE old_routing_workcenter_id IS NULL""", + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.copy_columns(env.cr, _column_copies) + fill_mrp_routing_workcenter_bom_id(env) diff --git a/openupgrade_scripts/scripts/mrp/14.0.2.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/mrp/14.0.2.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..544ccc0052bd --- /dev/null +++ b/openupgrade_scripts/scripts/mrp/14.0.2.0/upgrade_analysis_work.txt @@ -0,0 +1,198 @@ +---Models in module 'mrp'--- +obsolete model mrp.abstract.workorder [abstract] +obsolete model mrp.abstract.workorder.line [abstract] +obsolete model mrp.product.produce [transient] +obsolete model mrp.product.produce.line [transient] +new model mrp.consumption.warning [transient] +new model mrp.consumption.warning.line [transient] +new model mrp.immediate.production [transient] +new model mrp.immediate.production.line [transient] +new model mrp.production.backorder [transient] +new model mrp.production.backorder.line [transient] +# NOTHING TO DO: abstract + transient models + +obsolete model mrp.routing +obsolete model mrp.workorder.line +# NOTHING TO DO: obsolete models + +---Fields in module 'mrp'--- +mrp / mrp.document / key (char) : previously in module website +mrp / mrp.document / theme_template_id (many2one) : previously in module website_theme_install +mrp / mrp.document / website_id (many2one) : previously in module website +mrp / mrp.document / website_url (char) : previously in module website +# NOTHING TO DO: falsy analysis, but if anything, handled by ORM + +mrp / mrp.bom / consumption (selection) : now required, req_default: function +mrp / mrp.bom / consumption (selection) : selection_keys is now '['flexible', 'strict', 'warning']' ('['flexible', 'strict']') +# NOTHING TO DO: new default value 'warning' + +mrp / mrp.production / consumption (selection) : NEW required, selection_keys: ['flexible', 'strict', 'warning'], req_default: function, hasdefault +mrp / mrp.workorder / consumption (selection) : selection_keys is now '['flexible', 'strict', 'warning']' ('['flexible', 'strict']') +# NOTHING TO DO: new features + +mrp / mrp.bom / operation_ids (one2many) : NEW relation: mrp.routing.workcenter +mrp / mrp.routing / operation_ids (one2many) : DEL relation: mrp.routing.workcenter +mrp / mrp.routing.workcenter / bom_id (many2one) : NEW relation: mrp.bom +mrp / mrp.routing.workcenter / routing_id (many2one) : DEL relation: mrp.routing, required +# DONE: pre-migration: duplicate mrp.routing.workcenter records and fill bom_id + +mrp / mrp.bom / routing_id (many2one) : DEL relation: mrp.routing +mrp / mrp.bom.byproduct / routing_id (many2one) : DEL relation: mrp.routing +mrp / mrp.bom.line / routing_id (many2one) : DEL relation: mrp.routing +mrp / mrp.production / routing_id (many2one) : DEL relation: mrp.routing +# NOTHING TO DO: mrp.routing model is obsolete + +mrp / mrp.production / _order : _order is now 'priority desc, date_planned_start asc,id' ('date_planned_start asc,id') +# NOTHING TO DO + +mrp / mrp.production / backorder_sequence (integer) : NEW hasdefault +# NOTHING TO DO: new feature + +mrp / mrp.production / date_deadline (datetime) : now a function +mrp / mrp.production / date_start_wo (datetime) : DEL +# NOTHING TO DO + +mrp / mrp.production / lot_producing_id (many2one) : NEW relation: stock.production.lot +mrp / mrp.production / qty_producing (float) : NEW +# NOTHING TO DO: fields from mrp.abstract.workorder (used in old mrp.product.produce wizard) + +mrp / mrp.production / priority (selection) : selection_keys is now '['0', '1']' ('['0', '1', '2', '3']') +# DONE: post-migration: merge 1 to 0, and 2 and 3 to 1 + +mrp / mrp.production / product_description_variants (char): NEW +# TODO: new feature, may be filled in some cases + +mrp / mrp.production / production_location_id (many2one): is now stored +mrp / mrp.production / production_location_id (many2one): not related anymore +mrp / mrp.production / production_location_id (many2one): now a function +# NOTHING TO DO: computed in load + +mrp / mrp.production / propagate_date (boolean) : DEL +mrp / mrp.production / propagate_date_minimum_delta (integer): DEL +# NOTHING TO DO: not used anymore + +mrp / mrp.production / state (selection) : selection_keys is now '['cancel', 'confirmed', 'done', 'draft', 'progress', 'to_close']' ('['cancel', 'confirmed', 'done', 'draft', 'planned', 'progress', 'to_close']') +DONE: post-migration: map 'planned' to 'confirmed'/'progress'/'done' using _compute_state method + +mrp / mrp.routing / active (boolean) : DEL +mrp / mrp.routing / code (char) : DEL +mrp / mrp.routing / company_id (many2one) : DEL relation: res.company +mrp / mrp.routing / name (char) : DEL required +mrp / mrp.routing / note (text) : DEL +# NOTHING TO DO: obsolete model + +mrp / mrp.routing.workcenter / batch (selection) : DEL required, selection_keys: ['no', 'yes'], req_default: function +mrp / mrp.routing.workcenter / batch_size (float) : DEL +# NOTHING TO DO: obsolete + +mrp / mrp.routing.workcenter / company_id (many2one) : not related anymore +# NOTHING TO DO + +mrp / mrp.routing.workcenter / worksheet_type (selection) : selection_keys is now '['google_slide', 'pdf', 'text']' ('['google_slide', 'pdf']') +# NOTHING TO DO: new option 'text' + +mrp / mrp.workorder / activity_ids (one2many) : DEL relation: mail.activity +mrp / mrp.workorder / message_follower_ids (one2many): DEL relation: mail.followers +mrp / mrp.workorder / message_ids (one2many) : DEL relation: mail.message +mrp / mrp.workorder / message_main_attachment_id (many2one): DEL relation: ir.attachment +mrp / mrp.workorder / website_message_ids (one2many): DEL relation: mail.message +# NOTHING TO DO: losing mail mixins + +mrp / mrp.workorder / capacity (float) : DEL +# NOTHING TO DO: unused field + +mrp / mrp.workorder / finished_lot_id (many2one) : not stored anymore +mrp / mrp.workorder / finished_lot_id (many2one) : now a function +mrp / mrp.workorder / qty_producing (float) : not stored anymore +mrp / mrp.workorder / qty_producing (float) : now a function +# NOTHING TO DO: non-stored computes + +mrp / mrp.workorder.line / finished_workorder_id (many2one): DEL relation: mrp.workorder +mrp / mrp.workorder.line / lot_id (many2one) : DEL relation: stock.production.lot +mrp / mrp.workorder.line / move_id (many2one) : DEL relation: stock.move +mrp / mrp.workorder.line / product_id (many2one) : DEL relation: product.product, required +mrp / mrp.workorder.line / product_uom_id (many2one) : DEL relation: uom.uom +mrp / mrp.workorder.line / qty_done (float) : DEL +mrp / mrp.workorder.line / qty_reserved (float) : DEL +mrp / mrp.workorder.line / qty_to_consume (float) : DEL +mrp / mrp.workorder.line / raw_workorder_id (many2one) : DEL relation: mrp.workorder +mrp / mrp.workorder / finished_workorder_line_ids (one2many): DEL relation: mrp.workorder.line +# NOTHING TO DO: obsolete model + +mrp / procurement.group / mrp_production_ids (one2many) : NEW relation: mrp.production +# NOTHING TO DO: one2many + +mrp / stock.move / unit_factor (float) : now a function +# NOTHING TO DO: automatic compute + +mrp / stock.move.line / done_move (boolean) : DEL +mrp / stock.move.line / lot_produced_qty (float) : DEL +# NOTHING TO DO: unused fields + +mrp / stock.move.line / lot_produced_ids (many2many) : DEL relation: stock.production.lot +DONE: post-migration: use stock_move_line_stock_production_lot_rel to fill stock_move_line_consume_rel + +mrp / stock.warehouse.orderpoint / bom_id (many2one) : NEW relation: mrp.bom +# NOTHING TO DO: new feature + +---XML records in module 'mrp'--- +NEW digest.tip: mrp.digest_tip_mrp_0 +NEW ir.actions.act_window: mrp.action_mrp_consumption_warning +NEW ir.actions.act_window: mrp.action_mrp_production_backorder +NEW ir.actions.act_window: mrp.mrp_workorder_mrp_production_form +DEL ir.actions.act_window: mrp.act_mrp_product_produce +DEL ir.actions.act_window: mrp.act_product_mrp_production +DEL ir.actions.act_window: mrp.action_mrp_unbuild_move_line +DEL ir.actions.act_window: mrp.mrp_workcenter_productivity_loss_action +DEL ir.actions.act_window: mrp.mrp_workorder_delta_report +NEW ir.actions.server: mrp.action_production_order_mark_done +NEW ir.actions.server: mrp.mrp_production_action_unreserve_tree +NEW ir.model.access: mrp.access_change_production_qty +NEW ir.model.access: mrp.access_mrp_consumption_warning +NEW ir.model.access: mrp.access_mrp_consumption_warning_line +NEW ir.model.access: mrp.access_mrp_immediate_production +NEW ir.model.access: mrp.access_mrp_immediate_production_line +NEW ir.model.access: mrp.access_mrp_production_backorder +NEW ir.model.access: mrp.access_mrp_production_backorder_line +NEW ir.model.access: mrp.access_stock_warn_insufficient_qty_unbuild +DEL ir.model.access: mrp.access_mrp_resource_manager +DEL ir.model.access: mrp.access_mrp_routing +DEL ir.model.access: mrp.access_mrp_routing_manager +DEL ir.model.access: mrp.access_mrp_workorder_line_mrp_manager +DEL ir.model.access: mrp.access_mrp_workorder_line_mrp_user +NEW ir.ui.menu: mrp.menu_procurement_compute_mrp +DEL ir.ui.menu: mrp.menu_mrp_dashboard +NEW ir.ui.view: mrp.mrp_production_workorder_form_view_inherit_editable +NEW ir.ui.view: mrp.mrp_production_workorder_tree_editable_view +NEW ir.ui.view: mrp.mrp_production_workorder_tree_view +NEW ir.ui.view: mrp.mrp_report_product_product_replenishment +NEW ir.ui.view: mrp.mrp_unbuild_form_view_simplified +NEW ir.ui.view: mrp.stock_report_delivery_document_inherit_mrp +NEW ir.ui.view: mrp.stock_report_delivery_kit_sections +NEW ir.ui.view: mrp.stock_report_delivery_no_kit_section +NEW ir.ui.view: mrp.view_immediate_production +NEW ir.ui.view: mrp.view_mrp_consumption_warning_form +NEW ir.ui.view: mrp.view_mrp_document_form +NEW ir.ui.view: mrp.view_mrp_production_backorder_form +NEW ir.ui.view: mrp.view_stock_move_operations_finished +NEW ir.ui.view: mrp.view_stock_move_operations_raw +NEW ir.ui.view: mrp.view_warehouse_orderpoint_tree_editable_inherited_purchase +DEL ir.ui.view: mrp.mrp_product_produce_line_form +DEL ir.ui.view: mrp.mrp_product_produce_line_kanban +DEL ir.ui.view: mrp.mrp_production_workorder_tree_view_inherit +DEL ir.ui.view: mrp.mrp_routing_form_view +DEL ir.ui.view: mrp.mrp_routing_kanban_view +DEL ir.ui.view: mrp.mrp_routing_search_view +DEL ir.ui.view: mrp.mrp_routing_tree_view +DEL ir.ui.view: mrp.view_document_form +DEL ir.ui.view: mrp.view_finisehd_move_line +DEL ir.ui.view: mrp.view_move_kanban_inherit_mrp +DEL ir.ui.view: mrp.view_mrp_product_produce_wizard +DEL ir.ui.view: mrp.view_stock_move_lots +DEL ir.ui.view: mrp.view_stock_move_raw_tree +NEW res.groups: mrp.group_locked_by_default +# NOTHING TO DO + +DEL ir.rule: mrp.mrp_routing_rule (noupdate) +DEL ir.sequence: mrp.sequence_mrp_route (noupdate) +# DONE: post-migration: safely deleted xmlids