Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules170-180.rst
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ Module coverage 17.0 -> 18.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| microsoft_outlook | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| mrp | | |
| mrp |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| mrp_account | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
31 changes: 31 additions & 0 deletions openupgrade_scripts/scripts/mrp/18.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2025 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def mrp_document_to_product_document(env):
"""
mrp.document has been replaced by product.document.
copy all records of mrp_document to product_document, keep a link
"""
link_column = openupgrade.get_legacy_name("mrp_document_id")
openupgrade.add_columns(
env,
[("product.document", link_column, "integer")],
)
openupgrade.logged_query(
env.cr,
f"""
INSERT INTO product_document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think https://github.com/OCA/OpenUpgrade/blob/17.0/openupgrade_scripts/scripts/product/17.0.1.2/post-migration.py#L61 also included the ones in mrp.document. So, in fact, I think we should just check product_document.ir_attachment_id with mpr_document.ir_attachment_id and where is match set attached_on_mrp = 'bom'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IA says:
Selection_4675

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it matter what the v17 migration did? This needs to work for just 17->18 too, so if there's anything to do, it's excluding attachments that are mrp.documents in the v17 migration.

Not sure how the word soup is helpful? We can't do anything about the field because this is set depending on the attachment being created via a bom or not, which we simply don't know, so I think defaulting to hidden is the right thing to do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's excluding attachments that are mrp.documents in the v17 migration.

Exactly, just not set hidden for them.

(ir_attachment_id, active, sequence, {link_column})
SELECT
ir_attachment_id, active, 10-COALESCE(priority, '0')::int, id
FROM mrp_document
""",
)


@openupgrade.migrate()
def migrate(env, version):
mrp_document_to_product_document(env)
36 changes: 36 additions & 0 deletions openupgrade_scripts/scripts/mrp/18.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2025 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

add_columns = [
("product.document", "attached_on_mrp", "char", "hidden"),
]

copy_columns = {
"mrp_production": [
("location_dest_id", "location_final_id", "integer"),
],
}


def mrp_workorder_sequence(env):
"""
Precreate sequence field and fill with operation_id.sequence or 100
"""
openupgrade.add_columns(env, [("mrp.workorder", "sequence", "integer", 100)])
env.cr.execute(
"""
UPDATE mrp_workorder
SET sequence=COALESCE(mrp_routing_workcenter.sequence, mrp_workorder.sequence)
FROM mrp_routing_workcenter
WHERE mrp_workorder.operation_id=mrp_routing_workcenter.id
"""
)
Comment on lines +21 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
openupgrade.add_columns(env, [("mrp.workorder", "sequence", "integer", 100)])
env.cr.execute(
"""
UPDATE mrp_workorder
SET sequence=COALESCE(mrp_routing_workcenter.sequence, mrp_workorder.sequence)
FROM mrp_routing_workcenter
WHERE mrp_workorder.operation_id=mrp_routing_workcenter.id
"""
)
openupgrade.add_columns(env, [("mrp.workorder", "sequence", "integer")])
env.cr.execute(
"""
UPDATE mrp_workorder
SET sequence=COALESCE(mrp_routing_workcenter.sequence, mrp_workorder.sequence)
FROM mrp_routing_workcenter
WHERE mrp_workorder.operation_id=mrp_routing_workcenter.id
"""
)
env.cr.execute(
"""
SELECT COALESCE(max(sequence), 0) AS max_sequence
FROM mrp_workorder
WHERE sequence IS NOT NULL
"""
)
max_sequence = env.cr.fetchone()[0]
openupgrade.logged_query(
env.cr,
f"""
UPDATE mrp_workorder
SET sequence = {max_sequence} + id::int
WHERE sequence IS NULL""",
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of this? In my version, work orders without operation_id are ordered by leave_id, date_start, id thanks to the default value you propose to delete. How is moving them after all orders with operation_id and enforcing an ordering by id only an improvement?

Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, should we update them by leave_id, date_start, id? 😅



@openupgrade.migrate()
def migrate(env, version):
openupgrade.add_columns(env, add_columns)
openupgrade.copy_columns(env.cr, copy_columns)
mrp_workorder_sequence(env)
103 changes: 103 additions & 0 deletions openupgrade_scripts/scripts/mrp/18.0.2.0/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---Models in module 'mrp'---
obsolete model mrp.document (merged to product.document)

# DONE: copy records from mrp_document to product_document

new model mrp.batch.produce [transient]

# NOTHING TO DO

---Fields in module 'mrp'---
mrp / mrp.document / _inherits : DEL _inherits: {'ir.attachment': 'ir_attachment_id'}, stored: False
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: see above

mrp / mrp.production / location_final_id (many2one) : NEW relation: stock.location

# DONE: copy from location_dest_id

mrp / mrp.production / never_product_template_attribute_value_ids (many2many): NEW relation: product.template.attribute.value

# NOTHING TO DO: new feature

mrp / mrp.production / search_date_category (selection): NEW selection_keys: ['after', 'before', 'day_1', 'day_2', 'today', 'yesterday'], stored: False

# NOTHING TO DO: virtual search field

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: mail/activity mixin added, new feature

mrp / mrp.unbuild / bom_id (many2one) : now a function
mrp / mrp.unbuild / lot_id (many2one) : now a function

# NOTHING TO DO: function are defaults

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: mail mixin added, new feature

mrp / mrp.workorder / _order : _order is now 'sequence, leave_id, date_start, id' ('leave_id, date_start, id')

# DONE: set from operation_id.sequence

mrp / mrp.workorder / production_date (datetime) : not related anymore
mrp / mrp.workorder / production_date (datetime) : now a function

# NOTHING TO DO

mrp / mrp.workorder / sequence (integer) : NEW hasdefault: default

# DONE: see above

mrp / product.document / attached_on_mrp (selection) : NEW required, selection_keys: ['bom', 'hidden'], hasdefault: default

# NOTHING TO DO: we can't detect if a document has been attached via the bom or the product itself, so we keep the default 'hidden'

mrp / stock.move / manual_consumption (boolean) : not a function anymore

# NOTHING TO DO: can be edited manually now

mrp / stock.picking.type / use_auto_consume_components_lots (boolean): DEL

# NOTHING TO DO: replaced by manual_consumption being manually editable above

---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
DEL ir.actions.act_window: mrp.act_assign_serial_numbers_production
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
DEL ir.ui.view: mrp.mrp_workorder_view_gantt
DEL ir.ui.view: mrp.view_assign_serial_numbers_production
DEL ir.ui.view: mrp.view_document_file_kanban_mrp
DEL ir.ui.view: mrp.view_mrp_document_form
DEL ir.ui.view: mrp.workcenter_line_gantt_production
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