2020-06-30 20:59:24 +08:00
|
|
|
# The accounting application of the Mia project.
|
|
|
|
# by imacat <imacat@mail.imacat.idv.tw>, 2020/6/30
|
|
|
|
|
|
|
|
# Copyright (c) 2020 imacat.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""The route settings of the accounting application.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2020-06-30 23:49:21 +08:00
|
|
|
from django.urls import path, register_converter
|
2020-06-30 20:59:24 +08:00
|
|
|
|
2020-07-21 22:05:39 +08:00
|
|
|
from mia_core.period import Period
|
2020-06-30 20:59:24 +08:00
|
|
|
from . import views
|
2020-07-09 23:19:48 +08:00
|
|
|
from mia_core import views as mia_core_views
|
2020-07-21 22:05:39 +08:00
|
|
|
from .models import Transaction
|
2020-07-21 08:20:57 +08:00
|
|
|
from .views import reports
|
2020-06-30 20:59:24 +08:00
|
|
|
|
2020-06-30 23:49:21 +08:00
|
|
|
|
|
|
|
class TransactionTypeConverter:
|
|
|
|
"""The path converter for the transaction types."""
|
|
|
|
regex = "income|expense|transfer"
|
|
|
|
|
|
|
|
def to_python(self, value):
|
|
|
|
return value
|
|
|
|
|
|
|
|
def to_url(self, value):
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
register_converter(TransactionTypeConverter, "txn-type")
|
|
|
|
|
2020-07-21 22:05:39 +08:00
|
|
|
|
|
|
|
class PeriodConverter:
|
|
|
|
"""The path converter for the period."""
|
|
|
|
regex = ".+"
|
|
|
|
|
|
|
|
def to_python(self, value):
|
|
|
|
"""Returns the period by the period specification.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (str): The period specification.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Period: The period.
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
|
|
|
def to_url(self, value):
|
|
|
|
"""Returns the specification of a period.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
value (Period|str): The period.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: The period specification.
|
|
|
|
"""
|
|
|
|
if isinstance(value, Period):
|
|
|
|
return value.spec
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
register_converter(PeriodConverter, "period")
|
|
|
|
|
2020-06-30 20:59:24 +08:00
|
|
|
app_name = "accounting"
|
|
|
|
urlpatterns = [
|
|
|
|
path("", views.home, name="home"),
|
2020-07-21 08:20:57 +08:00
|
|
|
path("cash", reports.cash_default, name="cash.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("cash/<str:account_code>/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.cash, name="cash"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("cash-summary",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.cash_summary_default, name="cash-summary.home"),
|
2020-07-21 10:38:47 +08:00
|
|
|
path("cash-summary/<str:account_code>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.cash_summary, name="cash-summary"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("ledger",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.ledger_default, name="ledger.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("ledger/<str:account_code>/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.ledger, name="ledger"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("ledger-summary",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.ledger_summary_default, name="ledger-summary.home"),
|
2020-07-21 10:38:47 +08:00
|
|
|
path("ledger-summary/<str:account_code>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.ledger_summary, name="ledger-summary"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("journal",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.journal_default, name="journal.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("journal/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.journal, name="journal"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("trial-balance",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.trial_balance_default, name="trial-balance.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("trial-balance/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.trial_balance, name="trial-balance"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("income-statement",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.income_statement_default, name="income-statement.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("income-statement/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.income_statement, name="income-statement"),
|
2020-07-11 07:12:53 +08:00
|
|
|
path("balance-sheet",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.balance_sheet_default, name="balance-sheet.home"),
|
2020-07-21 22:05:39 +08:00
|
|
|
path("balance-sheet/<period:period>",
|
2020-07-21 08:20:57 +08:00
|
|
|
reports.balance_sheet, name="balance-sheet"),
|
2020-07-09 23:19:48 +08:00
|
|
|
path("search",
|
2020-07-21 10:04:29 +08:00
|
|
|
reports.search, name="search"),
|
2020-07-09 23:19:48 +08:00
|
|
|
path("transactions/<txn-type:type>/create",
|
|
|
|
mia_core_views.todo, name="transactions.create"),
|
|
|
|
path("transactions/<txn-type:type>/store",
|
|
|
|
mia_core_views.todo, name="transactions.store"),
|
2020-07-02 09:45:11 +08:00
|
|
|
path("transactions/<txn-type:type>/<int:pk>",
|
2020-07-09 23:19:48 +08:00
|
|
|
mia_core_views.todo, name="transactions.view"),
|
2020-07-02 09:45:11 +08:00
|
|
|
path("transactions/<txn-type:type>/<int:pk>/edit",
|
2020-07-09 23:19:48 +08:00
|
|
|
mia_core_views.todo, name="transactions.edit"),
|
|
|
|
path("transactions/<txn-type:type>/<int:pk>/update",
|
|
|
|
mia_core_views.todo, name="transactions.update"),
|
|
|
|
path("transactions/<int:pk>/delete",
|
|
|
|
mia_core_views.todo, name="transactions.delete"),
|
2020-07-21 10:38:47 +08:00
|
|
|
path("accounts",
|
|
|
|
mia_core_views.todo, name="accounts"),
|
|
|
|
path("accounts/create",
|
|
|
|
mia_core_views.todo, name="accounts.create"),
|
|
|
|
path("accounts/store",
|
|
|
|
mia_core_views.todo, name="accounts.store"),
|
|
|
|
path("accounts/<str:account_code>",
|
|
|
|
mia_core_views.todo, name="accounts.view"),
|
|
|
|
path("accounts/<str:account_code>/edit",
|
|
|
|
mia_core_views.todo, name="accounts.edit"),
|
|
|
|
path("accounts/<str:account_code>/update",
|
|
|
|
mia_core_views.todo, name="accounts.update"),
|
|
|
|
path("accounts/<str:account_code>/delete",
|
|
|
|
mia_core_views.todo, name="accounts.delete"),
|
2020-06-30 20:59:24 +08:00
|
|
|
]
|