Skip to content

Commit

Permalink
[FIX] make changes processing code more obvious
Browse files Browse the repository at this point in the history
  • Loading branch information
huguesdk committed Nov 1, 2024
1 parent a1d1d9f commit 4a08b6e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions beesdoo_shift_swap/models/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ def _prepare_task_day(self):

swap_subscription_done = []
for shift in shifts:
for rec in list(changes):
shift, swap_subscription_done, done = rec.update_shift_data(
shift, swap_subscription_done
)
if done:
# You're not supposed to remove items from a list while
# looping over it. We circumvent this problem by looping
# over a copy of the list, which will not be affected.
changes.remove(rec)
# process the remaining changes and create a new list containing
# only the changes that have not be processed yet.
changes = [
rec
for rec in changes
# 3rd returned element is a boolean telling whether it was done
if not rec.update_shift_data(shift, swap_subscription_done)[2]
]

return shifts

0 comments on commit 4a08b6e

Please sign in to comment.