diff --git a/accounting/converters.py b/accounting/converters.py index 17d1ccf..7b840ef 100644 --- a/accounting/converters.py +++ b/accounting/converters.py @@ -18,6 +18,8 @@ """The URL converters. """ +import datetime +import re from django.utils.translation import pgettext @@ -74,6 +76,37 @@ class PeriodConverter: return value +class DateConverter: + """The path converter for the date.""" + regex = "([0-9]{4})-([0-9]{2})-([0-9]{2})" + + def to_python(self, value): + """Returns the date by the date specification. + + Args: + value (str): The date specification. + + Returns: + datetime.date: The date. + """ + m = re.match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$", value) + year = int(m.group(1)) + month = int(m.group(2)) + day = int(m.group(3)) + return datetime.date(year, month, day) + + def to_url(self, value): + """Returns the specification of a date. + + Args: + value (datetime.date): The date. + + Returns: + str: The date specification. + """ + return value.strftime("%Y-%m-%d") + + class CashAccountConverter: """The path converter for the cash account.""" regex = "0|(11|12|21|22)[1-9]{1,3}" diff --git a/accounting/templates/accounting/transactions/expense/show.html b/accounting/templates/accounting/transactions/expense/show.html index bc9c3b9..8e0e27a 100644 --- a/accounting/templates/accounting/transactions/expense/show.html +++ b/accounting/templates/accounting/transactions/expense/show.html @@ -39,6 +39,33 @@ First written: 2020/7/23 {% endif %} + +
+ {% csrf_token %} + + +
+
@@ -48,6 +75,47 @@ First written: 2020/7/23 {% trans "Edit" context "Navigation|" as text %}{{ text|force_escape }} + {% if not item.has_many_same_day %} + + {% else %} + + + {% trans "Sort" context "Navigation|" as text %}{{ text|force_escape }} + + {% endif %} + + + {% trans "To Transfer" context "Navigation|" as text %}{{ text|force_escape }} + +
+ + +
+
diff --git a/accounting/templates/accounting/transactions/income/show.html b/accounting/templates/accounting/transactions/income/show.html index 1e19b68..ab982ce 100644 --- a/accounting/templates/accounting/transactions/income/show.html +++ b/accounting/templates/accounting/transactions/income/show.html @@ -39,6 +39,33 @@ First written: 2020/7/23
{% endif %} + +
+ {% csrf_token %} + + +
+
@@ -48,6 +75,47 @@ First written: 2020/7/23 {% trans "Edit" context "Navigation|" as text %}{{ text|force_escape }} + {% if not item.has_many_same_day %} + + {% else %} + + + {% trans "Sort" context "Navigation|" as text %}{{ text|force_escape }} + + {% endif %} + + + {% trans "To Transfer" context "Navigation|" as text %}{{ text|force_escape }} + +
+ + +
+
diff --git a/accounting/templates/accounting/transactions/transfer/show.html b/accounting/templates/accounting/transactions/transfer/show.html index ecb4309..968746e 100644 --- a/accounting/templates/accounting/transactions/transfer/show.html +++ b/accounting/templates/accounting/transactions/transfer/show.html @@ -39,6 +39,33 @@ First written: 2020/7/23
{% endif %} + +
+ {% csrf_token %} + + +
+
@@ -48,6 +75,39 @@ First written: 2020/7/23 {% trans "Edit" context "Navigation|" as text %}{{ text|force_escape }} + {% if not item.has_many_same_day %} + + {% else %} + + + {% trans "Sort" context "Navigation|" as text %}{{ text|force_escape }} + + {% endif %} +
+ + +
+
diff --git a/accounting/urls.py b/accounting/urls.py index 3290c9b..9d382e5 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -29,6 +29,7 @@ register_converter(converters.CashAccountConverter, "cash-account") register_converter(converters.LedgerAccountConverter, "ledger-account") register_converter(converters.TransactionTypeConverter, "txn-type") register_converter(converters.TransactionConverter, "txn") +register_converter(converters.DateConverter, "date") app_name = "accounting" urlpatterns = [ @@ -78,6 +79,8 @@ urlpatterns = [ mia_core_views.todo, name="transactions.update"), path("transactions//delete", mia_core_views.todo, name="transactions.delete"), + path("transactions/sort/", + mia_core_views.todo, name="transactions.sort"), path("accounts", mia_core_views.todo, name="accounts"), path("accounts/create",