Changed the unmatched offsets from a module to a report, and to show both the unapplied original line items and the unmatched offsets instead of only the unmatched offsets, and added the accumulated balance, in order for ease of use. Removed the match information from the unapplied original line item report. Added the currency and period filters to both the unapplied original line item report and unmatched offset reports.
This commit is contained in:
@ -23,18 +23,19 @@ from decimal import Decimal
|
||||
from flask import render_template, Response
|
||||
|
||||
from accounting.locale import gettext
|
||||
from accounting.models import Account, JournalEntryLineItem
|
||||
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
|
||||
from accounting.report.utils.csv_export import BaseCSVRow, csv_download, \
|
||||
period_spec
|
||||
from accounting.report.utils.offset_matcher import OffsetMatcher
|
||||
from accounting.report.utils.option_link import OptionLink
|
||||
from accounting.report.utils.report_chooser import ReportChooser
|
||||
from accounting.report.utils.report_type import ReportType
|
||||
from accounting.report.utils.unapplied import get_accounts_with_unapplied
|
||||
from accounting.report.utils.urls import unapplied_url
|
||||
from accounting.utils.offset_matcher import OffsetMatcher
|
||||
from accounting.utils.pagination import Pagination
|
||||
from accounting.utils.permission import can_edit
|
||||
|
||||
|
||||
class CSVRow(BaseCSVRow):
|
||||
@ -75,25 +76,32 @@ class CSVRow(BaseCSVRow):
|
||||
class PageParams(BasePageParams):
|
||||
"""The HTML page parameters."""
|
||||
|
||||
def __init__(self, account: Account,
|
||||
is_mark_matches: bool,
|
||||
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 is_mark_matches: Whether to mark the matched offsets.
|
||||
:param period: The period.
|
||||
:param pagination: The pagination.
|
||||
:param line_items: The line items.
|
||||
"""
|
||||
self.currency: Currency = currency
|
||||
"""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.is_mark_matches: bool = is_mark_matches
|
||||
"""Whether to mark the matched offsets."""
|
||||
self.period_chooser: PeriodChooser = PeriodChooser(
|
||||
lambda x: unapplied_url(currency, account, x))
|
||||
"""The period chooser."""
|
||||
|
||||
@property
|
||||
def has_data(self) -> bool:
|
||||
@ -109,8 +117,18 @@ class PageParams(BasePageParams):
|
||||
|
||||
:return: The report chooser.
|
||||
"""
|
||||
return ReportChooser(ReportType.UNAPPLIED,
|
||||
account=self.account)
|
||||
return ReportChooser(ReportType.UNAPPLIED, currency=self.currency,
|
||||
account=self.account, period=self.period)
|
||||
|
||||
@property
|
||||
def currency_options(self) -> list[OptionLink]:
|
||||
"""Returns the currency options.
|
||||
|
||||
:return: The currency options.
|
||||
"""
|
||||
return self._get_currency_options(
|
||||
lambda x: unapplied_url(x, self.account, self.period),
|
||||
self.currency)
|
||||
|
||||
@property
|
||||
def account_options(self) -> list[OptionLink]:
|
||||
@ -118,13 +136,15 @@ class PageParams(BasePageParams):
|
||||
|
||||
:return: The account options.
|
||||
"""
|
||||
options: list[OptionLink] = [OptionLink(gettext("Accounts"),
|
||||
unapplied_url(None),
|
||||
False)]
|
||||
options.extend([OptionLink(str(x),
|
||||
unapplied_url(x),
|
||||
x.id == self.account.id)
|
||||
for x in get_accounts_with_unapplied()])
|
||||
options: list[OptionLink] \
|
||||
= [OptionLink(gettext("Accounts"),
|
||||
unapplied_url(self.currency, None, self.period),
|
||||
False)]
|
||||
options.extend(
|
||||
[OptionLink(str(x),
|
||||
unapplied_url(self.currency, x, self.period),
|
||||
x.id == self.account.id)
|
||||
for x in get_accounts_with_unapplied(self.currency, self.period)])
|
||||
return options
|
||||
|
||||
|
||||
@ -146,27 +166,33 @@ def get_csv_rows(line_items: list[JournalEntryLineItem]) -> list[CSVRow]:
|
||||
class UnappliedOriginalLineItems(BaseReport):
|
||||
"""The unapplied original line items."""
|
||||
|
||||
def __init__(self, account: Account):
|
||||
def __init__(self, currency: Currency, account: Account, period: Period):
|
||||
"""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."""
|
||||
offset_matcher: OffsetMatcher = OffsetMatcher(self.__account)
|
||||
self.__period: Period = period
|
||||
"""The period."""
|
||||
offset_matcher: OffsetMatcher \
|
||||
= OffsetMatcher(self.__currency, self.__account, self.__period)
|
||||
self.__line_items: list[JournalEntryLineItem] \
|
||||
= offset_matcher.unapplied
|
||||
"""The line items."""
|
||||
self.__is_mark_matches: bool \
|
||||
= can_edit() and len(offset_matcher.unmatched_offsets) > 0
|
||||
"""Whether to mark the matched offsets."""
|
||||
|
||||
def csv(self) -> Response:
|
||||
"""Returns the report as CSV for download.
|
||||
|
||||
:return: The response of the report for download.
|
||||
"""
|
||||
filename: str = f"unapplied-{self.__account.code}.csv"
|
||||
filename: str = "unapplied-{currency}-{account}-{period}.csv"\
|
||||
.format(currency=self.__currency.code, account=self.__account.code,
|
||||
period=period_spec(self.__period))
|
||||
return csv_download(filename, get_csv_rows(self.__line_items))
|
||||
|
||||
def html(self) -> str:
|
||||
@ -177,8 +203,9 @@ class UnappliedOriginalLineItems(BaseReport):
|
||||
pagination: Pagination[JournalEntryLineItem] \
|
||||
= Pagination[JournalEntryLineItem](self.__line_items,
|
||||
is_reversed=True)
|
||||
params: PageParams = PageParams(account=self.__account,
|
||||
is_mark_matches=self.__is_mark_matches,
|
||||
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",
|
||||
|
Reference in New Issue
Block a user