Skip to content

Commit

Permalink
Merge pull request #4 from sebalix/13.0-stock_picking_group_by_partne…
Browse files Browse the repository at this point in the history
…r_by_carrier-imp2

[FIX] stock_picking_group_by_partner_by_carrier: add a hook to handle domain on move_type
  • Loading branch information
jgrandguillaume authored Jun 2, 2020
2 parents 7e1e758 + 63a668b commit 609bfe4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
10 changes: 8 additions & 2 deletions stock_picking_group_by_partner_by_carrier/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def _search_picking_for_assignation(self):
)
return picking

def _domain_search_picking_handle_move_type(self):
"""Hook to handle the move type. Can be overloaded by other modules.
By default the move type is taken from the procurement group.
"""
# avoid mixing picking policies
return [("move_type", "=", self.group_id.move_type)]

def _domain_search_picking_for_assignation(self):
states = ("draft", "confirmed", "waiting", "partially_available", "assigned")
if (
Expand All @@ -51,10 +58,9 @@ def _domain_search_picking_for_assignation(self):
domain = [
# same partner
("partner_id", "=", self.group_id.partner_id.id),
# avoid mixing picking policies
("move_type", "=", self.group_id.move_type),
# don't search on the procurement.group
]
domain += self._domain_search_picking_handle_move_type()
# same carrier only for outgoing transfers
if self.picking_type_id.code == "outgoing":
domain += [
Expand Down
33 changes: 33 additions & 0 deletions stock_picking_group_by_partner_by_carrier/tests/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,39 @@ def test_delivery_multi_step_group_pick(self):
self.assertEqual(len(picks), 1)
self.assertFalse(so1.picking_ids - so2.picking_ids)

def test_delivery_multi_step_group_pick_pack(self):
"""the warehouse uses pick + pack + ship (with grouping enabled on pack)
-> shippings are grouped, as well as pickings"""
warehouse = self.env.ref("stock.warehouse0")
warehouse.delivery_steps = "pick_pack_ship"
warehouse.pick_type_id.group_pickings = False
warehouse.pack_type_id.group_pickings = True
so1 = self._get_new_sale_order(carrier=self.carrier1)
so1.action_confirm()
so2 = self._get_new_sale_order(amount=11, carrier=self.carrier1)
so2.action_confirm()
self.assertEqual(len(so1.picking_ids), 3)
self.assertEqual(len(so2.picking_ids), 3)
# ship & pack should be shared between so1 and so2, but not pick
all_transfers = so1.picking_ids | so2.picking_ids
common_transfers = so1.picking_ids & so2.picking_ids
self.assertEqual(len(all_transfers), 4)
self.assertEqual(len(common_transfers), 2)
ships = all_transfers.filtered(
lambda o: o.picking_type_id == warehouse.out_type_id
)
packs = all_transfers.filtered(
lambda o: o.picking_type_id == warehouse.pack_type_id
)
picks = all_transfers.filtered(
lambda o: o.picking_type_id == warehouse.pick_type_id
)
self.assertEqual(len(ships), 1)
self.assertEqual(len(packs), 1)
self.assertEqual(len(picks), 2)
self.assertTrue(so1.picking_ids - so2.picking_ids)

def test_delivery_multi_step_cancel_so1(self):
"""the warehouse uses pick + ship. Cancel SO1
Expand Down

0 comments on commit 609bfe4

Please sign in to comment.