-
-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c181fb
commit 6819b9b
Showing
5 changed files
with
371 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
openupgrade_scripts/scripts/mrp/14.0.2.0/noupdate_changes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
openupgrade_scripts/scripts/mrp/14.0.2.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
107
openupgrade_scripts/scripts/mrp/14.0.2.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.