Self hosted FLOSS fitness/workout, nutrition and weight tracker
Fix bug in the need_logs_to_advance toggle
Roland Geidera110d1b6743c
diff --git a/wger/manager/models/routine.py b/wger/manager/models/routine.pyindex 26fb88cfe..77d30db61 100644--- a/wger/manager/models/routine.py+++ b/wger/manager/models/routine.py@@ -269,13 +269,17 @@ class Routine(models.Model):or current_date > timezone.localdate())+ wrapped = Falseif can_proceed and not is_first:iteration_counter[current_day.id] += 1day_index = (day_index + 1) % nr_of_days+ wrapped = day_index == 0current_day = days_list[day_index]- # If fit_in_week is set we need to fill the rest of the week with placeholders- if self.fit_in_week and nr_of_days % 7 != 0 and day_index == 0 and not is_first:+ # If fit_in_week is set we need to fill the rest of the week with placeholders.+ # This must only happen when the cycle actually wrapped around, not when the+ # first day is stuck at index 0 waiting for logs (need_logs_to_advance).+ if self.fit_in_week and nr_of_days % 7 != 0 and wrapped:days_to_monday = 7 - current_date.weekday()for i in range(days_to_monday):placeholder_date = current_date + datetime.timedelta(days=i)diff --git a/wger/manager/tests/test_routine.py b/wger/manager/tests/test_routine.pyindex b9db0b702..7605b4ae0 100644--- a/wger/manager/tests/test_routine.py+++ b/wger/manager/tests/test_routine.py@@ -479,6 +479,50 @@ class RoutineTestCase(WgerTestCase):],)+ def test_date_sequence_fit_in_week_need_logs_no_session(self):+ """+ Test that fit_in_week doesn't insert rest day placeholders while the+ first day is still waiting for logs+ """++ # Arrange+ today = datetime.date.today()+ start = today - datetime.timedelta(days=10)++ self.routine.fit_in_week = True+ self.routine.start = start+ self.routine.end = today + datetime.timedelta(weeks=2)+ self.routine.save()+ self.day1.need_logs_to_advance = True+ self.day1.save()++ Label.objects.all().delete()+ WorkoutSession.objects.all().delete()++ # Assert+ sequence = self.routine.date_sequence++ # The first day stays current up to today, one entry per date+ for i in range((today - start).days + 1):+ self.assertEqual(+ sequence[i],+ WorkoutDayData(+ day=self.day1,+ iteration=1,+ date=start + datetime.timedelta(days=i),+ ),+ )++ # For dates in the future, the days advance+ self.assertEqual(+ sequence[(today - start).days + 1],+ WorkoutDayData(+ day=self.day2,+ iteration=1,+ date=today + datetime.timedelta(days=1),+ ),+ )+def test_date_sequences_current(self):"""Test that the correct active day is returned