Skip to content

Commit

Permalink
shopfloor_reception: improve move lign assignation to user
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Nov 8, 2023
1 parent d855784 commit f32f528
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions shopfloor_reception/services/reception.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,28 @@ 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.shopfloor_user_id.id == self.env.uid:
line = move_line
break

Check warning on line 261 in shopfloor_reception/services/reception.py

View check run for this annotation

Codecov / codecov/patch

shopfloor_reception/services/reception.py#L260-L261

Added lines #L260 - L261 were not covered by tests
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 f32f528

Please sign in to comment.