From 4a08b6e19938d6daf6a8f6134193f6616708010a Mon Sep 17 00:00:00 2001 From: hugues de keyzer Date: Fri, 1 Nov 2024 11:34:18 +0100 Subject: [PATCH] [FIX] make changes processing code more obvious --- beesdoo_shift_swap/models/planning.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/beesdoo_shift_swap/models/planning.py b/beesdoo_shift_swap/models/planning.py index a8ea457e2..4a3489c0c 100644 --- a/beesdoo_shift_swap/models/planning.py +++ b/beesdoo_shift_swap/models/planning.py @@ -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