Skip to content

Commit 0bcdb85

Browse files
committed
Merge PR #2544 into 18.0
Signed-off-by LoisRForgeFlow
2 parents 315c9de + f942620 commit 0bcdb85

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

stock_move_purchase_uom/models/stock_move.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def create(self, vals_list):
2424
rounding_method=move.picking_type_id.purchase_uom_rounding_method,
2525
)
2626
move.product_uom = move.product_id.uom_po_id
27-
move.product_uom_qty = updated_product_uom_qty
27+
move.with_context(
28+
do_not_unreserve=True
29+
).product_uom_qty = updated_product_uom_qty
2830
return moves
2931

3032
@api.onchange("product_id", "picking_type_id")

stock_move_purchase_uom/tests/test_stock_move.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
3+
from odoo import Command
34
from odoo.tests import Form
45

56
from .test_common import TestCommon
@@ -99,3 +100,42 @@ def test_create_move_same_uom_rounding_half_up(self):
99100
}
100101
)
101102
self.assertEqual(move.product_uom_qty, 5.0)
103+
104+
def test_create_move_linked_sml_not_unreserved(self):
105+
# The UoM conversion in create must not trigger unreservation of
106+
# explicitly linked SML
107+
sml = self.env["stock.move.line"].create(
108+
{
109+
"product_id": self.product.id,
110+
"product_uom_id": self.cm_uom.id,
111+
"quantity": 70,
112+
"location_id": self.location.id,
113+
"location_dest_id": self.location_dest.id,
114+
"company_id": self.env.company.id,
115+
}
116+
)
117+
move = self.env["stock.move"].create(
118+
{
119+
"name": self.product.display_name,
120+
"location_id": self.location.id,
121+
"location_dest_id": self.location_dest.id,
122+
"product_id": self.product.id,
123+
"product_uom_qty": 30,
124+
"product_uom": self.cm_uom.id,
125+
"picking_type_id": self.stock_picking_type_2.id,
126+
"state": "assigned",
127+
"move_line_ids": [Command.link(sml.id)],
128+
}
129+
)
130+
self.assertTrue(sml.exists())
131+
self.assertEqual(sml.move_id, move)
132+
# UoM was converted on the SM but not on the SML
133+
self.assertEqual(move.product_uom, self.meter_uom)
134+
self.assertEqual(sml.product_uom_id, self.cm_uom)
135+
# SML quantity is unchanged (70 cm)
136+
self.assertEqual(sml.quantity, 70)
137+
# SM demand converted: 30 cm --> 0.3 m
138+
self.assertEqual(move.product_uom_qty, 0.3)
139+
# SM reserved qty is computed from SML: 70 cm --> 0.7 m
140+
# Quantities are coherent, but SML is kept as original
141+
self.assertEqual(move.quantity, 0.7)

0 commit comments

Comments
 (0)