Skip to content
Merged
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions addons/mrp/migrations/13.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,40 @@ def fill_planned_datetime(env):
""")


def fill_stock_move_bom_line_id(env):
"""v13 added a new functionality to this bom_line_id field.
A part from the usual value for raw moves in mrp productions,
now this field has a value for delivery moves generated from a kit.
See _prepare_phantom_move_values method, that has bom_line_id field."""
openupgrade.logged_query(
env.cr, """
UPDATE stock_move sm0
SET bom_line_id = mbl0.id
FROM (
SELECT moves.id, moves.product_id,
(array_agg(moves.bom_id))[1] as bom_id
FROM (
SELECT sm.id, mb.id AS bom_id, sm.product_id
FROM stock_move sm
JOIN stock_picking_type spt ON (
sm.picking_type_id = spt.id AND spt.code = 'outgoing')
JOIN product_product pp ON sm.product_id = pp.id
JOIN product_template pt ON (
pp.product_tmpl_id = pt.id AND pt.type != 'service')
JOIN mrp_bom_line mbl ON mbl.product_id = pp.id
JOIN mrp_bom mb ON (mbl.bom_id = mb.id
AND (mb.company_id IS NULL OR mb.company_id = sm.company_id)
AND mb.type = 'phantom')
WHERE sm.bom_line_id IS NULL
ORDER BY sm.id, mb.sequence, mb.product_id
) moves
GROUP BY moves.id, moves.product_id
) rel
JOIN mrp_bom_line mbl0 ON (
rel.bom_id = mbl0.bom_id AND mbl0.product_id = rel.product_id)
WHERE sm0.id = rel.id""")


@openupgrade.migrate()
def migrate(env, version):
fill_bom_product_template_attribute_value(env)
Expand All @@ -290,3 +324,4 @@ def migrate(env, version):
enable_group_mrp_byproducts(env)
generate_wo_line(env)
fill_planned_datetime(env)
fill_stock_move_bom_line_id(env)