Skip to content
Open
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
20 changes: 12 additions & 8 deletions addons/mrp/migrations/10.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,24 @@ def fill_stock_move_bom_line_id(cr):
cr,
"""
UPDATE stock_move sm_update
SET bom_line_id = mbl.bom_line_id
FROM stock_move sm
SET bom_line_id = q.bom_line_id
FROM (
SELECT sm.id, mbl.bom_line_id
FROM stock_move sm
INNER JOIN mrp_production mp
ON sm.raw_material_production_id = mp.id
LEFT JOIN (
SELECT min(id) AS bom_line_id, bom_id, product_id
FROM mrp_bom_line
GROUP BY bom_id, product_id
) mbl ON (
mbl.bom_id = mp.bom_id
AND mbl.product_id = sm.product_id)
WHERE sm_update.raw_material_production_id = mp.id
AND sm_update.id = sm.id
AND sm_update.bom_line_id IS NULL;
) mbl ON (
mbl.bom_id = mp.bom_id
AND mbl.product_id = sm.product_id
)
WHERE sm.raw_material_production_id = mp.id
AND mbl.bom_line_id IS NOT NULL
Copy link
Member

@StefanRijnhart StefanRijnhart Oct 13, 2022

Choose a reason for hiding this comment

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

I'm pretty sure this bom_line_id IS NOT NULL condition is void here. Is this where the original sm_update.bom_line_id IS NULL landed? (I'm not sure why that was there in the previous version because the field is new in version 10 and here is the only place where it is populated).

-- edit -- oh, it's because the subquery that provides it is left-joined. Makes me think you can take the condition out and apply an inner join.

) q
WHERE sm_update.id = q.id;
"""
)

Expand Down