Skip to content

Commit

Permalink
[MIG] mrp
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Jan 13, 2022
1 parent 4c181fb commit 6819b9b
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docsource/modules130-140.rst
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Module coverage 13.0 -> 14.0
+--------------------------------------------+-------------------------------------------------+
| |new| microsoft_calendar | |
+--------------------------------------------+-------------------------------------------------+
|mrp | |
|mrp | Done |
+--------------------------------------------+-------------------------------------------------+
|mrp_account | |
+--------------------------------------------+-------------------------------------------------+
Expand Down
18 changes: 9 additions & 9 deletions openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="mrp_bom_byproduct_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_bom_line_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_bom_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_production_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_routing_workcenter_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_unbuild_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_workcenter_productivity" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_workcenter_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
<record id="mrp_workorder_rule" model="ir.rule">
<field name="global"/>
<!-- <field name="global"/>-->
</record>
</odoo>
56 changes: 56 additions & 0 deletions openupgrade_scripts/scripts/mrp/14.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2021 ForgeFlow S.L. <https://www.forgeflow.com>
# 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"]
)
107 changes: 107 additions & 0 deletions openupgrade_scripts/scripts/mrp/14.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2021 ForgeFlow S.L. <https://www.forgeflow.com>
# 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)
Loading

0 comments on commit 6819b9b

Please sign in to comment.