Removed the period filter from the unapplied original line items and unmatched offsets. It does not make sense for these two reports.

This commit is contained in:
2023-04-18 09:21:42 +08:00
parent 26b4d4388f
commit 014d67f7b8
16 changed files with 148 additions and 304 deletions

View File

@ -26,11 +26,9 @@ from sqlalchemy.orm import selectinload
from accounting.locale import gettext
from accounting.models import Currency, Account, JournalEntry, \
JournalEntryLineItem
from accounting.report.period import Period, PeriodChooser
from accounting.report.utils.base_page_params import BasePageParams
from accounting.report.utils.base_report import BaseReport
from accounting.report.utils.csv_export import BaseCSVRow, csv_download, \
period_spec
from accounting.report.utils.csv_export import BaseCSVRow, csv_download
from accounting.report.utils.option_link import OptionLink
from accounting.report.utils.report_chooser import ReportChooser
from accounting.report.utils.report_type import ReportType
@ -80,14 +78,12 @@ class PageParams(BasePageParams):
def __init__(self, currency: Currency,
account: Account,
period: Period,
pagination: Pagination[JournalEntryLineItem],
line_items: list[JournalEntryLineItem]):
"""Constructs the HTML page parameters.
:param currency: The currency.
:param account: The account.
:param period: The period.
:param pagination: The pagination.
:param line_items: The line items.
"""
@ -95,15 +91,10 @@ class PageParams(BasePageParams):
"""The currency."""
self.account: Account = account
"""The account."""
self.period: Period = period
"""The period."""
self.pagination: Pagination[JournalEntryLineItem] = pagination
"""The pagination."""
self.line_items: list[JournalEntryLineItem] = line_items
"""The line items."""
self.period_chooser: PeriodChooser = PeriodChooser(
lambda x: unapplied_url(currency, account, x))
"""The period chooser."""
@property
def has_data(self) -> bool:
@ -120,7 +111,7 @@ class PageParams(BasePageParams):
:return: The report chooser.
"""
return ReportChooser(ReportType.UNAPPLIED, currency=self.currency,
account=self.account, period=self.period)
account=self.account)
@property
def currency_options(self) -> list[OptionLink]:
@ -129,8 +120,7 @@ class PageParams(BasePageParams):
:return: The currency options.
"""
return self._get_currency_options(
lambda x: unapplied_url(x, self.account, self.period),
self.currency)
lambda x: unapplied_url(x, self.account), self.currency)
@property
def account_options(self) -> list[OptionLink]:
@ -140,13 +130,12 @@ class PageParams(BasePageParams):
"""
options: list[OptionLink] \
= [OptionLink(gettext("Accounts"),
unapplied_url(self.currency, None, self.period),
unapplied_url(self.currency, None),
False)]
options.extend(
[OptionLink(str(x),
unapplied_url(self.currency, x, self.period),
[OptionLink(str(x), unapplied_url(self.currency, x),
x.id == self.account.id)
for x in get_accounts_with_unapplied(self.currency, self.period)])
for x in get_accounts_with_unapplied(self.currency)])
return options
@ -168,19 +157,16 @@ def get_csv_rows(line_items: list[JournalEntryLineItem]) -> list[CSVRow]:
class UnappliedOriginalLineItems(BaseReport):
"""The unapplied original line items."""
def __init__(self, currency: Currency, account: Account, period: Period):
def __init__(self, currency: Currency, account: Account):
"""Constructs the unapplied original line items.
:param currency: The currency.
:param account: The account.
:param period: The period.
"""
self.__currency: Currency = currency
"""The currency."""
self.__account: Account = account
"""The account."""
self.__period: Period = period
"""The period."""
self.__line_items: list[JournalEntryLineItem] \
= self.__query_line_items()
"""The line items."""
@ -191,7 +177,7 @@ class UnappliedOriginalLineItems(BaseReport):
:return: The line items.
"""
net_balances: dict[int, Decimal | None] \
= get_net_balances(self.__currency, self.__account, self.__period)
= get_net_balances(self.__currency, self.__account)
line_items: list[JournalEntryLineItem] = JournalEntryLineItem.query \
.join(Account).join(JournalEntry) \
.filter(JournalEntryLineItem.id.in_(net_balances)) \
@ -210,9 +196,8 @@ class UnappliedOriginalLineItems(BaseReport):
:return: The response of the report for download.
"""
filename: str = "unapplied-{currency}-{account}-{period}.csv"\
.format(currency=self.__currency.code, account=self.__account.code,
period=period_spec(self.__period))
filename: str = "unapplied-{currency}-{account}.csv"\
.format(currency=self.__currency.code, account=self.__account.code)
return csv_download(filename, get_csv_rows(self.__line_items))
def html(self) -> str:
@ -225,7 +210,6 @@ class UnappliedOriginalLineItems(BaseReport):
is_reversed=True)
params: PageParams = PageParams(currency=self.__currency,
account=self.__account,
period=self.__period,
pagination=pagination,
line_items=pagination.list)
return render_template("accounting/report/unapplied.html",

View File

@ -24,7 +24,6 @@ from flask import render_template, Response
from accounting.locale import gettext
from accounting.models import Currency, Account
from accounting.report.period import Period, PeriodChooser
from accounting.report.utils.base_page_params import BasePageParams
from accounting.report.utils.base_report import BaseReport
from accounting.report.utils.csv_export import BaseCSVRow, csv_download
@ -61,24 +60,16 @@ class CSVRow(BaseCSVRow):
class PageParams(BasePageParams):
"""The HTML page parameters."""
def __init__(self, currency: Currency,
period: Period,
accounts: list[Account]):
def __init__(self, currency: Currency, accounts: list[Account]):
"""Constructs the HTML page parameters.
:param currency: The currency.
:param period: The period.
:param accounts: The accounts.
"""
self.currency: Currency = currency
"""The currency."""
self.period: Period = period
"""The period."""
self.accounts: list[Account] = accounts
"""The accounts."""
self.period_chooser: PeriodChooser = PeriodChooser(
lambda x: unapplied_url(currency, None, x))
"""The period chooser."""
@property
def has_data(self) -> bool:
@ -95,7 +86,7 @@ class PageParams(BasePageParams):
:return: The report chooser.
"""
return ReportChooser(ReportType.UNAPPLIED, currency=self.currency,
account=None, period=self.period)
account=None)
@property
def currency_options(self) -> list[OptionLink]:
@ -103,9 +94,8 @@ class PageParams(BasePageParams):
:return: The currency options.
"""
return self._get_currency_options(
lambda x: unapplied_url(x, None, self.period),
self.currency)
return self._get_currency_options(lambda x: unapplied_url(x, None),
self.currency)
@property
def account_options(self) -> list[OptionLink]:
@ -115,12 +105,10 @@ class PageParams(BasePageParams):
"""
options: list[OptionLink] \
= [OptionLink(gettext("Accounts"),
unapplied_url(self.currency, None, self.period),
unapplied_url(self.currency, None),
True)]
options.extend(
[OptionLink(str(x),
unapplied_url(self.currency, x, self.period),
False)
[OptionLink(str(x), unapplied_url(self.currency, x), False)
for x in self.accounts])
return options
@ -140,18 +128,14 @@ def get_csv_rows(accounts: list[Account]) -> list[CSVRow]:
class AccountsWithUnappliedOriginalLineItems(BaseReport):
"""The accounts with unapplied original line items."""
def __init__(self, currency: Currency, period: Period):
def __init__(self, currency: Currency):
"""Constructs the outstanding balances.
:param currency: The currency.
:param period: The period.
"""
self.__currency: Currency = currency
"""The currency."""
self.__period: Period = period
"""The period."""
self.__accounts: list[Account] \
= get_accounts_with_unapplied(currency, period)
self.__accounts: list[Account] = get_accounts_with_unapplied(currency)
"""The accounts."""
def csv(self) -> Response:
@ -169,5 +153,4 @@ class AccountsWithUnappliedOriginalLineItems(BaseReport):
"""
return render_template("accounting/report/unapplied-accounts.html",
report=PageParams(currency=self.__currency,
period=self.__period,
accounts=self.__accounts))

View File

@ -25,11 +25,9 @@ from flask_babel import LazyString
from accounting.locale import gettext
from accounting.models import Currency, Account, JournalEntryLineItem
from accounting.report.period import Period, PeriodChooser
from accounting.report.utils.base_page_params import BasePageParams
from accounting.report.utils.base_report import BaseReport
from accounting.report.utils.csv_export import BaseCSVRow, csv_download, \
period_spec
from accounting.report.utils.csv_export import BaseCSVRow, csv_download
from accounting.report.utils.offset_matcher import OffsetMatcher, OffsetPair
from accounting.report.utils.option_link import OptionLink
from accounting.report.utils.report_chooser import ReportChooser
@ -82,7 +80,6 @@ class PageParams(BasePageParams):
def __init__(self, currency: Currency,
account: Account,
period: Period,
match_status: str | LazyString,
matched_pairs: list[OffsetPair],
pagination: Pagination[JournalEntryLineItem],
@ -91,7 +88,6 @@ class PageParams(BasePageParams):
:param currency: The currency.
:param account: The account.
:param period: The period.
:param match_status: The match status message.
:param matched_pairs: A list of matched pairs.
:param pagination: The pagination.
@ -101,8 +97,6 @@ class PageParams(BasePageParams):
"""The currency."""
self.account: Account = account
"""The account."""
self.period: Period = period
"""The period."""
self.match_status: str | LazyString = match_status
"""The match status message."""
self.matched_pairs: list[OffsetPair] = matched_pairs
@ -111,9 +105,6 @@ class PageParams(BasePageParams):
"""The pagination."""
self.line_items: list[JournalEntryLineItem] = line_items
"""The line items."""
self.period_chooser: PeriodChooser = PeriodChooser(
lambda x: unmatched_url(currency, account, x))
"""The period chooser."""
@property
def has_data(self) -> bool:
@ -139,8 +130,7 @@ class PageParams(BasePageParams):
:return: The currency options.
"""
return self._get_currency_options(
lambda x: unmatched_url(x, self.account, self.period),
self.currency)
lambda x: unmatched_url(x, self.account), self.currency)
@property
def account_options(self) -> list[OptionLink]:
@ -150,13 +140,12 @@ class PageParams(BasePageParams):
"""
options: list[OptionLink] \
= [OptionLink(gettext("Accounts"),
unmatched_url(self.currency, None, self.period),
unmatched_url(self.currency, None),
False)]
options.extend(
[OptionLink(str(x),
unmatched_url(self.currency, x, self.period),
[OptionLink(str(x), unmatched_url(self.currency, x),
x.id == self.account.id)
for x in get_accounts_with_unmatched(self.currency, self.period)])
for x in get_accounts_with_unmatched(self.currency)])
return options
@ -178,21 +167,18 @@ def get_csv_rows(line_items: list[JournalEntryLineItem]) -> list[CSVRow]:
class UnmatchedOffsets(BaseReport):
"""The unmatched offsets."""
def __init__(self, currency: Currency, account: Account, period: Period):
def __init__(self, currency: Currency, account: Account):
"""Constructs the unmatched offsets.
:param currency: The currency.
:param account: The account.
:param period: The period.
"""
self.__currency: Currency = currency
"""The currency."""
self.__account: Account = account
"""The account."""
self.__period: Period = period
"""The period."""
offset_matcher: OffsetMatcher \
= OffsetMatcher(self.__currency, self.__account, self.__period)
= OffsetMatcher(self.__currency, self.__account)
self.__line_items: list[JournalEntryLineItem] \
= offset_matcher.line_items
"""The line items."""
@ -206,9 +192,8 @@ class UnmatchedOffsets(BaseReport):
:return: The response of the report for download.
"""
filename: str = "unmatched-{currency}-{account}-{period}.csv"\
.format(currency=self.__currency.code, account=self.__account.code,
period=period_spec(self.__period))
filename: str = "unmatched-{currency}-{account}.csv"\
.format(currency=self.__currency.code, account=self.__account.code)
return csv_download(filename, get_csv_rows(self.__line_items))
def html(self) -> str:
@ -221,7 +206,6 @@ class UnmatchedOffsets(BaseReport):
is_reversed=True)
params: PageParams = PageParams(currency=self.__currency,
account=self.__account,
period=self.__period,
match_status=self.__match_status,
matched_pairs=self.__matched_pairs,
pagination=pagination,

View File

@ -24,7 +24,6 @@ from flask import render_template, Response
from accounting.locale import gettext
from accounting.models import Currency, Account
from accounting.report.period import Period, PeriodChooser
from accounting.report.utils.base_page_params import BasePageParams
from accounting.report.utils.base_report import BaseReport
from accounting.report.utils.csv_export import BaseCSVRow, csv_download
@ -61,24 +60,16 @@ class CSVRow(BaseCSVRow):
class PageParams(BasePageParams):
"""The HTML page parameters."""
def __init__(self, currency: Currency,
period: Period,
accounts: list[Account]):
def __init__(self, currency: Currency, accounts: list[Account]):
"""Constructs the HTML page parameters.
:param currency: The currency.
:param period: The period.
:param accounts: The accounts.
"""
self.currency: Currency = currency
"""The currency."""
self.period: Period = period
"""The period."""
self.accounts: list[Account] = accounts
"""The accounts."""
self.period_chooser: PeriodChooser = PeriodChooser(
lambda x: unmatched_url(currency, None, x))
"""The period chooser."""
@property
def has_data(self) -> bool:
@ -95,7 +86,7 @@ class PageParams(BasePageParams):
:return: The report chooser.
"""
return ReportChooser(ReportType.UNMATCHED, currency=self.currency,
account=None, period=self.period)
account=None)
@property
def currency_options(self) -> list[OptionLink]:
@ -103,9 +94,8 @@ class PageParams(BasePageParams):
:return: The currency options.
"""
return self._get_currency_options(
lambda x: unmatched_url(x, None, self.period),
self.currency)
return self._get_currency_options(lambda x: unmatched_url(x, None),
self.currency)
@property
def account_options(self) -> list[OptionLink]:
@ -115,12 +105,10 @@ class PageParams(BasePageParams):
"""
options: list[OptionLink] \
= [OptionLink(gettext("Accounts"),
unmatched_url(self.currency, None, self.period),
unmatched_url(self.currency, None),
True)]
options.extend(
[OptionLink(str(x),
unmatched_url(self.currency, x, self.period),
False)
[OptionLink(str(x), unmatched_url(self.currency, x), False)
for x in self.accounts])
return options
@ -140,18 +128,15 @@ def get_csv_rows(accounts: list[Account]) -> list[CSVRow]:
class AccountsWithUnmatchedOffsets(BaseReport):
"""The accounts with unmatched offsets."""
def __init__(self, currency: Currency, period: Period):
def __init__(self, currency: Currency):
"""Constructs the outstanding balances.
:param currency: The currency.
:param period: The period.
"""
self.__currency: Currency = currency
"""The currency."""
self.__period: Period = period
"""The period."""
self.__accounts: list[Account] \
= get_accounts_with_unmatched(currency, period)
= get_accounts_with_unmatched(currency)
"""The accounts."""
def csv(self) -> Response:
@ -169,5 +154,4 @@ class AccountsWithUnmatchedOffsets(BaseReport):
"""
return render_template("accounting/report/unmatched-accounts.html",
report=PageParams(currency=self.__currency,
period=self.__period,
accounts=self.__accounts))