add form for nextrun-records, update of nextrun-records, tests
This commit is contained in:
parent
9f3e33d225
commit
0fc0c4c8b9
8 changed files with 472 additions and 194 deletions
50
planner.py
50
planner.py
|
@ -105,11 +105,11 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
where=t.end_date != DEF_NONE),
|
||||
})
|
||||
|
||||
def _compute_dates_by_rrule(self, start_date=None, count=5, params={}):
|
||||
def _compute_dates_by_rrule(self, query_date=None, count=5, params={}):
|
||||
""" run rrule with values from record or from 'params'
|
||||
|
||||
Args:
|
||||
start_date (date, optional): Start date as a filter for
|
||||
query_date (date, optional): Start date as a filter for
|
||||
recurrences. Defaults to None.
|
||||
count (int, optional): number of recurrences in result.
|
||||
Defaults to 5. max value = 100
|
||||
|
@ -160,8 +160,8 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
|
||||
result = []
|
||||
for x in dtrule:
|
||||
if (start_date and (x.date() >= start_date)) or \
|
||||
(start_date is None):
|
||||
if (query_date and (x.date() >= query_date)) or \
|
||||
(query_date is None):
|
||||
result.append(x.date())
|
||||
if len(result) >= count:
|
||||
break
|
||||
|
@ -178,7 +178,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
name (string, optional): name of field. Defaults to None.
|
||||
|
||||
context:
|
||||
start_date (date, optional): start date for dates in result,
|
||||
nextrun_querydate (date, optional): start date for dates in result,
|
||||
defaults to today if not set or None
|
||||
|
||||
Returns:
|
||||
|
@ -187,14 +187,14 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
context = Transaction().context
|
||||
|
||||
start_date = context.get('start_date', None)
|
||||
if not isinstance(start_date, date):
|
||||
start_date = IrDate.today()
|
||||
query_date = context.get('nextrun_querydate', None)
|
||||
if not isinstance(query_date, date):
|
||||
query_date = IrDate.today()
|
||||
|
||||
return ' | '.join([
|
||||
Report.format_date(x)
|
||||
for x in self._compute_dates_by_rrule(
|
||||
start_date=start_date,
|
||||
query_date=query_date,
|
||||
params={
|
||||
'start_date': self.start_date,
|
||||
'end_date': self.end_date,
|
||||
|
@ -291,6 +291,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
pool = Pool()
|
||||
IrDate = pool.get('ir.date')
|
||||
NextRun = pool.get('cashbook.planner.nextrun')
|
||||
context = Transaction().context
|
||||
|
||||
to_create = []
|
||||
to_write = []
|
||||
|
@ -303,10 +304,14 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
elif record.active:
|
||||
# get next-run date
|
||||
next_date = record._compute_dates_by_rrule(
|
||||
start_date=IrDate.today(), count=1)
|
||||
query_date=context.get(
|
||||
'nextrun_querydate', IrDate.today()),
|
||||
count=1)
|
||||
if next_date:
|
||||
next_date = next_date[0]
|
||||
else:
|
||||
if record.nextrun:
|
||||
to_delete.extend(record.nextrun)
|
||||
continue
|
||||
|
||||
if not record.nextrun:
|
||||
|
@ -324,6 +329,31 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
if to_write:
|
||||
NextRun.write(*to_write)
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
""" update nextrun-records on create of planner-records
|
||||
|
||||
Args:
|
||||
vlist (list of dict): values to create records
|
||||
|
||||
Returns:
|
||||
list: created records
|
||||
"""
|
||||
records = super(ScheduledBooking, cls).create(vlist)
|
||||
cls.update_next_occurence(records)
|
||||
return records
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
""" update nextrun-records on create of planner-records
|
||||
"""
|
||||
to_update = []
|
||||
actions = iter(args)
|
||||
for records, values in zip(actions, actions):
|
||||
to_update.extend(records)
|
||||
super(ScheduledBooking, cls).write(*args)
|
||||
cls.update_next_occurence(records)
|
||||
|
||||
@classmethod
|
||||
def cronjob(cls):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue