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

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

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'