Skip to content

Commit 9ffab67

Browse files
fixup! [FIX] repair_type: migration script
1 parent 23b587b commit 9ffab67

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

repair_type/migrations/17.0.1.0.0/post-migration.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,37 @@
66

77
@openupgrade.migrate()
88
def migrate(env, version):
9+
if not openupgrade.table_exists(env.cr, "repair_type"):
10+
return
11+
openupgrade.logged_query(
12+
env.cr,
13+
"""
14+
ALTER TABLE stock_picking_type
15+
ADD COLUMN old_repair_type_id_legacy INTEGER;
16+
""",
17+
)
918
openupgrade.logged_query(
1019
env.cr,
1120
"""
1221
INSERT INTO stock_picking_type
1322
(create_date, default_location_dest_id, default_remove_location_dest_id,
14-
name,default_add_location_src_id, default_remove_location_src_id)
23+
name,default_add_location_src_id, default_remove_location_src_id,
24+
old_repair_type_id_legacy)
1525
SELECT create_date, destination_location_add_part_id,
16-
destination_location_remove_part_id, name::jsonb,
17-
source_location_add_part_id, source_location_remove_part_id
26+
destination_location_remove_part_id, jsonb_build_object('en_US', name) as name,
27+
source_location_add_part_id, source_location_remove_part_id, id
1828
FROM repair_type;
1929
""",
2030
)
31+
openupgrade.logged_query(
32+
env.cr,
33+
"""
34+
UPDATE repair_order ro
35+
SET picking_type_id = spt.id
36+
FROM stock_picking_type spt
37+
WHERE ro.repair_type_id = spt.old_repair_type_id_legacy;
38+
""",
39+
)
2140
openupgrade.logged_query(
2241
env.cr,
2342
"""

0 commit comments

Comments
 (0)