add form for nextrun-records, update of nextrun-records, tests

This commit is contained in:
Frederik Jaeckel 2024-02-29 23:20:19 +01:00
parent 9f3e33d225
commit 0fc0c4c8b9
8 changed files with 472 additions and 194 deletions

View file

@ -38,7 +38,7 @@ msgstr "geplante Buchungen"
################# #################
# ir.rule.group # # ir.rule.group #
################# #################
msgctxt "model:ir.rule.group,name:rg_planner_write_admin" msgctxt "model:ir.rule.group,name:rg_planner_admin"
msgid "Administrators: scheduled bookings read/write" msgid "Administrators: scheduled bookings read/write"
msgstr "Administratoren: geplante Buchungen schreiben" msgstr "Administratoren: geplante Buchungen schreiben"
@ -58,6 +58,26 @@ msgctxt "model:ir.rule.group,name:rg_planner_companies"
msgid "User in companies" msgid "User in companies"
msgstr "Benutzer im Unternehmen" msgstr "Benutzer im Unternehmen"
msgctxt "model:ir.rule.group,name:rg_nextrun_admin"
msgid "Administrators: scheduled bookings read/write"
msgstr "Administratoren: geplante Buchungen schreiben"
msgctxt "model:ir.rule.group,name:rg_planner_owner"
msgid "Owners: scheduled bookings"
msgstr "Eigentümer: geplante Buchungen"
msgctxt "model:ir.rule.group,name:rg_planner_read_nonowner"
msgid "Observers: scheduled bookings read"
msgstr "Beobachter: geplante Buchungen lesen"
msgctxt "model:ir.rule.group,name:rg_planner_write_nonowner"
msgid "Reviewer: scheduled bookings write"
msgstr "Bearbeiter: geplante Buchungen schreiben"
msgctxt "model:ir.rule.group,name:rg_nextrun_companies"
msgid "User in companies"
msgstr "Benutzer im Unternehmen"
#################### ####################
# cashbook.planner # # cashbook.planner #

View file

@ -1,172 +1,208 @@
# #
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n" msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "selection:ir.cron,method:" msgctxt "selection:ir.cron,method:"
msgid "Execute scheduled bookings" msgid "Execute scheduled bookings"
msgstr "Execute scheduled bookings" msgstr "Execute scheduled bookings"
msgctxt "model:res.group,name:group_planner" msgctxt "model:res.group,name:group_planner"
msgid "Cashbook - Scheduled Bookings" msgid "Cashbook - Scheduled Bookings"
msgstr "Cashbook - Scheduled Bookings" msgstr "Cashbook - Scheduled Bookings"
msgctxt "model:ir.ui.menu,name:menu_planner" msgctxt "model:ir.ui.menu,name:menu_planner"
msgid "Scheduled Bookings" msgid "Scheduled Bookings"
msgstr "Scheduled Bookings" msgstr "Scheduled Bookings"
msgctxt "model:ir.action,name:act_planner_view" msgctxt "model:ir.action,name:act_planner_view"
msgid "Scheduled Bookings" msgid "Scheduled Bookings"
msgstr "Scheduled Bookings" msgstr "Scheduled Bookings"
msgctxt "model:ir.rule.group,name:rg_planner_write_admin" msgctxt "model:ir.rule.group,name:rg_planner_admin"
msgid "Administrators: scheduled bookings read/write" msgid "Administrators: scheduled bookings read/write"
msgstr "Administrators: scheduled bookings read/write" msgstr "Administrators: scheduled bookings read/write"
msgctxt "model:ir.rule.group,name:rg_planner_owner" msgctxt "model:ir.rule.group,name:rg_planner_owner"
msgid "Owners: scheduled bookings" msgid "Owners: scheduled bookings"
msgstr "Owners: scheduled bookings" msgstr "Owners: scheduled bookings"
msgctxt "model:ir.rule.group,name:rg_planner_read_nonowner" msgctxt "model:ir.rule.group,name:rg_planner_read_nonowner"
msgid "Observers: scheduled bookings read" msgid "Observers: scheduled bookings read"
msgstr "Observers: scheduled bookings read" msgstr "Observers: scheduled bookings read"
msgctxt "model:ir.rule.group,name:rg_planner_write_nonowner" msgctxt "model:ir.rule.group,name:rg_planner_write_nonowner"
msgid "Reviewer: scheduled bookings write" msgid "Reviewer: scheduled bookings write"
msgstr "Reviewer: scheduled bookings write" msgstr "Reviewer: scheduled bookings write"
msgctxt "model:ir.rule.group,name:rg_planner_companies" msgctxt "model:ir.rule.group,name:rg_planner_companies"
msgid "User in companies" msgid "User in companies"
msgstr "User in companies" msgstr "User in companies"
msgctxt "model:cashbook.planner,name:" msgctxt "model:ir.rule.group,name:rg_nextrun_admin"
msgid "Scheduled Booking" msgid "Administrators: scheduled bookings read/write"
msgstr "Scheduled Booking" msgstr "Administrators: scheduled bookings read/write"
msgctxt "view:cashbook.planner:" msgctxt "model:ir.rule.group,name:rg_planner_owner"
msgid "Recurrence Rule" msgid "Owners: scheduled bookings"
msgstr "Recurrence Rule" msgstr "Owners: scheduled bookings"
msgctxt "view:cashbook.planner:" msgctxt "model:ir.rule.group,name:rg_planner_read_nonowner"
msgid "Result of the recurrence rule" msgid "Observers: scheduled bookings read"
msgstr "Result of the recurrence rule" msgstr "Observers: scheduled bookings read"
msgctxt "field:cashbook.planner,company:" msgctxt "model:ir.rule.group,name:rg_planner_write_nonowner"
msgid "Company" msgid "Reviewer: scheduled bookings write"
msgstr "Company" msgstr "Reviewer: scheduled bookings write"
msgctxt "field:cashbook.planner,cashbook:" msgctxt "model:ir.rule.group,name:rg_nextrun_companies"
msgid "Cashbook" msgid "User in companies"
msgstr "Cashbook" msgstr "User in companies"
msgctxt "help:cashbook.planner,cashbook:" msgctxt "model:cashbook.planner,name:"
msgid "Cash book for which the planned posting is to be executed." msgid "Scheduled Booking"
msgstr "Cash book for which the planned posting is to be executed." msgstr "Scheduled Booking"
msgctxt "field:cashbook.planner,name:" msgctxt "view:cashbook.planner:"
msgid "Name" msgid "Recurrence Rule"
msgstr "Name" msgstr "Recurrence Rule"
msgctxt "field:cashbook.planner,description:" msgctxt "view:cashbook.planner:"
msgid "Description" msgid "Result of the recurrence rule"
msgstr "Description" msgstr "Result of the recurrence rule"
msgctxt "field:cashbook.planner,start_date:" msgctxt "field:cashbook.planner,company:"
msgid "Start Date" msgid "Company"
msgstr "Start Date" msgstr "Company"
msgctxt "field:cashbook.planner,end_date:" msgctxt "field:cashbook.planner,cashbook:"
msgid "End Date" msgid "Cashbook"
msgstr "End Date" msgstr "Cashbook"
msgctxt "field:cashbook.planner,frequ:" msgctxt "help:cashbook.planner,cashbook:"
msgid "Frequency" msgid "Cash book for which the planned posting is to be executed."
msgstr "Frequency" msgstr "Cash book for which the planned posting is to be executed."
msgctxt "selection:cashbook.planner,frequ:" msgctxt "field:cashbook.planner,name:"
msgid "Yearly" msgid "Name"
msgstr "Yearly" msgstr "Name"
msgctxt "selection:cashbook.planner,frequ:" msgctxt "field:cashbook.planner,description:"
msgid "Monthly" msgid "Description"
msgstr "Monthly" msgstr "Description"
msgctxt "selection:cashbook.planner,frequ:" msgctxt "field:cashbook.planner,start_date:"
msgid "Weekly" msgid "Start Date"
msgstr "Weekly" msgstr "Start Date"
msgctxt "selection:cashbook.planner,frequ:" msgctxt "field:cashbook.planner,end_date:"
msgid "Daily" msgid "End Date"
msgstr "Daily" msgstr "End Date"
msgctxt "field:cashbook.planner,weekday:" msgctxt "field:cashbook.planner,frequ:"
msgid "Weekday" msgid "Frequency"
msgstr "Weekday" msgstr "Frequency"
msgctxt "help:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,frequ:"
msgid "Select a day of the week if you want the rule to run on that day." msgid "Yearly"
msgstr "Select a day of the week if you want the rule to run on that day." msgstr "Yearly"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,frequ:"
msgid "Monday" msgid "Monthly"
msgstr "Monday" msgstr "Monthly"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,frequ:"
msgid "Tuesday" msgid "Weekly"
msgstr "Tuesday" msgstr "Weekly"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,frequ:"
msgid "Wednesday" msgid "Daily"
msgstr "Wednesday" msgstr "Daily"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "field:cashbook.planner,weekday:"
msgid "Thursday" msgid "Weekday"
msgstr "Thursday" msgstr "Weekday"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "help:cashbook.planner,weekday:"
msgid "Friday" msgid "Select a day of the week if you want the rule to run on that day."
msgstr "Friday" msgstr "Select a day of the week if you want the rule to run on that day."
msgctxt "selection:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Saturday" msgid "Monday"
msgstr "Saturday" msgstr "Monday"
msgctxt "selection:cashbook.planner,weekday:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Sunday" msgid "Tuesday"
msgstr "Sunday" msgstr "Tuesday"
msgctxt "field:cashbook.planner,monthday:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Day of month" msgid "Wednesday"
msgstr "Day of month" msgstr "Wednesday"
msgctxt "help:cashbook.planner,monthday:" msgctxt "selection:cashbook.planner,weekday:"
msgid "If you want the rule to run on a specific day of the month, select the day here." msgid "Thursday"
msgstr "If you want the rule to run on a specific day of the month, select the day here." msgstr "Thursday"
msgctxt "field:cashbook.planner,interval:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Interval" msgid "Friday"
msgstr "Interval" msgstr "Friday"
msgctxt "help:cashbook.planner,interval:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Select an interval to run the rule on every n-th date." msgid "Saturday"
msgstr "Select an interval to run the rule on every n-th date." msgstr "Saturday"
msgctxt "field:cashbook.planner,nextdates:" msgctxt "selection:cashbook.planner,weekday:"
msgid "Next Dates" msgid "Sunday"
msgstr "Next Dates" msgstr "Sunday"
msgctxt "help:cashbook.planner,nextdates:" msgctxt "field:cashbook.planner,monthday:"
msgid "the next 5 appointments based on the configured rule" msgid "Day of month"
msgstr "the next 5 appointments based on the configured rule" msgstr "Day of month"
msgctxt "field:cashbook.planner,setpos:" msgctxt "help:cashbook.planner,monthday:"
msgid "Occurrence" msgid "If you want the rule to run on a specific day of the month, select the day here."
msgstr "Occurrence" msgstr "If you want the rule to run on a specific day of the month, select the day here."
msgctxt "help:cashbook.planner,setpos:" msgctxt "field:cashbook.planner,interval:"
msgid "For example, if you want to run the rule on the second Wednesday of the month, enter 2 here." msgid "Interval"
msgstr "For example, if you want to run the rule on the second Wednesday of the month, enter 2 here." msgstr "Interval"
msgctxt "view:cashbook.book:" msgctxt "help:cashbook.planner,interval:"
msgid "Scheduled Bookings" msgid "Select an interval to run the rule on every n-th date."
msgstr "Scheduled Bookings" msgstr "Select an interval to run the rule on every n-th date."
msgctxt "field:cashbook.planner,nextdates:"
msgid "Next Dates"
msgstr "Next Dates"
msgctxt "help:cashbook.planner,nextdates:"
msgid "the next 5 appointments based on the configured rule"
msgstr "the next 5 appointments based on the configured rule"
msgctxt "field:cashbook.planner,setpos:"
msgid "Occurrence"
msgstr "Occurrence"
msgctxt "help:cashbook.planner,setpos:"
msgid "For example, if you want to run the rule on the second Wednesday of the month, enter 2 here."
msgstr "For example, if you want to run the rule on the second Wednesday of the month, enter 2 here."
msgctxt "field:cashbook.planner,nextrun:"
msgid "Next Execution Date"
msgstr "Next Execution Date"
msgctxt "model:cashbook.planner.nextrun,name:"
msgid "Next Execution Date"
msgstr "Next Execution Date"
msgctxt "field:cashbook.planner.nextrun,planner:"
msgid "Planner"
msgstr "Planner"
msgctxt "field:cashbook.planner.nextrun,date:"
msgid "Date"
msgstr "Date"
msgctxt "view:cashbook.book:"
msgid "Scheduled Bookings"
msgstr "Scheduled Bookings"

145
nextrun.xml Normal file
View file

@ -0,0 +1,145 @@
<?xml version="1.0"?>
<!-- This file is part of the cashbook-planner from m-ds for Tryton.
The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. -->
<tryton>
<data>
<!-- views -->
<record model="ir.ui.view" id="nextrun_view_list">
<field name="model">cashbook.planner.nextrun</field>
<field name="type">tree</field>
<field name="priority" eval="10"/>
<field name="name">nextrun_list</field>
</record>
<record model="ir.ui.view" id="nextrun_view_form">
<field name="model">cashbook.planner.nextrun</field>
<field name="type">form</field>
<field name="priority" eval="20"/>
<field name="name">nextrun_form</field>
</record>
<!-- permission -->
<!-- anon: deny all -->
<record model="ir.model.access" id="access_nextrun-anon">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<!-- group_planner_write: read/write -->
<record model="ir.model.access" id="access_nextrun-group_planner">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="group" ref="group_planner"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!-- permission by rule - admin-write -->
<record model="ir.rule.group" id="rg_nextrun_admin">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="name">Administrators: scheduled bookings read/write</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.rule" id="rg_nextrun_admin-1">
<field name="domain" eval="[]" pyson="1"/>
<field name="rule_group" ref="rg_nextrun_admin"/>
</record>
<record model="ir.rule.group-res.group"
id="rg_nextrun_admin-group_cashbook_admin">
<field name="rule_group" ref="rg_nextrun_admin"/>
<field name="group" ref="cashbook.group_cashbook_admin"/>
</record>
<!-- permission by rule - read/write: owner -->
<record model="ir.rule.group" id="rg_nextrun_owner">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="name">Owners: scheduled bookings</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.rule" id="rg_nextrun_owner-1">
<field name="domain" eval="[
('planner.cashbook.owner.id', '=', Eval('user_id', -1)),
]" pyson="1"/>
<field name="rule_group" ref="rg_nextrun_owner"/>
</record>
<record model="ir.rule.group-res.group"
id="rg_nextrun_owner-group_planner">
<field name="rule_group" ref="rg_nextrun_owner"/>
<field name="group" ref="group_planner"/>
</record>
<!-- permission by rule - read: observer -->
<record model="ir.rule.group" id="rg_nextrun_read_nonowner">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="name">Observers: scheduled bookings read</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.rule" id="rg_nextrun_read_nonowner-1">
<field name="domain" eval="[
('planner.cashbook.observer.id', 'in', Eval('groups', [])),
]" pyson="1"/>
<field name="rule_group" ref="rg_nextrun_read_nonowner"/>
</record>
<record model="ir.rule.group-res.group"
id="rg_nextrun_read_nonowner-group_planner">
<field name="rule_group" ref="rg_nextrun_read_nonowner"/>
<field name="group" ref="group_planner"/>
</record>
<!-- permission by rule - write: reviewer -->
<record model="ir.rule.group" id="rg_nextrun_write_nonowner">
<field name="model" search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="name">Reviewer: scheduled bookings write</field>
<field name="global_p" eval="False"/>
<field name="default_p" eval="False"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.rule" id="rg_nextrun_write_nonowner-1">
<field name="domain" eval="[
('planner.cashbook.reviewer.id', 'in', Eval('groups', [])),
]" pyson="1"/>
<field name="rule_group" ref="rg_nextrun_write_nonowner"/>
</record>
<record model="ir.rule.group-res.group"
id="rg_nextrun_write_nonowner-group_planner">
<field name="rule_group" ref="rg_nextrun_write_nonowner"/>
<field name="group" ref="group_planner"/>
</record>
<record model="ir.rule.group" id="rg_nextrun_companies">
<field name="name">User in companies</field>
<field name="model"
search="[('model', '=', 'cashbook.planner.nextrun')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="r_nextrun_companies">
<field name="domain"
eval="[('company', 'in', Eval('companies', []))]"
pyson="1"/>
<field name="rule_group" ref="rg_nextrun_companies"/>
</record>
</data>
</tryton>

View file

@ -105,11 +105,11 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
where=t.end_date != DEF_NONE), 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' """ run rrule with values from record or from 'params'
Args: 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. recurrences. Defaults to None.
count (int, optional): number of recurrences in result. count (int, optional): number of recurrences in result.
Defaults to 5. max value = 100 Defaults to 5. max value = 100
@ -160,8 +160,8 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
result = [] result = []
for x in dtrule: for x in dtrule:
if (start_date and (x.date() >= start_date)) or \ if (query_date and (x.date() >= query_date)) or \
(start_date is None): (query_date is None):
result.append(x.date()) result.append(x.date())
if len(result) >= count: if len(result) >= count:
break break
@ -178,7 +178,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
name (string, optional): name of field. Defaults to None. name (string, optional): name of field. Defaults to None.
context: 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 defaults to today if not set or None
Returns: Returns:
@ -187,14 +187,14 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
IrDate = Pool().get('ir.date') IrDate = Pool().get('ir.date')
context = Transaction().context context = Transaction().context
start_date = context.get('start_date', None) query_date = context.get('nextrun_querydate', None)
if not isinstance(start_date, date): if not isinstance(query_date, date):
start_date = IrDate.today() query_date = IrDate.today()
return ' | '.join([ return ' | '.join([
Report.format_date(x) Report.format_date(x)
for x in self._compute_dates_by_rrule( for x in self._compute_dates_by_rrule(
start_date=start_date, query_date=query_date,
params={ params={
'start_date': self.start_date, 'start_date': self.start_date,
'end_date': self.end_date, 'end_date': self.end_date,
@ -291,6 +291,7 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
pool = Pool() pool = Pool()
IrDate = pool.get('ir.date') IrDate = pool.get('ir.date')
NextRun = pool.get('cashbook.planner.nextrun') NextRun = pool.get('cashbook.planner.nextrun')
context = Transaction().context
to_create = [] to_create = []
to_write = [] to_write = []
@ -303,10 +304,14 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
elif record.active: elif record.active:
# get next-run date # get next-run date
next_date = record._compute_dates_by_rrule( 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: if next_date:
next_date = next_date[0] next_date = next_date[0]
else: else:
if record.nextrun:
to_delete.extend(record.nextrun)
continue continue
if not record.nextrun: if not record.nextrun:
@ -324,6 +329,31 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
if to_write: if to_write:
NextRun.write(*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 @classmethod
def cronjob(cls): def cronjob(cls):
pass pass

View file

@ -24,7 +24,7 @@ class PlannerTestCase(object):
job = None job = None
with Transaction().set_context({ with Transaction().set_context({
'company': company.id, 'company': company.id,
'start_date': date(2022, 5, 1)}): 'nextrun_querydate': date(2022, 5, 1)}):
book, = Book.create([{ book, = Book.create([{
'name': 'Book 1', 'name': 'Book 1',
'btype': types.id, 'btype': types.id,
@ -63,7 +63,7 @@ class PlannerTestCase(object):
job = self.prep_create_job() job = self.prep_create_job()
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
start_date=date(2022, 5, 1), count=5), [ query_date=date(2022, 5, 1), count=5), [
date(2022, 5, 1), date(2022, 6, 1), date(2022, 5, 1), date(2022, 6, 1),
date(2022, 7, 1), date(2022, 8, 1), date(2022, 7, 1), date(2022, 8, 1),
date(2022, 9, 1)]) date(2022, 9, 1)])
@ -78,7 +78,7 @@ class PlannerTestCase(object):
Planner.write(*[[job], { Planner.write(*[[job], {
'end_date': date(2022, 9, 15), 'monthday': 3}]) 'end_date': date(2022, 9, 15), 'monthday': 3}])
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule(start_date=date(2022, 5, 1)), [ job._compute_dates_by_rrule(query_date=date(2022, 5, 1)), [
date(2022, 5, 3), date(2022, 6, 3), date(2022, 5, 3), date(2022, 6, 3),
date(2022, 7, 3), date(2022, 8, 3), date(2022, 7, 3), date(2022, 8, 3),
date(2022, 9, 3)]) date(2022, 9, 3)])
@ -86,7 +86,7 @@ class PlannerTestCase(object):
Planner.write(*[[job], { Planner.write(*[[job], {
'end_date': date(2022, 9, 15), 'monthday': 3, 'interval': 2}]) 'end_date': date(2022, 9, 15), 'monthday': 3, 'interval': 2}])
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule(start_date=date(2022, 5, 1)), [ job._compute_dates_by_rrule(query_date=date(2022, 5, 1)), [
date(2022, 5, 3), date(2022, 7, 3), date(2022, 5, 3), date(2022, 7, 3),
date(2022, 9, 3)]) date(2022, 9, 3)])
@ -95,7 +95,7 @@ class PlannerTestCase(object):
'end_date': None, 'monthday': 1, 'interval': 1}]) 'end_date': None, 'monthday': 1, 'interval': 1}])
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
start_date=date(2022, 5, 1), query_date=date(2022, 5, 1),
params={ params={
'end_date': date(2022, 9, 15), 'monthday': 3, 'end_date': date(2022, 9, 15), 'monthday': 3,
'interval': 2}), 'interval': 2}),
@ -104,7 +104,7 @@ class PlannerTestCase(object):
# 1st wednesday of each 2nd month # 1st wednesday of each 2nd month
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
start_date=date(2022, 5, 1), query_date=date(2022, 5, 1),
params={ params={
'end_date': date(2022, 9, 15), 'weekday': '2', 'end_date': date(2022, 9, 15), 'weekday': '2',
'interval': 2, 'setpos': 1, 'monthday': None}), 'interval': 2, 'setpos': 1, 'monthday': None}),
@ -113,7 +113,7 @@ class PlannerTestCase(object):
# 2nd wednesday of each 2nd month # 2nd wednesday of each 2nd month
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
start_date=date(2022, 5, 1), query_date=date(2022, 5, 1),
params={ params={
'end_date': date(2022, 9, 15), 'weekday': '2', 'end_date': date(2022, 9, 15), 'weekday': '2',
'interval': 2, 'setpos': 2, 'monthday': None}), 'interval': 2, 'setpos': 2, 'monthday': None}),
@ -122,7 +122,7 @@ class PlannerTestCase(object):
# 2nd wednesday of each month, 6x occurences # 2nd wednesday of each month, 6x occurences
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
start_date=date(2022, 5, 1), count=6, query_date=date(2022, 5, 1), count=6,
params={ params={
'weekday': '2', 'end_date': None, 'weekday': '2', 'end_date': None,
'interval': 1, 'setpos': 2, 'monthday': None}), 'interval': 1, 'setpos': 2, 'monthday': None}),
@ -216,10 +216,38 @@ class PlannerTestCase(object):
job = self.prep_create_job() job = self.prep_create_job()
self.assertEqual( self.assertEqual(
job._compute_dates_by_rrule( job._compute_dates_by_rrule(
count=1, start_date=date(2022, 5, 1)), [ count=1, query_date=date(2022, 5, 1)), [
date(2022, 5, 1)]) date(2022, 5, 1)])
job.update_next_occurence([job]) with Transaction().set_context({
self.assertEqual(len(job.nextrun), 1) 'nextrun_querydate': date(2022, 5, 25)}):
Planner.update_next_occurence([job])
self.assertEqual(len(job.nextrun), 1)
self.assertEqual(job.nextrun[0].date, date(2022, 6, 1))
with Transaction().set_context({
'nextrun_querydate': date(2022, 5, 30)}):
Planner.update_next_occurence([job])
self.assertEqual(len(job.nextrun), 1)
self.assertEqual(job.nextrun[0].date, date(2022, 6, 1))
with Transaction().set_context({
'nextrun_querydate': date(2022, 6, 1)}):
Planner.update_next_occurence([job])
self.assertEqual(len(job.nextrun), 1)
self.assertEqual(job.nextrun[0].date, date(2022, 6, 1))
with Transaction().set_context({
'nextrun_querydate': date(2022, 6, 2)}):
Planner.update_next_occurence([job])
self.assertEqual(len(job.nextrun), 1)
self.assertEqual(job.nextrun[0].date, date(2022, 7, 1))
with Transaction().set_context({
'nextrun_querydate': date(2022, 6, 2)}):
# set end-date to check delete of futore runs
Planner.write(*[[job], {'end_date': date(2022, 6, 20)}])
# write to planner-record updates nextrun-records too
self.assertEqual(len(job.nextrun), 0)
# end PlannerTestCase # end PlannerTestCase

View file

@ -7,6 +7,7 @@ extras_depend:
xml: xml:
group.xml group.xml
planner.xml planner.xml
nextrun.xml
cashbook.xml cashbook.xml
cron.xml cron.xml
menu.xml menu.xml

10
view/nextrun_form.xml Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of the cashbook-planner from m-ds for Tryton.
The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. -->
<form col="4">
<label name="planner"/>
<field name="planner"/>
<label name="date"/>
<field name="date"/>
</form>

8
view/nextrun_list.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of the cashbook-planner from m-ds for Tryton.
The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. -->
<tree>
<field name="planner"/>
<field name="date"/>
</tree>