diff --git a/buildout.cfg b/buildout.cfg index 48dac86f..2f233661 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -9,3 +9,4 @@ extends = eggs += Products.PrintingMailHost design.plone.ioprenoto + diff --git a/src/redturtle/prenotazioni/browser/prenotazioni_context_state.py b/src/redturtle/prenotazioni/browser/prenotazioni_context_state.py index de3d75ae..8a5ea422 100644 --- a/src/redturtle/prenotazioni/browser/prenotazioni_context_state.py +++ b/src/redturtle/prenotazioni/browser/prenotazioni_context_state.py @@ -296,13 +296,24 @@ def is_before_allowed_period(self, day, bypass_user_restrictions=False): @memoize def is_valid_day(self, day, bypass_user_restrictions=False): - """Returns True if the day is valid""" + """Returns True if the day is valid + Day is not valid in those conditions: + - day is out of validity range + (not applied to BookingManager if PrenotazioniFolder.bookins_manager_is_restricted_by_dates is False) + - day is vacation day + - day is out of PrenotazioniFolder.futures_day range + (not applied to BookingManager if PrenotazioniFolder.bookins_manager_is_restricted_by_dates is False) + - week day is not configured + """ if isinstance(day, datetime): day = day.date() is_configured_day = self.is_configured_day(day) + if bypass_user_restrictions: + return True + if ( is_configured_day and self.user_can_manage_prenotazioni @@ -316,20 +327,16 @@ def is_valid_day(self, day, bypass_user_restrictions=False): if self.is_vacation_day(day): return False - if not bypass_user_restrictions and ( - self.last_bookable_day and day > self.last_bookable_day - ): + if self.last_bookable_day and day > self.last_bookable_day: return False - if self.is_before_allowed_period( - day, bypass_user_restrictions=bypass_user_restrictions - ): + if self.is_before_allowed_period(day, bypass_user_restrictions=False): return False if self.future_days_limit: date_limit = date.today() + timedelta(days=self.future_days_limit) - if day >= date_limit and not bypass_user_restrictions: + if day >= date_limit: return False return is_configured_day diff --git a/src/redturtle/prenotazioni/tests/test_day.py b/src/redturtle/prenotazioni/tests/test_day.py index b8d2ca6f..38e824a5 100644 --- a/src/redturtle/prenotazioni/tests/test_day.py +++ b/src/redturtle/prenotazioni/tests/test_day.py @@ -187,6 +187,6 @@ def test_requested_day_is_out_of_range(self): results = response.json() - self.assertEquals(results["gates"], []) - self.assertEquals(results["pauses"], []) - self.assertEquals(results["bookings"], []) + self.assertEqual(results["gates"], []) + self.assertEqual(results["pauses"], []) + self.assertEqual(results["bookings"], [])