From 9d6c04e67b9932b9f14fea226dbec719d88c3650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Fri, 27 Nov 2020 09:44:37 +0100 Subject: [PATCH] [FIX] shopfloor, checkout: ability to recover/restart If the user starts to process a line, and for whatever reason he stops there and restarts the scenario from the beginning, he should still be able to find/recover the previous line. For that purpose we are using the `shopfloor_user_id` field on move lines (already used to manage currently processed lines in the Zone picking and Location content transfer scenarios). --- shopfloor/services/checkout.py | 9 ++++++-- shopfloor/tests/test_checkout_scan.py | 31 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/shopfloor/services/checkout.py b/shopfloor/services/checkout.py index fe45bd74a1..e2e63626bf 100644 --- a/shopfloor/services/checkout.py +++ b/shopfloor/services/checkout.py @@ -296,13 +296,16 @@ def _select_lines(self, lines): if line.shopfloor_checkout_done: continue line.qty_done = line.product_uom_qty + line.shopfloor_user_id = self.env.user picking = lines.mapped("picking_id") other_lines = picking.move_line_ids - lines self._deselect_lines(other_lines) def _deselect_lines(self, lines): - lines.filtered(lambda l: not l.shopfloor_checkout_done).qty_done = 0 + lines.filtered(lambda l: not l.shopfloor_checkout_done).write( + {"qty_done": 0, "shopfloor_user_id": False} + ) def scan_line(self, picking_id, barcode): """Scan move lines of the stock picking @@ -598,7 +601,9 @@ def _switch_line_qty_done(self, picking, selected_lines, switch_lines): @staticmethod def _filter_lines_unpacked(move_line): - return move_line.qty_done == 0 and not move_line.shopfloor_checkout_done + return ( + move_line.qty_done == 0 or move_line.shopfloor_user_id + ) and not move_line.shopfloor_checkout_done @staticmethod def _filter_lines_to_pack(move_line): diff --git a/shopfloor/tests/test_checkout_scan.py b/shopfloor/tests/test_checkout_scan.py index 1af8473da2..6cc8c5708c 100644 --- a/shopfloor/tests/test_checkout_scan.py +++ b/shopfloor/tests/test_checkout_scan.py @@ -128,3 +128,34 @@ def test_scan_document_error_location_several_pickings(self): " or select a transfer manually.", }, ) + + def test_scan_document_recover(self): + """If the user starts to process a line, and for whatever reason he + stops there and restarts the scenario from the beginning, he should + still be able to find the previous line. + """ + picking = self._create_picking() + self._fill_stock_for_moves(picking.move_lines, in_package=True) + picking.action_assign() + package = picking.move_line_ids.package_id + # The user selects a line, then stops working in the middle of the process + response = self.service.dispatch( + "scan_document", params={"barcode": package.name} + ) + data = response["data"]["select_line"] + self.assertEqual(data["picking"]["move_line_count"], 2) + self.assertEqual(len(data["picking"]["move_lines"]), 2) + self.assertFalse(picking.move_line_ids.shopfloor_user_id) + response = self.service.dispatch( + "select_line", params={"picking_id": picking.id, "package_id": package.id}, + ) + self.assertTrue(all(l.qty_done for l in picking.move_line_ids)) + self.assertEqual(picking.move_line_ids.shopfloor_user_id, self.env.user) + # He restarts the scenario and try to select again the previous line + # to continue its job + response = self.service.dispatch( + "scan_document", params={"barcode": package.name} + ) + data = response["data"]["select_line"] + self.assertEqual(data["picking"]["move_line_count"], 2) + self.assertEqual(len(data["picking"]["move_lines"]), 2) # Lines found