add cronjob
This commit is contained in:
parent
132fcbb0d5
commit
9f3e33d225
11 changed files with 339 additions and 168 deletions
51
planner.py
51
planner.py
|
@ -84,6 +84,9 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
string='Next Dates', readonly=True,
|
||||
help='the next 5 appointments based on the configured rule'),
|
||||
'on_change_with_nextdates')
|
||||
nextrun = fields.One2Many(
|
||||
string='Next Execution Date', size=1, field='planner',
|
||||
model_name='cashbook.planner.nextrun')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -277,4 +280,52 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
return IrDate.today()
|
||||
|
||||
@classmethod
|
||||
def update_next_occurence(cls, records):
|
||||
""" compute date of next execution, create/update nextrun-record,
|
||||
delete nextrun-record if scheduled booking is disabled
|
||||
|
||||
Args:
|
||||
records (list): scheduled-booking records
|
||||
"""
|
||||
pool = Pool()
|
||||
IrDate = pool.get('ir.date')
|
||||
NextRun = pool.get('cashbook.planner.nextrun')
|
||||
|
||||
to_create = []
|
||||
to_write = []
|
||||
to_delete = []
|
||||
for record in records:
|
||||
if not record.active:
|
||||
# delete nextrun-record if disabled
|
||||
if record.nextrun:
|
||||
to_delete.extend(record.nextrun)
|
||||
elif record.active:
|
||||
# get next-run date
|
||||
next_date = record._compute_dates_by_rrule(
|
||||
start_date=IrDate.today(), count=1)
|
||||
if next_date:
|
||||
next_date = next_date[0]
|
||||
else:
|
||||
continue
|
||||
|
||||
if not record.nextrun:
|
||||
# add record if not exist
|
||||
to_create.append({'planner': record.id, 'date': next_date})
|
||||
else:
|
||||
# update existing records
|
||||
for nxrun in record.nextrun:
|
||||
if nxrun.date != next_date:
|
||||
to_write.extend([[nxrun], {'date': next_date}])
|
||||
if to_create:
|
||||
NextRun.create(to_create)
|
||||
if to_delete:
|
||||
NextRun.delete(to_delete)
|
||||
if to_write:
|
||||
NextRun.write(*to_write)
|
||||
|
||||
@classmethod
|
||||
def cronjob(cls):
|
||||
pass
|
||||
|
||||
# ens ScheduledBooking
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue