Skip to content

Commit

Permalink
[IMP] make code more obvious (attempt 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
huguesdk committed Nov 1, 2024
1 parent 550e45c commit eafb62d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions beesdoo_shift_swap/models/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@ def _prepare_task_day(self):
)

changes = (
set(swaps)
| set(exchanges)
| set(solidarity_offers)
| set(solidarity_requests)
list(swaps)
+ list(exchanges)
+ list(solidarity_offers)
+ list(solidarity_requests)
)
processed = set()

# Sort changes by validation date to evaluate them in the correct order
changes.sort(key=lambda x: x.get_validate_date())

swap_subscription_done = []
for shift in shifts:
# Sort changes by validation date to evaluate them in the correct order
to_process = sorted(changes, key=lambda x: x.get_validate_date())
for rec in to_process:
shift, swap_subscription_done, done = rec.update_shift_data(
shift, swap_subscription_done
)
if done:
processed.add(rec)
changes -= processed
# process the remaining changes and update the list to contain
# 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 eafb62d

Please sign in to comment.