Replaced the views of the default accounting reports with class-based redirect views in the accounting application.
This commit is contained in:
parent
e64089f06f
commit
a8058209bd
@ -20,8 +20,11 @@
|
||||
"""
|
||||
|
||||
from django.urls import path, register_converter
|
||||
from django.views.decorators.http import require_GET
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from mia_core import views as mia_core_views
|
||||
from mia_core.digest_auth import digest_login_required
|
||||
from . import converters, views
|
||||
|
||||
register_converter(converters.PeriodConverter, "period")
|
||||
@ -33,36 +36,41 @@ register_converter(converters.DateConverter, "date")
|
||||
|
||||
app_name = "accounting"
|
||||
urlpatterns = [
|
||||
path("", views.home, name="home"),
|
||||
path("cash", views.cash_default, name="cash.home"),
|
||||
path("", require_GET(digest_login_required(RedirectView.as_view(
|
||||
query_string = True,
|
||||
pattern_name = "accounting:cash.home",
|
||||
))), name="home"),
|
||||
path("cash",
|
||||
views.CashDefaultView.as_view(), name="cash.home"),
|
||||
path("cash/<cash-account:account>/<period:period>",
|
||||
views.cash, name="cash"),
|
||||
path("cash-summary",
|
||||
views.cash_summary_default, name="cash-summary.home"),
|
||||
views.CashSummaryDefaultView.as_view(), name="cash-summary.home"),
|
||||
path("cash-summary/<cash-account:account>",
|
||||
views.cash_summary, name="cash-summary"),
|
||||
path("ledger",
|
||||
views.ledger_default, name="ledger.home"),
|
||||
views.LedgerDefaultView.as_view(), name="ledger.home"),
|
||||
path("ledger/<ledger-account:account>/<period:period>",
|
||||
views.ledger, name="ledger"),
|
||||
path("ledger-summary",
|
||||
views.ledger_summary_default, name="ledger-summary.home"),
|
||||
views.LedgerSummaryDefaultView.as_view(), name="ledger-summary.home"),
|
||||
path("ledger-summary/<ledger-account:account>",
|
||||
views.ledger_summary, name="ledger-summary"),
|
||||
path("journal",
|
||||
views.journal_default, name="journal.home"),
|
||||
views.JournalDefaultView.as_view(), name="journal.home"),
|
||||
path("journal/<period:period>",
|
||||
views.journal, name="journal"),
|
||||
path("trial-balance",
|
||||
views.trial_balance_default, name="trial-balance.home"),
|
||||
views.TrialBalanceDefaultView.as_view(), name="trial-balance.home"),
|
||||
path("trial-balance/<period:period>",
|
||||
views.trial_balance, name="trial-balance"),
|
||||
path("income-statement",
|
||||
views.income_statement_default, name="income-statement.home"),
|
||||
views.IncomeStatementDefaultView.as_view(),
|
||||
name="income-statement.home"),
|
||||
path("income-statement/<period:period>",
|
||||
views.income_statement, name="income-statement"),
|
||||
path("balance-sheet",
|
||||
views.balance_sheet_default, name="balance-sheet.home"),
|
||||
views.BalanceSheetDefaultView.as_view(), name="balance-sheet.home"),
|
||||
path("balance-sheet/<period:period>",
|
||||
views.balance_sheet, name="balance-sheet"),
|
||||
path("search",
|
||||
|
@ -24,11 +24,12 @@ from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Sum, Case, When, F, Q
|
||||
from django.db.models.functions import TruncMonth, Coalesce
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import pgettext, gettext_noop
|
||||
from django.views.decorators.http import require_GET, require_POST
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from mia_core.digest_auth import digest_login_required
|
||||
from mia_core.period import Period
|
||||
@ -40,39 +41,18 @@ from .utils import ReportUrl, get_cash_accounts, get_ledger_accounts, \
|
||||
sort_form_transaction_records, fill_transaction_from_previous_form
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def home(request):
|
||||
"""The accounting home page.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class CashDefaultView(RedirectView):
|
||||
"""The default cash account."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:cash"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default
|
||||
accounting report.
|
||||
"""
|
||||
return HttpResponseRedirect(reverse("accounting:cash.home"))
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def cash_default(request):
|
||||
"""The default cash account.
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default account
|
||||
and month.
|
||||
"""
|
||||
account = Account.objects.get(
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["account"] = Account.objects.get(
|
||||
code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"])
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:cash", args=(account, Period.default_spec())))
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -177,22 +157,17 @@ def cash(request, account, period):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def cash_summary_default(request):
|
||||
"""The default cash account summary.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class CashSummaryDefaultView(RedirectView):
|
||||
"""The default cash account summary."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:cash-summary"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default account.
|
||||
"""
|
||||
account = Account.objects.get(
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["account"] = Account.objects.get(
|
||||
code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"])
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:cash-summary", args=(account,)))
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -279,23 +254,18 @@ def cash_summary(request, account):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def ledger_default(request):
|
||||
"""The default ledger.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class LedgerDefaultView(RedirectView):
|
||||
"""The default ledger."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:ledger"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default account
|
||||
and month.
|
||||
"""
|
||||
account = Account.objects.get(
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["account"] = Account.objects.get(
|
||||
code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:ledger", args=(account, Period.default_spec())))
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -318,7 +288,8 @@ def ledger(request, account, period):
|
||||
transaction__date__gte=period.start,
|
||||
transaction__date__lte=period.end,
|
||||
account__code__startswith=account.code)
|
||||
.order_by("transaction__date", "transaction__ord", "is_credit", "ord"))
|
||||
.order_by("transaction__date", "transaction__ord", "is_credit",
|
||||
"ord"))
|
||||
if re.match("^[1-3]", account.code) is not None:
|
||||
balance = Record.objects \
|
||||
.filter(
|
||||
@ -359,22 +330,17 @@ def ledger(request, account, period):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def ledger_summary_default(request):
|
||||
"""The default ledger summary.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class LedgerSummaryDefaultView(RedirectView):
|
||||
"""The default ledger summary."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:ledger-summary"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default account.
|
||||
"""
|
||||
account = Account.objects.get(
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["account"] = Account.objects.get(
|
||||
code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:ledger-summary", args=(account,)))
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -426,20 +392,16 @@ def ledger_summary(request, account):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def journal_default(request):
|
||||
"""The default journal.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class JournalDefaultView(RedirectView):
|
||||
"""The default journal."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:journal"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default month.
|
||||
"""
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:journal", args=(Period.default_spec(),)))
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -512,20 +474,16 @@ def journal(request, period):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def trial_balance_default(request):
|
||||
"""The default trial balance.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class TrialBalanceDefaultView(RedirectView):
|
||||
"""The default trial balance."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:trial-balance"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default month.
|
||||
"""
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:trial-balance", args=(Period.default_spec(),)))
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -620,20 +578,16 @@ def trial_balance(request, period):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def income_statement_default(request):
|
||||
"""The default income statement.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class IncomeStatementDefaultView(RedirectView):
|
||||
"""The default income statement."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:income-statement"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default month.
|
||||
"""
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:income-statement", args=(Period.default_spec(),)))
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
@ -704,20 +658,16 @@ def income_statement(request, period):
|
||||
})
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@require_GET
|
||||
@digest_login_required
|
||||
def balance_sheet_default(request):
|
||||
"""The default balance sheet.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
@method_decorator(digest_login_required, name="dispatch")
|
||||
class BalanceSheetDefaultView(RedirectView):
|
||||
"""The default balance sheet."""
|
||||
query_string = True
|
||||
pattern_name = "accounting:balance-sheet"
|
||||
|
||||
Args:
|
||||
request (HttpRequest) The request.
|
||||
|
||||
Returns:
|
||||
HttpResponseRedirect: The redirection to the default month.
|
||||
"""
|
||||
return HttpResponseRedirect(
|
||||
reverse("accounting:balance-sheet", args=(Period.default_spec(),)))
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
kwargs["period"] = Period.default_spec()
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
@require_GET
|
||||
|
Loading…
Reference in New Issue
Block a user