Skip to content

Commit

Permalink
shopfloor_reception: fix auto post option
Browse files Browse the repository at this point in the history
When 2 users work on the same move and one user completes his picking,
The move containing the quantity left to do could not be switch back
to assigned.
  • Loading branch information
TDu committed Nov 29, 2023
1 parent 20560a6 commit 8e35df0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
11 changes: 11 additions & 0 deletions shopfloor_reception/services/reception.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,17 @@ def _auto_post_line(self, selected_line):
new_move._action_confirm(merge=False)
new_move._recompute_state()
new_move._action_assign()
# Set back the quantity to do on one of the lines
line = fields.first(
move.move_line_ids.filtered(
lambda line: line.state not in ("cancel", "done")
)
)
if line:
move_quantity = move.product_uom._compute_quantity(
move.product_uom_qty, line[0].product_uom_id
)
line.product_uom_qty = move_quantity
move._recompute_state()
new_move.extract_and_action_done()

Expand Down
51 changes: 49 additions & 2 deletions shopfloor_reception/tests/test_set_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,54 @@ def test_auto_posting(self):
line_in_picking = picking.move_line_ids.filtered(
lambda l: l.product_id == selected_move_line.product_id
)
# New created line always quantity to do at zero
self.assertEqual(line_in_picking.product_uom_qty, 0)
self.assertEqual(line_in_picking.product_uom_qty, 7)
self.assertEqual(line_in_picking.qty_done, 0)
self.assertEqual(picking.state, "assigned")

def test_auto_posting_concurent_work(self):
"""Check 2 users working on the same move.
With the auto post line option On.
"""
self.menu.sudo().auto_post_line = True
picking = self._create_picking(lines=[(self.product_a, 10)])
move = picking.move_lines
# User 1 starts working
service_u1 = self.service
res_u1 = service_u1.dispatch(
"manual_select_move",
params={"move_id": move.id},
)
# User 2 starts working on the same move
service_u2 = self._get_service_for_user(self.shopfloor_manager)
service_u2.dispatch(
"manual_select_move",
params={"move_id": move.id},
)
self.assertEqual(len(move.move_line_ids), 2)
# User 1 finishes his work
move_line_data = res_u1["data"]["set_quantity"]["selected_move_line"][0]
line_id_u1 = move_line_data["id"]
qty_done_u1 = move_line_data["qty_done"]
res_u1 = service_u1.dispatch(
"process_without_pack",
params={
"picking_id": picking.id,
"selected_line_id": line_id_u1,
"quantity": qty_done_u1,
},
)
res_u1 = service_u1.dispatch(
"set_destination",
params={
"picking_id": picking.id,
"selected_line_id": line_id_u1,
"location_name": self.dispatch_location.name,
},
)
# With the auto post line option
# The work done is moved and done in a specific transfer
self.assertEqual(picking.state, "assigned")
# So the quantity left to do on the current move has decreased
self.assertEqual(move.product_uom_qty, 9)
8 changes: 3 additions & 5 deletions shopfloor_reception/tests/test_set_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,15 +730,13 @@ def test_concurrent_update_2(self):
)
# After move_line is posted, its state is done, and its qty_done is 1.0
self.assertEqual(move_line_user_1.state, "done")

# The remaining one is still to be done
self.assertEqual(move_line_user_2.state, "confirmed")
self.assertEqual(move_line_user_2.state, "assigned")
# As well as the new one
self.assertEqual(len(lines_after), 1)
# The total remaining qty to be done on line is always zero
# Because it is computed in the frontend
# The quantity to do is set on 1 of the lines
self.assertEqual(lines_after.product_uom_qty, 0)
self.assertEqual(move_line_user_2.product_uom_qty, 0)
self.assertEqual(move_line_user_2.product_uom_qty, 9)

def test_move_states(self):
# as only assigned moves can be posted, we need to ensure that
Expand Down

0 comments on commit 8e35df0

Please sign in to comment.