Skip to content

Commit

Permalink
shopfloor_reception: improve move line assignation to user
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Nov 27, 2023
1 parent 7ec0522 commit ee88c38
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions shopfloor_reception/services/reception.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,30 @@ def _select_document_from_lot(self, lot):
)

def _scan_line__find_or_create_line(self, picking, move, qty_done=1):
line = fields.first(
move.move_line_ids.filtered(
lambda l: (
not l.result_package_id
and l.shopfloor_user_id.id in [False, self.env.uid]
)
)
)
"""Find or create a line on a move for the user to work on.
First try to find a line already assigned to the user.
Then a line that is not yet assigned to any users (locking the line
to avoid concurent access.)
If none are found create a new line.
"""
line = None
unassigned_lines = self.env["stock.move.line"]
for move_line in move.move_line_ids:
if move_line.result_package_id:
continue
if move_line.shopfloor_user_id.id == self.env.uid:
line = move_line
break
elif not move_line.shopfloor_user_id:
unassigned_lines |= move_line
if not line and unassigned_lines:
lock = self._actions_for("lock")
for move_line in unassigned_lines:
if lock.for_update(move_line, skip_locked=True):
line = move_line
break
if not line:
values = move._prepare_move_line_vals()
line = self.env["stock.move.line"].create(values)
Expand Down

0 comments on commit ee88c38

Please sign in to comment.