recurrence rule + test works

This commit is contained in:
Frederik Jaeckel 2024-02-26 22:46:20 +01:00
parent ed350ba3e2
commit 132fcbb0d5
2 changed files with 109 additions and 11 deletions

View file

@ -85,8 +85,6 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
help='the next 5 appointments based on the configured rule'),
'on_change_with_nextdates')
# rrule: frequ, dtstart, until, bymonthday
@classmethod
def __setup__(cls):
super(ScheduledBooking, cls).__setup__()
@ -125,12 +123,11 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
'year': YEARLY, 'month': MONTHLY, 'week': WEEKLY, 'day': DAILY}
pweekday = {
'0': MO, '1': TU, '2': WE, '3': TH, '4': FR, '5': SA, '6': SU,
'99': None}
'99': None}.get(params.get('weekday', self.weekday), None)
if (count is None) or (count > 100):
count = 100
if count < 1:
count = 1
if count is None:
count = 5
count = 1 if count < 1 else 100 if count > 100 else count
end_date = params.get('end_date', self.end_date)
frequ = pfrequ[params.get('frequ', self.frequ)]
@ -144,11 +141,15 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
monthday = 1 if monthday < 1 else 31 if monthday > 31 else monthday
interval = params.get('interval', self.interval)
if interval is None:
interval = 1
interval = 1 if interval < 1 else 10 if interval > 10 else interval
assert (monthday is None) or (pweekday is None), \
"weekday and monthday cannot be used together"
dtrule = rrule(
freq=frequ,
byweekday=pweekday[params.get('weekday', self.weekday)],
freq=frequ, byweekday=pweekday,
dtstart=params.get('start_date', self.start_date),
until=end_date,
bysetpos=setpos if frequ == MONTHLY else None,