# The accounting application of the Mia project. # by imacat , 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. """ from django.urls import path, register_converter from mia_core.period import Period from . import views from mia_core import views as mia_core_views from .models import Transaction from .views import reports 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") 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") app_name = "accounting" urlpatterns = [ path("", views.home, name="home"), path("cash", reports.cash_default, name="cash.home"), path("cash//", reports.cash, name="cash"), path("cash-summary", reports.cash_summary_default, name="cash-summary.home"), path("cash-summary/", reports.cash_summary, name="cash-summary"), path("ledger", reports.ledger_default, name="ledger.home"), path("ledger//", reports.ledger, name="ledger"), path("ledger-summary", reports.ledger_summary_default, name="ledger-summary.home"), path("ledger-summary/", reports.ledger_summary, name="ledger-summary"), path("journal", reports.journal_default, name="journal.home"), path("journal/", reports.journal, name="journal"), path("trial-balance", reports.trial_balance_default, name="trial-balance.home"), path("trial-balance/", reports.trial_balance, name="trial-balance"), path("income-statement", reports.income_statement_default, name="income-statement.home"), path("income-statement/", reports.income_statement, name="income-statement"), path("balance-sheet", reports.balance_sheet_default, name="balance-sheet.home"), path("balance-sheet/", reports.balance_sheet, name="balance-sheet"), path("search", reports.search, name="search"), path("transactions//create", mia_core_views.todo, name="transactions.create"), path("transactions//store", mia_core_views.todo, name="transactions.store"), path("transactions//", mia_core_views.todo, name="transactions.view"), path("transactions///edit", mia_core_views.todo, name="transactions.edit"), path("transactions///update", mia_core_views.todo, name="transactions.update"), path("transactions//delete", mia_core_views.todo, name="transactions.delete"), 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/", mia_core_views.todo, name="accounts.view"), path("accounts//edit", mia_core_views.todo, name="accounts.edit"), path("accounts//update", mia_core_views.todo, name="accounts.update"), path("accounts//delete", mia_core_views.todo, name="accounts.delete"), ]