diff --git a/locale/de.po b/locale/de.po index 4cd94d0..80480d3 100644 --- a/locale/de.po +++ b/locale/de.po @@ -204,7 +204,7 @@ msgstr "Tag des Monats" msgctxt "help:cashbook.planner,monthday:" msgid "If you want the rule to run on a specific day of the month, select the day here." -msgstr "Wenn die Regel an einem bestimmten Tag im Monat ausgeführt soll, wählen Siehier den Tag." +msgstr "Wenn die Regel an einem bestimmten Tag im Monat ausgeführt soll, wählen Sie hier den Tag." msgctxt "field:cashbook.planner,interval:" msgid "Interval" @@ -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" diff --git a/locale/en.po b/locale/en.po index f4994ad..c743815 100644 --- a/locale/en.po +++ b/locale/en.po @@ -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" diff --git a/planner.py b/planner.py index 7f701dc..c1b4824 100644 --- a/planner.py +++ b/planner.py @@ -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' diff --git a/tests/planner.py b/tests/planner.py index eb3389f..7638279 100644 --- a/tests/planner.py +++ b/tests/planner.py @@ -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) diff --git a/view/planner_form.xml b/view/planner_form.xml index 9baf580..d15d0ff 100644 --- a/view/planner_form.xml +++ b/view/planner_form.xml @@ -12,8 +12,8 @@ full copyright notices and license terms. -->