Replaced the invalid_period() method in Period.Parser with ValueError in the Mia core application.

This commit is contained in:
2020-08-03 21:42:51 +08:00
parent 95cd08a887
commit 95e0173126
2 changed files with 42 additions and 65 deletions

View File

@ -52,15 +52,16 @@ class PeriodConverter:
Returns:
Period: The period.
Raises:
ValueError: When the period specification is invalid.
"""
first_txn = Transaction.objects.order_by("date").first()
data_start = first_txn.date if first_txn is not None else None
last_txn = Transaction.objects.order_by("-date").first()
data_end = last_txn.date if last_txn is not None else None
period = Period(value, data_start, data_end)
if period.error is not None:
raise ValueError
return period
# Raises ValueError
return Period(value, data_start, data_end)
def to_url(self, value):
"""Returns the specification of a period.