Added the account list as the default page for the unapplied original line items.
This commit is contained in:
@ -33,7 +33,6 @@ from accounting.template_globals import default_currency_code
|
||||
from accounting.utils.current_account import CurrentAccount
|
||||
from .option_link import OptionLink
|
||||
from .report_type import ReportType
|
||||
from .unapplied import get_accounts_with_unapplied
|
||||
from .urls import journal_url, ledger_url, income_expenses_url, \
|
||||
trial_balance_url, income_statement_url, balance_sheet_url, unapplied_url
|
||||
|
||||
@ -161,7 +160,10 @@ class ReportChooser:
|
||||
"""
|
||||
account: Account = self.__account
|
||||
if not account.is_need_offset:
|
||||
account = get_accounts_with_unapplied()[0]
|
||||
return OptionLink(gettext("Unapplied Original Line Items"),
|
||||
unapplied_url(None),
|
||||
self.__active_report == ReportType.UNAPPLIED,
|
||||
fa_icon="fa-solid fa-link-slash")
|
||||
return OptionLink(gettext("Unapplied Original Line Items"),
|
||||
unapplied_url(account),
|
||||
self.__active_report == ReportType.UNAPPLIED,
|
||||
|
@ -19,6 +19,7 @@
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
|
||||
from accounting import db
|
||||
from accounting.models import Account, JournalEntryLineItem
|
||||
from accounting.utils.cast import be
|
||||
from accounting.utils.offset_alias import offset_alias
|
||||
@ -50,12 +51,17 @@ def get_accounts_with_unapplied() -> list[Account]:
|
||||
.group_by(JournalEntryLineItem.id)\
|
||||
.having(sa.or_(sa.func.count(offset.c.id) == 0, net_balance != 0))
|
||||
|
||||
count_func: sa.Function \
|
||||
= sa.func.count(JournalEntryLineItem.id)
|
||||
select: sa.Select = sa.select(Account.id)\
|
||||
count_func: sa.Label \
|
||||
= sa.func.count(JournalEntryLineItem.id).label("count")
|
||||
select: sa.Select = sa.select(Account.id, count_func)\
|
||||
.join(JournalEntryLineItem, isouter=True)\
|
||||
.filter(JournalEntryLineItem.id.in_(select_unapplied))\
|
||||
.group_by(Account.id)\
|
||||
.having(count_func > 0)
|
||||
return Account.query.filter(Account.id.in_(select))\
|
||||
counts: dict[int, int] \
|
||||
= {x.id: x.count for x in db.session.execute(select)}
|
||||
accounts: list[Account] = Account.query.filter(Account.id.in_(counts))\
|
||||
.order_by(Account.base_code, Account.no).all()
|
||||
for account in accounts:
|
||||
account.count = counts[account.id]
|
||||
return accounts
|
||||
|
@ -118,10 +118,13 @@ def balance_sheet_url(currency: Currency, period: Period) -> str:
|
||||
currency=currency, period=period)
|
||||
|
||||
|
||||
def unapplied_url(account: Account) -> str:
|
||||
def unapplied_url(account: Account | None) -> str:
|
||||
"""Returns the URL of the unapplied original line items.
|
||||
|
||||
:param account: The account.
|
||||
:param account: The account, or None to list the accounts with unapplied
|
||||
original line items.
|
||||
:return: The URL of the unapplied original line items.
|
||||
"""
|
||||
if account is None:
|
||||
return url_for("accounting-report.unapplied-default")
|
||||
return url_for("accounting-report.unapplied", account=account)
|
||||
|
Reference in New Issue
Block a user