field 'nextrun_link' --> 'nextrun_date', add default-order

This commit is contained in:
Frederik Jaeckel 2024-03-11 12:50:00 +01:00
parent e1502cae53
commit e7bd95ff31
6 changed files with 68 additions and 14 deletions

View file

@ -234,7 +234,7 @@ msgctxt "field:cashbook.planner,nextrun:"
msgid "Next Execution Date"
msgstr "Nächster Ausführungstermin"
msgctxt "field:cashbook.planner,nextrun_link:"
msgctxt "field:cashbook.planner,nextrun_date:"
msgid "Next Execution Date"
msgstr "Nächster Ausführungstermin"

View file

@ -210,7 +210,7 @@ msgctxt "field:cashbook.planner,nextrun:"
msgid "Next Execution Date"
msgstr "Next Execution Date"
msgctxt "field:cashbook.planner,nextrun_link:"
msgctxt "field:cashbook.planner,nextrun_date:"
msgid "Next Execution Date"
msgstr "Next Execution Date"

View file

@ -98,10 +98,9 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
nextrun = fields.One2Many(
string='Next Execution Date', size=1, field='planner',
model_name='cashbook.planner.nextrun')
nextrun_link = fields.Function(fields.Many2One(
string='Next Execution Date', readonly=True,
model_name='cashbook.planner.nextrun'),
'on_change_with_nextrun_link')
nextrun_date = fields.Function(fields.Date(
string='Next Execution Date', readonly=True),
'on_change_with_nextrun_date', searcher='search_nextrun_date')
bookingtype = fields.Selection(
string='Type', selection=sel_bookingtype, required=True,
@ -159,6 +158,8 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super(ScheduledBooking, cls).__setup__()
cls._order.insert(0, ('name', 'ASC'))
cls._order.insert(0, ('nextrun_date', 'ASC'))
t = cls.__table__()
cls._sql_indexes.update({
Index(
@ -189,7 +190,8 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
self.booktransf.name
if self.booktransf
else self.category.rec_name if self.category else '-',
self.nextrun_link.rec_name if self.nextrun_link else '-',
Report.format_date(self.nextrun_date, lang=None)
if self.nextrun_date else '-',
Report.format_currency(
self.amount, lang=None, currency=self.cashbook.currency)
])
@ -302,17 +304,17 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
return self.cashbook.currency.id
@fields.depends('nextrun')
def on_change_with_nextrun_link(self, name=None):
def on_change_with_nextrun_date(self, name=None):
""" get nextrun-record if exist
Args:
name (str, optional): field name. Defaults to None.
Returns:
int: id of nextrun-record or None
date: date of nextrun or None
"""
if self.nextrun:
return self.nextrun[0].id
return self.nextrun[0].date
return None
@fields.depends(
@ -402,6 +404,44 @@ class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
"""
self.on_change_frequ()
@staticmethod
def order_nextrun_date(tables):
""" get query to sort by date of next execution
Args:
tables (list): tables
Returns:
list of query: sort-query
"""
pool = Pool()
Nextrun = pool.get('cashbook.planner.nextrun')
Planner2 = pool.get('cashbook.planner')
tab_nxrun = Nextrun.__table__()
tab_plan = Planner2.__table__()
table, _ = tables[None]
query = tab_plan.join(
tab_nxrun,
condition=tab_nxrun.planner == tab_plan.id
).select(
tab_nxrun.date,
where=tab_plan.id == table.id)
return [query]
@classmethod
def search_nextrun_date(cls, name, clause):
""" get query for search on 'nextrun_date'
Args:
name (str): name of field to search on
clause (dict): search clause
Returns:
list of dict: search clause
"""
return [('nextrun.date',) + tuple(clause[1:])]
@classmethod
def default_wfcheck(cls):
""" False as default for wf-state 'checked'

View file

@ -292,6 +292,20 @@ class PlannerTestCase(object):
Planner.update_next_occurence([job], query_date=date(2022, 5, 25))
self.assertEqual(len(job.nextrun), 1)
self.assertEqual(job.nextrun[0].date, date(2022, 6, 1))
self.assertEqual(job.nextrun_date, date(2022, 6, 1))
# check searcher + order
self.assertEqual(
Planner.search(
[('nextrun_date', '=', date(2022, 6, 1))],
order=[('nextrun_date', 'ASC')]),
[job])
self.assertEqual(
Planner.search_count([('nextrun_date', '=', date(2022, 6, 1))]),
1)
self.assertEqual(
Planner.search_count([('nextrun_date', '=', date(2022, 6, 2))]),
0)
Planner.update_next_occurence([job], query_date=date(2022, 5, 30))
self.assertEqual(len(job.nextrun), 1)

View file

@ -12,8 +12,8 @@ full copyright notices and license terms. -->
<label name="active"/>
<field name="active"/>
<label name="nextrun_link" colspan="5"/>
<field name="nextrun_link"/>
<label name="nextrun_date" colspan="5"/>
<field name="nextrun_date"/>
<notebook colspan="6">
<page id="rrule" col="6" string="Recurrence Rule">

View file

@ -14,7 +14,7 @@ full copyright notices and license terms. -->
<field name="wfcheck" optional="1"/>
<field name="cashbook" optional="0"/>
<field name="nextrun_link" optional="0"/>
<field name="nextrun_date" optional="0"/>
<field name="amount" optional="0"/>
<field name="bookingtype" optional="0"/>
<field name="booking_target" optional="0"/>