Revised the constructor of the ReportUrl utility to better deal with the keyword arguments in the accounting application.

This commit is contained in:
依瑪貓 2020-08-07 09:41:02 +08:00
parent ceb6a3454b
commit 23f7564e87

View File

@ -75,12 +75,11 @@ class ReportUrl:
"""The URL of the accounting reports. """The URL of the accounting reports.
Args: Args:
**kwargs: the keyword arguments:
period (Period): The currently-specified period.
cash (Account): The currently-specified account of the cash (Account): The currently-specified account of the
cash account or cash summary. cash account or cash summary.
ledger (Account): The currently-specified account of the ledger (Account): The currently-specified account of the
ledger or leger summary. ledger or leger summary.
period (Period): The currently-specified period.
Attributes: Attributes:
cash (str): The URL of the cash account. cash (str): The URL of the cash account.
@ -93,21 +92,14 @@ class ReportUrl:
balance_sheet (str): The URL of the balance sheet. balance_sheet (str): The URL of the balance sheet.
""" """
def __init__(self, **kwargs): def __init__(self, cash=None, ledger=None, period=None):
if "period" in kwargs: self._period = Period() if period is None else period
self._period = kwargs["period"]
else:
self._period = Period()
if "cash" in kwargs:
self._cash = kwargs["cash"]
else:
self._cash = Account.objects.get( self._cash = Account.objects.get(
code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"]) code=settings.ACCOUNTING["DEFAULT_CASH_ACCOUNT"])\
if "ledger" in kwargs: if cash is None else cash
self._ledger = kwargs["ledger"]
else:
self._ledger = Account.objects.get( self._ledger = Account.objects.get(
code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"]) code=settings.ACCOUNTING["DEFAULT_LEDGER_ACCOUNT"])\
if ledger is None else ledger
def cash(self): def cash(self):
return reverse( return reverse(