2020-07-14 10:02:16 +08:00
|
|
|
# The accounting application of the Mia project.
|
|
|
|
# by imacat <imacat@mail.imacat.idv.tw>, 2020/7/13
|
|
|
|
|
|
|
|
# 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 utilities of the accounting application.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2020-07-14 07:41:19 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2020-07-21 10:38:47 +08:00
|
|
|
from accounting.models import Account
|
2020-07-14 07:41:19 +08:00
|
|
|
from mia_core.period import Period
|
|
|
|
|
|
|
|
|
|
|
|
class ReportUrl:
|
|
|
|
"""The URL of the accounting reports.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
**kwargs: the keyword arguments:
|
|
|
|
period (Period): The currently-specified period.
|
2020-07-21 10:38:47 +08:00
|
|
|
cash (Account): The currently-specified account of the
|
2020-07-14 07:41:19 +08:00
|
|
|
cash account or cash summary.
|
2020-07-21 10:38:47 +08:00
|
|
|
ledger (Account): The currently-specified account of the
|
2020-07-14 07:41:19 +08:00
|
|
|
ledger or leger summary.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
cash (str): The URL of the cash account.
|
|
|
|
cash_summary (str): The URL of the cash summary.
|
|
|
|
ledger (str): The URL of the ledger.
|
|
|
|
ledger_summary (str): The URL of the ledger summary.
|
|
|
|
journal (str): The URL of the journal.
|
|
|
|
trial_balance (str): The URL of the trial balance.
|
|
|
|
income_statement (str): The URL of the income statement.
|
|
|
|
balance_sheet (str): The URL of the balance sheet.
|
|
|
|
"""
|
|
|
|
_period = None
|
2020-07-21 10:38:47 +08:00
|
|
|
_cash_account = None
|
|
|
|
_ledger_account = None
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
if "period" in kwargs:
|
|
|
|
self._period = kwargs["period"]
|
|
|
|
else:
|
2020-07-14 07:43:47 +08:00
|
|
|
self._period = Period()
|
2020-07-14 07:41:19 +08:00
|
|
|
if "cash" in kwargs:
|
2020-07-21 10:38:47 +08:00
|
|
|
self._cash_account = kwargs["cash"]
|
2020-07-14 07:41:19 +08:00
|
|
|
else:
|
2020-07-21 10:38:47 +08:00
|
|
|
self._cash_account = Account.objects.get(
|
|
|
|
code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"])
|
2020-07-14 07:41:19 +08:00
|
|
|
if "ledger" in kwargs:
|
2020-07-21 10:38:47 +08:00
|
|
|
self._ledger_account = kwargs["ledger"]
|
2020-07-14 07:41:19 +08:00
|
|
|
else:
|
2020-07-21 10:38:47 +08:00
|
|
|
self._ledger_account = Account.objects.get(
|
|
|
|
code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def cash(self):
|
|
|
|
return reverse(
|
|
|
|
"accounting:cash",
|
2020-07-21 22:05:39 +08:00
|
|
|
args=[self._cash_account.code, self._period])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def cash_summary(self):
|
|
|
|
return reverse(
|
2020-07-21 10:38:47 +08:00
|
|
|
"accounting:cash-summary", args=[self._cash_account.code])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ledger(self):
|
|
|
|
return reverse(
|
|
|
|
"accounting:ledger",
|
2020-07-21 22:05:39 +08:00
|
|
|
args=[self._ledger_account.code, self._period])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ledger_summary(self):
|
|
|
|
return reverse(
|
|
|
|
"accounting:ledger-summary",
|
2020-07-21 10:38:47 +08:00
|
|
|
args=[self._ledger_account.code])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def journal(self):
|
2020-07-21 22:05:39 +08:00
|
|
|
return reverse("accounting:journal", args=[self._period])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def trial_balance(self):
|
|
|
|
return reverse(
|
2020-07-21 22:05:39 +08:00
|
|
|
"accounting:trial-balance", args=[self._period])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def income_statement(self):
|
|
|
|
return reverse(
|
2020-07-21 22:05:39 +08:00
|
|
|
"accounting:income-statement", args=[self._period])
|
2020-07-14 07:41:19 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def balance_sheet(self):
|
|
|
|
return reverse(
|
2020-07-21 22:05:39 +08:00
|
|
|
"accounting:balance-sheet", args=[self._period])
|