From 79689ac0e5339838bbd140e31bd212794ecb4638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 8 Apr 2023 18:52:41 +0800 Subject: [PATCH] Revised the unapplied original line item report to mark matched offsets for administrators when there are unmatched offsets. --- src/accounting/report/reports/unapplied.py | 14 ++++++++++++-- src/accounting/static/css/style.css | 9 +++++++++ .../templates/accounting/report/unapplied.html | 9 +++++++-- src/accounting/unmatched_offset/forms.py | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/accounting/report/reports/unapplied.py b/src/accounting/report/reports/unapplied.py index 56dcbc8..a395379 100644 --- a/src/accounting/report/reports/unapplied.py +++ b/src/accounting/report/reports/unapplied.py @@ -32,8 +32,9 @@ 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.unmatched_offset.forms import OffsetMatcher from accounting.utils.pagination import Pagination -from accounting.utils.unapplied import get_unapplied_original_line_items +from accounting.utils.permission import can_admin class CSVRow(BaseCSVRow): @@ -75,11 +76,13 @@ class PageParams(BasePageParams): """The HTML page parameters.""" def __init__(self, account: Account, + is_mark_matches: bool, pagination: Pagination[JournalEntryLineItem], line_items: list[JournalEntryLineItem]): """Constructs the HTML page parameters. :param account: The account. + :param is_mark_matches: Whether to mark the matched offsets. :param pagination: The pagination. :param line_items: The line items. """ @@ -89,6 +92,8 @@ class PageParams(BasePageParams): """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.""" @property def has_data(self) -> bool: @@ -148,9 +153,13 @@ class UnappliedOriginalLineItems(BaseReport): """ self.__account: Account = account """The account.""" + offset_matcher: OffsetMatcher = OffsetMatcher(self.__account) self.__line_items: list[JournalEntryLineItem] \ - = get_unapplied_original_line_items(self.__account) + = offset_matcher.unapplied """The line items.""" + self.__is_mark_matches: bool \ + = can_admin() and len(offset_matcher.unmatched_offsets) > 0 + """Whether to mark the matched offsets.""" def csv(self) -> Response: """Returns the report as CSV for download. @@ -169,6 +178,7 @@ class UnappliedOriginalLineItems(BaseReport): = Pagination[JournalEntryLineItem](self.__line_items, is_reversed=True) params: PageParams = PageParams(account=self.__account, + is_mark_matches=self.__is_mark_matches, pagination=pagination, line_items=pagination.list) return render_template("accounting/report/unapplied.html", diff --git a/src/accounting/static/css/style.css b/src/accounting/static/css/style.css index d5ade96..789ef39 100644 --- a/src/accounting/static/css/style.css +++ b/src/accounting/static/css/style.css @@ -218,6 +218,15 @@ a.accounting-report-table-row { .accounting-report-table-body .accounting-report-table-row:hover { background-color: #e5e6e7; } +.accounting-report-table-body .accounting-report-table-row-danger { + background-color: #f8d7da; +} +.accounting-report-table-body .accounting-report-table-row-danger:nth-child(2n+1) { + background-color: #eccccf; +} +.accounting-report-table-body .accounting-report-table-row-danger:hover { + background-color: #e5c7ca; +} .accounting-journal-table .accounting-report-table-row { grid-template-columns: 1fr 1fr 2fr 4fr 1fr 1fr; } diff --git a/src/accounting/templates/accounting/report/unapplied.html b/src/accounting/templates/accounting/report/unapplied.html index b7d9a42..e1ec33e 100644 --- a/src/accounting/templates/accounting/report/unapplied.html +++ b/src/accounting/templates/accounting/report/unapplied.html @@ -56,10 +56,15 @@ First written: 2023/4/7
{% for line_item in report.line_items %} - +
{{ line_item.journal_entry.date|accounting_format_date }}
{{ line_item.currency.name }}
-
{{ line_item.description|accounting_default }}
+
+ {{ line_item.description|accounting_default }} + {% if report.is_mark_matches and line_item.match %} +
{{ A_("Can match %(offset)s", offset=line_item.match) }}
+ {% endif %} +
{{ line_item.amount|accounting_format_amount }}
{{ line_item.net_balance|accounting_format_amount }}
diff --git a/src/accounting/unmatched_offset/forms.py b/src/accounting/unmatched_offset/forms.py index e77f8b6..adc58cb 100644 --- a/src/accounting/unmatched_offset/forms.py +++ b/src/accounting/unmatched_offset/forms.py @@ -90,6 +90,7 @@ class OffsetMatcher: continue self.matched_pairs.append( OffsetPair(original_item, offset_candidates[0])) + original_item.match = offset_candidates[0] offset_candidates[0].match = original_item remains.remove(offset_candidates[0]) self.is_having_matches = len(self.matched_pairs) > 0