Added the prep_desc property to Period to return the text descriptions with prepositions, to be easier to embed it in a text message in the Mia core application, and applied it in the accounting reports in the accounting application.

This commit is contained in:
依瑪貓 2020-08-03 22:20:20 +08:00
parent 512fd35adc
commit 3babe8bc1f
7 changed files with 29 additions and 7 deletions

View File

@ -27,7 +27,7 @@ First written: 2020/7/20
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with period=period.description context "Accounting|" %}Balance Sheet in {{ period }}{% endblocktrans %} {% blocktrans asvar title with prep_period=period.prep_desc context "Accounting|" %}Balance Sheet {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/1
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with account=account.title|title period=period.description context "Accounting|" %}Cash Account for {{ account }} in {{ period }}{% endblocktrans %} {% blocktrans asvar title with account=account.title|title prep_period=period.prep_desc context "Accounting|" %}Cash Account for {{ account }} {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/19
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with period=period.description context "Accounting|" %}Income Statement in {{ period }}{% endblocktrans %} {% blocktrans asvar title with prep_period=period.prep_desc context "Accounting|" %}Income Statement {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/17
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with period=period.description context "Accounting|" %}Journal in {{ period }}{% endblocktrans %} {% blocktrans asvar title with prep_period=period.prep_desc context "Accounting|" %}Journal {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/16
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with account=account.title|title period=period.description context "Accounting|" %}Ledger for {{ account }} in {{ period }}{% endblocktrans %} {% blocktrans asvar title with account=account.title|title prep_period=period.prep_desc context "Accounting|" %}Ledger for {{ account }} {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -27,7 +27,7 @@ First written: 2020/7/19
{% load accounting %} {% load accounting %}
{% block settings %} {% block settings %}
{% blocktrans asvar title with period=period.description context "Accounting|" %}Trial Balance in {{ period }}{% endblocktrans %} {% blocktrans asvar title with prep_period=period.prep_desc context "Accounting|" %}Trial Balance {{ prep_period }}{% endblocktrans %}
{% setvar "title" title %} {% setvar "title" title %}
{% setvar "use_period_chooser" True %} {% setvar "use_period_chooser" True %}
{% static "accounting/css/report.css" as file %}{% add_css file %} {% static "accounting/css/report.css" as file %}{% add_css file %}

View File

@ -82,6 +82,17 @@ class Period:
""" """
return self._period.description return self._period.description
@property
def prep_desc(self):
"""Returns the text description with preposition of the
currently-specified period.
Returns:
str: The text description with preposition of the
currently-specified period
"""
return self._period.prep_desc
@staticmethod @staticmethod
def _get_last_month_start(): def _get_last_month_start():
"""Returns the first day of the last month. """Returns the first day of the last month.
@ -409,6 +420,7 @@ class Period:
start (datetime.date): The start of the period. start (datetime.date): The start of the period.
end (datetime.date): The end of the period. end (datetime.date): The end of the period.
description (str): The text description of the period. description (str): The text description of the period.
prep_desc (str): The text description with preposition.
""" """
VERY_START = datetime.date(1990, 1, 1) VERY_START = datetime.date(1990, 1, 1)
@ -417,6 +429,7 @@ class Period:
self.start = None self.start = None
self.end = None self.end = None
self.description = None self.description = None
self.prep_desc = None
if spec is None: if spec is None:
self._set_this_month() self._set_this_month()
@ -431,6 +444,7 @@ class Period:
self.start = datetime.date(year, month, 1) self.start = datetime.date(year, month, 1)
self.end = self._month_last_day(self.start) self.end = self._month_last_day(self.start)
self.description = self._month_text(year, month) self.description = self._month_text(year, month)
self.prep_desc = gettext("In %s") % self.description
return return
# From a specific month # From a specific month
m = re.match("^([0-9]{4})-([0-9]{2})-$", spec) m = re.match("^([0-9]{4})-([0-9]{2})-$", spec)
@ -442,6 +456,7 @@ class Period:
self.end = self._month_last_day(timezone.localdate()) self.end = self._month_last_day(timezone.localdate())
self.description = gettext("Since %s")\ self.description = gettext("Since %s")\
% self._month_text(year, month) % self._month_text(year, month)
self.prep_desc = self.description
return return
# Until a specific month # Until a specific month
m = re.match("^-([0-9]{4})-([0-9]{2})$", spec) m = re.match("^-([0-9]{4})-([0-9]{2})$", spec)
@ -454,6 +469,7 @@ class Period:
self.end = self._month_last_day(until_month) self.end = self._month_last_day(until_month)
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._month_text(year, month) % self._month_text(year, month)
self.prep_desc = self.description
return return
# A specific year # A specific year
m = re.match("^([0-9]{4})$", spec) m = re.match("^([0-9]{4})$", spec)
@ -463,6 +479,7 @@ class Period:
self.start = datetime.date(year, 1, 1) self.start = datetime.date(year, 1, 1)
self.end = datetime.date(year, 12, 31) self.end = datetime.date(year, 12, 31)
self.description = self._year_text(year) self.description = self._year_text(year)
self.prep_desc = gettext("In %s") % self.description
return return
# Until a specific year # Until a specific year
m = re.match("^-([0-9]{4})$", spec) m = re.match("^-([0-9]{4})$", spec)
@ -473,12 +490,14 @@ class Period:
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._year_text(year) % self._year_text(year)
self.prep_desc = self.description
return return
# All time # All time
if spec == "-": if spec == "-":
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.end = self._month_last_day(timezone.localdate()) self.end = self._month_last_day(timezone.localdate())
self.description = gettext("All") self.description = gettext("All Time")
self.prep_desc = gettext("In %s") % self.description
return return
# A specific date # A specific date
m = re.match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$", m = re.match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$",
@ -491,6 +510,7 @@ class Period:
int(m.group(3))) int(m.group(3)))
self.end = self.start self.end = self.start
self.description = self._date_text(self.start) self.description = self._date_text(self.start)
self.prep_desc = gettext("In %s") % self.description
return return
# A specific date period # A specific date period
m = re.match(("^([0-9]{4})-([0-9]{2})-([0-9]{2})" m = re.match(("^([0-9]{4})-([0-9]{2})-([0-9]{2})"
@ -536,6 +556,7 @@ class Period:
else: else:
self.spec = dateformat.format(self.start, "Y-m-d") self.spec = dateformat.format(self.start, "Y-m-d")
self.description = self._date_text(self.start) self.description = self._date_text(self.start)
self.prep_desc = gettext("In %s") % self.description
return return
# Until a specific day # Until a specific day
m = re.match("^-([0-9]{4})-([0-9]{2})-([0-9]{2})$", spec) m = re.match("^-([0-9]{4})-([0-9]{2})-([0-9]{2})$", spec)
@ -548,6 +569,7 @@ class Period:
self.start = Period.Parser.VERY_START self.start = Period.Parser.VERY_START
self.description = gettext("Until %s")\ self.description = gettext("Until %s")\
% self._date_text(self.end) % self._date_text(self.end)
self.prep_desc = self.description
return return
# Wrong period format # Wrong period format
raise ValueError raise ValueError