From 348faa1fa187117910ba86b47239951bf1e25661 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Thu, 16 Nov 2023 15:07:27 +0100 Subject: [PATCH] shopfloor_reception: fix auto post option 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. --- shopfloor_reception/services/reception.py | 11 ++++ .../tests/test_set_destination.py | 51 ++++++++++++++++++- .../tests/test_set_quantity.py | 8 ++- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/shopfloor_reception/services/reception.py b/shopfloor_reception/services/reception.py index c1ebb4959e5..0687aa532d3 100644 --- a/shopfloor_reception/services/reception.py +++ b/shopfloor_reception/services/reception.py @@ -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() diff --git a/shopfloor_reception/tests/test_set_destination.py b/shopfloor_reception/tests/test_set_destination.py index dc4a20e02ea..802f6d4b02e 100644 --- a/shopfloor_reception/tests/test_set_destination.py +++ b/shopfloor_reception/tests/test_set_destination.py @@ -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) diff --git a/shopfloor_reception/tests/test_set_quantity.py b/shopfloor_reception/tests/test_set_quantity.py index 98fbdc5373f..2c503855438 100644 --- a/shopfloor_reception/tests/test_set_quantity.py +++ b/shopfloor_reception/tests/test_set_quantity.py @@ -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