Skip to content

Commit

Permalink
zone_picking/unload_set_destination: fix move.state = partially_avail…
Browse files Browse the repository at this point in the history
…able handling
  • Loading branch information
simahawk committed Oct 19, 2020
1 parent 77968d9 commit d6aa35b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
13 changes: 11 additions & 2 deletions shopfloor/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ def split_other_move_lines(self, move_lines, intersection=False):
other_move_lines = self.move_line_ids & move_lines
else:
other_move_lines = self.move_line_ids - move_lines
if other_move_lines:
qty_to_split = sum(other_move_lines.mapped("product_uom_qty"))
if other_move_lines or self.state == "partially_available":
if intersection:
# TODO @sebalix: please check if we can abandon the flag.
# Thi behavior can be achieved by passing all move lines
# as done at zone_picking.py:1293
qty_to_split = sum(other_move_lines.mapped("product_uom_qty"))
else:
qty_to_split = self.product_uom_qty - sum(
move_lines.mapped("product_uom_qty")
)
backorder_move_id = self._split(qty_to_split)
backorder_move = self.browse(backorder_move_id)
backorder_move.move_line_ids = other_move_lines
backorder_move._recompute_state()
backorder_move._action_assign()
self._recompute_state()
return backorder_move
return False

Expand Down
7 changes: 7 additions & 0 deletions shopfloor/services/zone_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,16 @@ def unload_set_destination(
self._write_destination_on_lines(buffer_lines, location)
# set lines to done + refresh buffer lines (should be empty)
moves = buffer_lines.mapped("move_id")
# split move lines to a backorder move
# if quantity is not fully satisfied
for move in moves:
move.split_other_move_lines(buffer_lines & move.move_line_ids)

moves.extract_and_action_done()
buffer_lines = self._find_buffer_move_lines(zone_location, picking_type)

if buffer_lines:
# TODO: return success message if line has been processed
return self._response_for_unload_single(
zone_location, picking_type, first(buffer_lines)
)
Expand Down
76 changes: 76 additions & 0 deletions shopfloor/tests/test_zone_picking_unload_set_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ class ZonePickingUnloadSetDestinationCase(ZonePickingCommonCase):
"""

@classmethod
def setUpClassBaseData(cls, *args, **kwargs):
super().setUpClassBaseData(*args, **kwargs)
cls.product_g = (
cls.env["product.product"]
.sudo()
.create(
{
"name": "Product G",
"type": "product",
"default_code": "G",
"barcode": "G",
"weight": 7,
}
)
)
cls.picking_g = cls._create_picking(lines=[(cls.product_g, 40)])
cls._update_qty_in_location(cls.zone_sublocation1, cls.product_g, 32)

def test_unload_set_destination_wrong_parameters(self):
zone_location = self.zone_location
picking_type = self.picking1.picking_type_id
Expand Down Expand Up @@ -300,3 +319,60 @@ def test_unload_set_destination_ok_buffer_not_empty(self):
buffer_line,
popup=completion_info_popup,
)

def test_unload_set_destination_partially_available_backorder(self):
zone_location = self.zone_location
picking_type = self.picking_g.picking_type_id
self.assertEqual(self.picking_g.move_lines[0].product_uom_qty, 40)
self.picking_g.action_assign()
move_line = self.picking_g.move_line_ids
self.assertEqual(move_line.product_uom_qty, 32)
self.assertEqual(move_line.move_id.state, "partially_available")
packing_sublocation = (
self.env["stock.location"]
.sudo()
.create(
{
"name": "Packing sublocation",
"location_id": self.packing_location.id,
"barcode": "PACKING_SUBLOCATION",
}
)
)
# set the destination package
self.service._set_destination_package(
zone_location,
picking_type,
move_line,
move_line.product_uom_qty,
self.free_package,
)
response = self.service.dispatch(
"unload_set_destination",
params={
"zone_location_id": zone_location.id,
"picking_type_id": picking_type.id,
"package_id": self.free_package.id,
"barcode": packing_sublocation.barcode,
"confirmation": True,
},
)
# check data
# move line has been moved to a new picking
self.assertEqual(move_line.move_id.picking_id, self.picking_g.backorder_ids[0])
# the old picking contains a new line w/ the rest of the qty
# that couldn't be processed
self.assertEqual(self.picking_g.move_lines[0].product_uom_qty, 8)
self.assertEqual(self.picking_g.state, "confirmed")
# the line has been processed
self.assertEqual(move_line.location_dest_id, packing_sublocation)
self.assertEqual(move_line.move_id.state, "done")
# check response
move_lines = self.service._find_location_move_lines(zone_location, picking_type)
self.assert_response_select_line(
response,
zone_location,
picking_type,
move_lines,
message=self.service.msg_store.buffer_complete(),
)

0 comments on commit d6aa35b

Please sign in to comment.