Skip to content
Snippets Groups Projects
Commit 9216858c authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] fix date period selector limits in tx history

parent f79e5a15
No related branches found
No related tags found
1 merge request!7750.50.0
import logging
from PyQt5.QtCore import QTime, pyqtSignal, QObject
from PyQt5.QtCore import QTime, pyqtSignal, QObject, QDateTime
from PyQt5.QtGui import QCursor
from sakia.decorators import asyncify
......@@ -125,14 +125,50 @@ class TxHistoryController(QObject):
def dates_changed(self):
self._logger.debug("Changed dates")
if self.view.table_history.model():
qdate_from = self.view.date_from
# capture datetimes from calendar widget
qdate_from = self.view.date_from.dateTime() # type: QDateTime
qdate_to = self.view.date_to.dateTime() # type: QDateTime
# time is midnight
qdate_from.setTime(QTime(0, 0, 0))
qdate_to = self.view.date_to
qdate_to.setTime(QTime(0, 0, 0))
ts_from = qdate_from.dateTime().toTime_t()
ts_to = qdate_to.dateTime().toTime_t()
# calculate dates
qdate_from_plus_one_year = qdate_from.addYears(1)
qdate_to_minus_one_month = qdate_to.addMonths(-1)
qone_month_ago = QDateTime.currentDateTime().addMonths(-1)
qtomorrow = QDateTime.currentDateTime().addDays(1)
qtomorrow.setTime(QTime(0, 0, 0))
# if start later than one month ago...
if qdate_from > qone_month_ago:
# start = now - 1 month
qdate_from = qone_month_ago
# if start > end minus one month...
if qdate_from > qdate_to_minus_one_month:
# end = start + 1 month
qdate_to = qdate_from.addMonths(1)
# if period is more than one year long...
if qdate_to > qdate_from_plus_one_year:
# end = start + 1 year
qdate_to.setDate(qdate_from_plus_one_year.date())
# if end > tomorrow...
if qdate_to > qtomorrow:
# end = tomorrow
qdate_to = qtomorrow
# todo: update minimum and maximum of the calendar to forbid bad dates
# update calendar
self.view.date_from.setDateTime(qdate_from)
self.view.date_to.setDateTime(qdate_to)
# update model in table
ts_from = qdate_from.toTime_t()
ts_to = qdate_to.toTime_t()
self.view.table_history.model().set_period(ts_from, ts_to)
# refresh
self.refresh_balance()
self.refresh_pages()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment