diff --git a/shopfloor_reception/services/reception.py b/shopfloor_reception/services/reception.py index 89e18ba1b41..e38bb88e822 100644 --- a/shopfloor_reception/services/reception.py +++ b/shopfloor_reception/services/reception.py @@ -1299,6 +1299,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 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..63ffcea4494 100644 --- a/shopfloor_reception/tests/test_set_destination.py +++ b/shopfloor_reception/tests/test_set_destination.py @@ -152,3 +152,51 @@ def test_auto_posting(self): self.assertEqual(line_in_picking.product_uom_qty, 0) 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)