Renamed "voucher line item" to "journal entry line item".

This commit is contained in:
2023-03-20 20:52:35 +08:00
parent e26af6f3fc
commit 8f909965a9
34 changed files with 336 additions and 303 deletions

View File

@ -26,7 +26,7 @@ from sqlalchemy.orm import selectinload
from accounting import db
from accounting.locale import gettext
from accounting.models import Currency, Account, Voucher, VoucherLineItem
from accounting.models import Currency, Account, Voucher, 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
@ -43,10 +43,10 @@ from accounting.utils.pagination import Pagination
class ReportLineItem:
"""A line item in the report."""
def __init__(self, line_item: VoucherLineItem | None = None):
def __init__(self, line_item: JournalEntryLineItem | None = None):
"""Constructs the line item in the report.
:param line_item: The voucher line item.
:param line_item: The journal entry line item.
"""
self.is_brought_forward: bool = False
"""Whether this is the brought-forward line item."""
@ -65,7 +65,7 @@ class ReportLineItem:
self.note: str | None = None
"""The note."""
self.url: str | None = None
"""The URL to the voucher line item."""
"""The URL to the journal entry line item."""
if line_item is not None:
self.date = line_item.voucher.date
self.description = line_item.description
@ -114,11 +114,13 @@ class LineItemCollector:
if self.__account.is_nominal:
return None
balance_func: sa.Function = sa.func.sum(sa.case(
(VoucherLineItem.is_debit, VoucherLineItem.amount),
else_=-VoucherLineItem.amount))
(JournalEntryLineItem.is_debit, JournalEntryLineItem.amount),
else_=-JournalEntryLineItem.amount))
select: sa.Select = sa.Select(balance_func).join(Voucher)\
.filter(be(VoucherLineItem.currency_code == self.__currency.code),
be(VoucherLineItem.account_id == self.__account.id),
.filter(be(JournalEntryLineItem.currency_code
== self.__currency.code),
be(JournalEntryLineItem.account_id
== self.__account.id),
Voucher.date < self.__period.start)
balance: int | None = db.session.scalar(select)
if balance is None:
@ -140,19 +142,20 @@ class LineItemCollector:
:return: The line items.
"""
conditions: list[sa.BinaryExpression] \
= [VoucherLineItem.currency_code == self.__currency.code,
VoucherLineItem.account_id == self.__account.id]
= [JournalEntryLineItem.currency_code == self.__currency.code,
JournalEntryLineItem.account_id == self.__account.id]
if self.__period.start is not None:
conditions.append(Voucher.date >= self.__period.start)
if self.__period.end is not None:
conditions.append(Voucher.date <= self.__period.end)
return [ReportLineItem(x) for x in VoucherLineItem.query.join(Voucher)
return [ReportLineItem(x) for x in JournalEntryLineItem.query
.join(Voucher)
.filter(*conditions)
.order_by(Voucher.date,
Voucher.no,
VoucherLineItem.is_debit.desc(),
VoucherLineItem.no)
.options(selectinload(VoucherLineItem.voucher)).all()]
JournalEntryLineItem.is_debit.desc(),
JournalEntryLineItem.no)
.options(selectinload(JournalEntryLineItem.voucher)).all()]
def __get_total(self) -> ReportLineItem | None:
"""Composes the total line item.
@ -307,9 +310,10 @@ class PageParams(BasePageParams):
:return: The account options.
"""
in_use: sa.Select = sa.Select(VoucherLineItem.account_id)\
.filter(be(VoucherLineItem.currency_code == self.currency.code))\
.group_by(VoucherLineItem.account_id)
in_use: sa.Select = sa.Select(JournalEntryLineItem.account_id)\
.filter(be(JournalEntryLineItem.currency_code
== self.currency.code))\
.group_by(JournalEntryLineItem.account_id)
return [OptionLink(str(x), ledger_url(self.currency, x, self.period),
x.id == self.account.id)
for x in Account.query.filter(Account.id.in_(in_use))