Skip to content

Commit 943faf3

Browse files
committed
Merge PR #2463 into 15.0
Signed-off-by pedrobaeza
2 parents 741176f + 7427ade commit 943faf3

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

purchase_stock_price_unit_sync/models/purchase_order.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,23 @@ def stock_price_unit_sync(self):
3333
bom_type="phantom",
3434
):
3535
continue
36-
line.move_ids.write({"price_unit": line._get_stock_move_price_unit()})
37-
# Apply sudo() to avoid access errors with users without Inventory > Admin
38-
# permissions.
39-
svls = (
40-
line.move_ids.sudo()
41-
.mapped("stock_valuation_layer_ids")
42-
.filtered(
43-
# Filter children SVLs (like landed cost)
44-
lambda x: not x.stock_valuation_layer_id
36+
moves = line.move_ids.filtered(lambda m: m.state == "done")
37+
if moves:
38+
moves.write({"price_unit": line._get_stock_move_price_unit()})
39+
# Apply sudo() to avoid access errors with users without Inventory > Admin
40+
# permissions.
41+
svls = (
42+
moves.sudo()
43+
.mapped("stock_valuation_layer_ids")
44+
.filtered(
45+
# Filter children SVLs (like landed cost)
46+
lambda x: not x.stock_valuation_layer_id
47+
)
48+
)
49+
svls.write(
50+
{
51+
"unit_cost": line.with_context(
52+
skip_stock_price_unit_sync=True
53+
)._get_stock_move_price_unit(),
54+
}
4555
)
46-
)
47-
svls.write(
48-
{
49-
"unit_cost": line.with_context(
50-
skip_stock_price_unit_sync=True
51-
)._get_stock_move_price_unit(),
52-
}
53-
)

0 commit comments

Comments
 (0)