Renamed the variables.

This commit is contained in:
依瑪貓 2020-07-19 21:08:10 +08:00
parent a62d5df9a3
commit b8b5546b9f
2 changed files with 44 additions and 44 deletions

View File

@ -216,7 +216,7 @@ def cash(request, subject_code, period_spec):
balance=balance_before)) balance=balance_before))
records.append(record_sum) records.append(record_sum)
pagination = Pagination(request, records, True) pagination = Pagination(request, records, True)
records = pagination.records records = pagination.items
_find_imbalanced(records) _find_imbalanced(records)
_find_order_holes(records) _find_order_holes(records)
shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"] shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"]
@ -243,9 +243,9 @@ def cash_summary(request, subject_code):
current_subject = subject current_subject = subject
if current_subject is None: if current_subject is None:
raise Http404() raise Http404()
# The accounting records # The month summaries
if current_subject.code == "0": if current_subject.code == "0":
records = [RecordSummary(**x) for x in Record.objects.filter( months = [RecordSummary(**x) for x in Record.objects.filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
Q(record__subject__code__startswith="11") | Q(record__subject__code__startswith="11") |
Q(record__subject__code__startswith="12") | Q(record__subject__code__startswith="12") |
@ -269,7 +269,7 @@ def cash_summary(request, subject_code):
When(is_credit=False, then=-F("amount")), When(is_credit=False, then=-F("amount")),
default=F("amount"))))] default=F("amount"))))]
else: else:
records = [RecordSummary(**x) for x in Record.objects.filter( months = [RecordSummary(**x) for x in Record.objects.filter(
Q(transaction__in=Transaction.objects.filter( Q(transaction__in=Transaction.objects.filter(
record__subject__code__startswith=current_subject.code)), record__subject__code__startswith=current_subject.code)),
~Q(subject__code__startswith=current_subject.code)) \ ~Q(subject__code__startswith=current_subject.code)) \
@ -287,20 +287,20 @@ def cash_summary(request, subject_code):
When(is_credit=False, then=-F("amount")), When(is_credit=False, then=-F("amount")),
default=F("amount"))))] default=F("amount"))))]
cumulative_balance = 0 cumulative_balance = 0
for record in records: for month in months:
cumulative_balance = cumulative_balance + record.balance cumulative_balance = cumulative_balance + month.balance
record.cumulative_balance = cumulative_balance month.cumulative_balance = cumulative_balance
records.append(RecordSummary( months.append(RecordSummary(
label=pgettext("Accounting|", "Total"), label=pgettext("Accounting|", "Total"),
credit=sum([x.credit for x in records]), credit=sum([x.credit for x in months]),
debit=sum([x.debit for x in records]), debit=sum([x.debit for x in months]),
balance=sum([x.balance for x in records]), balance=sum([x.balance for x in months]),
cumulative_balance=cumulative_balance, cumulative_balance=cumulative_balance,
)) ))
pagination = Pagination(request, records, True) pagination = Pagination(request, months, True)
shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"] shortcut_subjects = settings.ACCOUNTING["CASH_SHORTCUT_SUBJECTS"]
return render(request, "accounting/cash-summary.html", { return render(request, "accounting/cash-summary.html", {
"item_list": pagination.records, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_subject": current_subject,
"reports": ReportUrl(cash=current_subject), "reports": ReportUrl(cash=current_subject),
@ -375,7 +375,7 @@ def ledger(request, subject_code, period_spec):
if record_brought_forward is not None: if record_brought_forward is not None:
records.insert(0, record_brought_forward) records.insert(0, record_brought_forward)
pagination = Pagination(request, records, True) pagination = Pagination(request, records, True)
records = pagination.records records = pagination.items
_find_imbalanced(records) _find_imbalanced(records)
_find_order_holes(records) _find_order_holes(records)
return render(request, "accounting/ledger.html", { return render(request, "accounting/ledger.html", {
@ -398,8 +398,8 @@ def ledger_summary(request, subject_code):
current_subject = subject current_subject = subject
if current_subject is None: if current_subject is None:
raise Http404() raise Http404()
# The accounting records # The month summaries
records = [RecordSummary(**x) for x in Record.objects\ months = [RecordSummary(**x) for x in Record.objects\
.filter(subject__code__startswith=current_subject.code)\ .filter(subject__code__startswith=current_subject.code)\
.annotate(month=TruncMonth("transaction__date"))\ .annotate(month=TruncMonth("transaction__date"))\
.values("month")\ .values("month")\
@ -415,19 +415,19 @@ def ledger_summary(request, subject_code):
When(is_credit=False, then=F("amount")), When(is_credit=False, then=F("amount")),
default=-F("amount"))))] default=-F("amount"))))]
cumulative_balance = 0 cumulative_balance = 0
for record in records: for month in months:
cumulative_balance = cumulative_balance + record.balance cumulative_balance = cumulative_balance + month.balance
record.cumulative_balance = cumulative_balance month.cumulative_balance = cumulative_balance
records.append(RecordSummary( months.append(RecordSummary(
label=pgettext("Accounting|", "Total"), label=pgettext("Accounting|", "Total"),
credit=sum([x.credit for x in records]), credit=sum([x.credit for x in months]),
debit=sum([x.debit for x in records]), debit=sum([x.debit for x in months]),
balance=sum([x.balance for x in records]), balance=sum([x.balance for x in months]),
cumulative_balance=cumulative_balance, cumulative_balance=cumulative_balance,
)) ))
pagination = Pagination(request, records, True) pagination = Pagination(request, months, True)
return render(request, "accounting/ledger-summary.html", { return render(request, "accounting/ledger-summary.html", {
"item_list": pagination.records, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"current_subject": current_subject, "current_subject": current_subject,
"reports": ReportUrl(ledger=current_subject), "reports": ReportUrl(ledger=current_subject),
@ -490,7 +490,7 @@ def journal(request, period_spec):
+ list(records) + list(records)
pagination = Pagination(request, records, True) pagination = Pagination(request, records, True)
return render(request, "accounting/journal.html", { return render(request, "accounting/journal.html", {
"item_list": pagination.records, "item_list": pagination.items,
"pagination": pagination, "pagination": pagination,
"period": period, "period": period,
}) })
@ -561,17 +561,17 @@ def trial_balance(request, period_spec):
brought_forward.debit = None brought_forward.debit = None
brought_forward.credit = -balance brought_forward.credit = -balance
real.append(brought_forward) real.append(brought_forward)
records = nominal + real accounts = nominal + real
records.sort(key=lambda x: x.code) accounts.sort(key=lambda x: x.code)
record_sum = Subject() total_account = Subject()
record_sum.title = pgettext("Accounting|", "Total") total_account.title = pgettext("Accounting|", "Total")
record_sum.debit = sum([x.debit for x in records total_account.debit = sum([x.debit for x in accounts
if x.debit is not None]) if x.debit is not None])
record_sum.credit = sum([x.credit for x in records total_account.credit = sum([x.credit for x in accounts
if x.credit is not None]) if x.credit is not None])
return render(request, "accounting/trial-balance.html", { return render(request, "accounting/trial-balance.html", {
"item_list": records, "item_list": accounts,
"total_item": record_sum, "total_item": total_account,
"reports": ReportUrl(period=period), "reports": ReportUrl(period=period),
"period": period, "period": period,
}) })

View File

@ -209,9 +209,9 @@ class Pagination:
Args: Args:
request (HttpRequest): The request request (HttpRequest): The request
records (list[Model]): All the records items (list): All the items
page_no (int): The specified page number page_no (int): The specified page number
page_size (int): The specified number of records per page page_size (int): The specified number of items per page
is_reversed (bool): Whether we should display the last is_reversed (bool): Whether we should display the last
page first page first
@ -225,7 +225,7 @@ class Pagination:
total_pages (int): The total number of pages available. total_pages (int): The total number of pages available.
is_paged (bool): Whether there are more than one page. is_paged (bool): Whether there are more than one page.
page_no (int): The current page number. page_no (int): The current page number.
records (list[Model]): The records in the current page. items (list[Model]): The items in the current page.
links (list[Link]): The navigation links in the pagination links (list[Link]): The navigation links in the pagination
bar. bar.
page_size_options(list[PageSizeOptions]): The page size page_size_options(list[PageSizeOptions]): The page size
@ -237,11 +237,11 @@ class Pagination:
total_pages = None total_pages = None
is_paged = None is_paged = None
page_no = None page_no = None
records = None items = None
DEFAULT_PAGE_SIZE = 10 DEFAULT_PAGE_SIZE = 10
def __init__(self, request, records, is_reversed=False): def __init__(self, request, items, is_reversed=False):
current_url = request.get_full_path() current_url = request.get_full_path()
self._current_url = current_url self._current_url = current_url
self.is_reversed = is_reversed self.is_reversed = is_reversed
@ -261,7 +261,7 @@ class Pagination:
raise PaginationException(str( raise PaginationException(str(
UrlBuilder(current_url).del_param("page-size"))) UrlBuilder(current_url).del_param("page-size")))
self.total_pages = int( self.total_pages = int(
(len(records) - 1) / self.page_size) + 1 (len(items) - 1) / self.page_size) + 1
default_page_no = 1 if not is_reversed else self.total_pages default_page_no = 1 if not is_reversed else self.total_pages
self.is_paged = self.total_pages > 1 self.is_paged = self.total_pages > 1
@ -288,10 +288,10 @@ class Pagination:
if not self.is_paged: if not self.is_paged:
self.page_no = 1 self.page_no = 1
self.records = records self.items = items
return return
start_no = self.page_size * (self.page_no - 1) start_no = self.page_size * (self.page_no - 1)
self.records = records[start_no:start_no + self.page_size] self.items = items[start_no:start_no + self.page_size]
_links = None _links = None