Skip to content

Commit d469448

Browse files
committed
stock_picking_batch_creation: fix stock device order
Before this change when searching for a device to use for the batch, the order of the devices was not guaranteed although important. And it could cause some batch split not happening. Now the possible devices will be sorted by their default order, which is by sequence and name.
1 parent f8ffab7 commit d469448

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

stock_picking_batch_creation/tests/test_get_device_to_use.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,67 @@ def test_get_device_to_use_filter_pickings(self):
213213
self.assertEqual(first_picking, self.pick1)
214214
device = make_picking_batch._compute_device_to_use(first_picking)
215215
self.assertEqual(device, self.device1)
216+
217+
def test_device_used_for_first_picking_splitting_00(self):
218+
"""Check the last device is used for splitting the first picking.
219+
220+
Default order is :: device3, device2, device1.
221+
The last device (device1) can not manage the only picking.
222+
So the picking will be split.
223+
224+
"""
225+
# Keep only one picking and a heavy one
226+
self.pick1.action_cancel()
227+
self.pick2.action_cancel()
228+
product_big_1 = self._create_product("Unittest P1 voluminous", 10, 100, 1, 1)
229+
self._set_quantity_in_stock(self.stock_location, product_big_1)
230+
self._add_product_to_picking(self.pick3, product_big_1)
231+
make_picking_batch = self.make_picking_batch.create(
232+
{
233+
"user_id": self.env.user.id,
234+
"picking_type_ids": [(4, self.picking_type_1.id)],
235+
"split_picking_exceeding_limits": True,
236+
# Add the device not in their default sort order
237+
"stock_device_type_ids": [
238+
(4, self.device1.id),
239+
(4, self.device2.id),
240+
(4, self.device3.id),
241+
],
242+
}
243+
)
244+
first_picking = make_picking_batch._get_first_picking()
245+
# A split picking has been created
246+
self.assertTrue(first_picking != self.pick3)
247+
248+
def test_device_used_for_first_picking_splitting_01(self):
249+
"""Check the last device is used for splitting the first picking.
250+
251+
The last device (device2) can manage the only picking.
252+
So picking will not be split.
253+
254+
"""
255+
# Keep only one picking and a heavy one.
256+
self.pick1.action_cancel()
257+
self.pick2.action_cancel()
258+
product_big_1 = self._create_product("Unittest P1 voluminous", 10, 100, 1, 1)
259+
self._set_quantity_in_stock(self.stock_location, product_big_1)
260+
self._add_product_to_picking(self.pick3, product_big_1)
261+
# Set the device order
262+
self.device1.sequence = 10
263+
self.device3.sequence = 20
264+
self.device2.sequence = 30
265+
make_picking_batch = self.make_picking_batch.create(
266+
{
267+
"user_id": self.env.user.id,
268+
"picking_type_ids": [(4, self.picking_type_1.id)],
269+
"split_picking_exceeding_limits": True,
270+
# Add the device not in their default sort order
271+
"stock_device_type_ids": [
272+
(4, self.device1.id),
273+
(4, self.device2.id),
274+
(4, self.device3.id),
275+
],
276+
}
277+
)
278+
first_picking = make_picking_batch._get_first_picking()
279+
self.assertEqual(first_picking, self.pick3)

stock_picking_batch_creation/wizards/make_picking_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _execute_search_pickings(self, domain, limit=None):
263263
)
264264

265265
def _split_first_picking_for_limit(self, picking):
266-
last_device = self.stock_device_type_ids[-1]
266+
last_device = self.stock_device_type_ids.sorted()[-1]
267267
if last_device.split_mode == "dimension":
268268
return (
269269
self.env["stock.split.picking"]
@@ -291,7 +291,7 @@ def _is_picking_exceeding_limits(self, picking):
291291
):
292292
return True
293293
# Then, check the device limits
294-
last_device = self.stock_device_type_ids[-1]
294+
last_device = self.stock_device_type_ids.sorted()[-1]
295295
if last_device.split_mode == "dimension":
296296
if last_device.max_volume and picking.volume > last_device.max_volume:
297297
return True
@@ -363,7 +363,7 @@ def _get_remaining_volume(self, partner=False):
363363
return remaining_volume
364364

365365
def _compute_device_to_use(self, picking):
366-
for device in self.stock_device_type_ids.sorted("sequence"):
366+
for device in self.stock_device_type_ids.sorted():
367367
if picking.filtered_domain(self._get_picking_domain_for_device(device)):
368368
return device
369369
return self.env["stock.device.type"]

0 commit comments

Comments
 (0)