Skip to content

Commit

Permalink
Merge PR #84 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Jan 13, 2021
2 parents 8605bb9 + 9d6c04e commit eefd149
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions shopfloor/services/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions shopfloor/tests/test_checkout_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eefd149

Please sign in to comment.