Skip to content

Commit 4f36ae6

Browse files
committed
stock_split_picking_kit: update reservation if needed
Before this change the reserved quantity could end up being higher than the demand.
1 parent 5562b6a commit 4f36ae6

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

stock_split_picking_kit/tests/test_stock_split_picking_kit.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def setUpClass(cls):
6060
],
6161
}
6262
)
63+
cls.stock_location = cls.env.ref("stock.stock_location_stock")
6364

6465
@classmethod
6566
def _get_kit_quantity(cls, picking, bom):
@@ -73,6 +74,16 @@ def _get_kit_quantity(cls, picking, bom):
7374
)
7475
return kit_quantity
7576

77+
@classmethod
78+
def _set_quantity_in_stock(cls, location, product, qty=10):
79+
cls.env["stock.quant"].create(
80+
{
81+
"location_id": location.id,
82+
"product_id": product.id,
83+
"inventory_quantity": qty,
84+
}
85+
).action_apply_inventory()
86+
7687
def _check_move_lines(self, picking, move_lines):
7788
moves = []
7889
for move in picking.move_ids:
@@ -127,6 +138,34 @@ def test_split_picking_kit_single_split(self):
127138
"1 kit is left in the original picking",
128139
)
129140

141+
def test_split_assigned_picking_kit_single_split(self):
142+
"""Check reservation is decreased if needed.
143+
144+
Number of kits is 3 and the split limit is 2.
145+
146+
"""
147+
self._set_quantity_in_stock(
148+
self.stock_location, self.product_garden_table_leg, qty=12
149+
)
150+
self._set_quantity_in_stock(
151+
self.stock_location, self.product_garden_table_top, qty=3
152+
)
153+
picking = self._create_picking()
154+
self._create_stock_move(self.product_garden_table, picking, qty=3)
155+
picking.action_confirm()
156+
picking.action_assign()
157+
self.assertEqual(picking.state, "assigned")
158+
self.assertEqual(picking.move_ids.mapped("quantity"), [12.0, 3.0])
159+
160+
with RecordCapturer(self.env["stock.picking"], []) as rc_picking:
161+
self._split_picking(picking, mode="kit_quantity", kit_split_quantity=2)
162+
new_picking = rc_picking.records
163+
164+
self.assertEqual(new_picking.state, "assigned", "New picking is assigned")
165+
self.assertEqual(picking.state, "assigned", "Original picking is assigned")
166+
self.assertEqual(picking.move_ids.mapped("quantity"), [4.0, 1.0])
167+
self.assertEqual(new_picking.move_ids.mapped("quantity"), [8.0, 2.0])
168+
130169
def test_split_picking_kit_with_no_kit(self):
131170
"""Check split picking only has non kit product.
132171

stock_split_picking_kit/wizards/stock_split_picking.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def _apply_kit_quantity(self):
6666
rounding_method="HALF-UP",
6767
)
6868
)
69+
# Update reserved quantity if needed
70+
if move.quantity > move.product_qty:
71+
move.quantity = move.product_qty
6972
# If we got this far, we've consumed all the todo_qty
7073
todo_qty = 0
7174
break
@@ -96,6 +99,9 @@ def _apply_kit_quantity(self):
9699
rounding_method="HALF-UP",
97100
)
98101
)
102+
# Update reserved quantity if needed
103+
if move.quantity > move.product_qty:
104+
move.quantity = move.product_qty
99105
# If we got this far, we've consumed all the todo_qty
100106
todo_qty = 0
101107
break

0 commit comments

Comments
 (0)