From c86514158366578b75543d1303de09d5ac17249b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 24 Mar 2023 07:38:17 +0800 Subject: [PATCH] Revised the #isQueryMatched method to always does partial match in the JavaScript OriginalLineItem class. Removed the full match from the query values. It is really wierd to type in the half with no match until you type the full term. It may create misunderstanding that there is no further match if you keep typing. --- src/accounting/models.py | 24 +++++++++---------- .../static/js/original-line-item-selector.js | 9 ++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/accounting/models.py b/src/accounting/models.py index 470e148..32e8e76 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -760,7 +760,7 @@ class JournalEntryLineItem(db.Model): setattr(self, "__net_balance", net_balance) @property - def query_values(self) -> tuple[list[str], list[str]]: + def query_values(self) -> list[str]: """Returns the values to be queried. :return: The values to be queried. @@ -772,17 +772,17 @@ class JournalEntryLineItem(db.Model): journal_entry_day: date = self.journal_entry.date description: str = "" if self.description is None else self.description - return ([description], - [str(journal_entry_day.year), - "{}/{}".format(journal_entry_day.year, - journal_entry_day.month), - "{}/{}".format(journal_entry_day.month, - journal_entry_day.day), - "{}/{}/{}".format(journal_entry_day.year, - journal_entry_day.month, - journal_entry_day.day), - format_amount(self.amount), - format_amount(self.net_balance)]) + return [description, + str(journal_entry_day.year), + "{}/{}".format(journal_entry_day.year, + journal_entry_day.month), + "{}/{}".format(journal_entry_day.month, + journal_entry_day.day), + "{}/{}/{}".format(journal_entry_day.year, + journal_entry_day.month, + journal_entry_day.day), + format_amount(self.amount), + format_amount(self.net_balance)] class Option(db.Model): diff --git a/src/accounting/static/js/original-line-item-selector.js b/src/accounting/static/js/original-line-item-selector.js index 2278e5c..24b62ec 100644 --- a/src/accounting/static/js/original-line-item-selector.js +++ b/src/accounting/static/js/original-line-item-selector.js @@ -273,7 +273,7 @@ class OriginalLineItem { /** * The values to query against - * @type {string[][]} + * @type {string[]} */ #queryValues; @@ -366,16 +366,11 @@ class OriginalLineItem { if (query === "") { return true; } - for (const queryValue of this.#queryValues[0]) { + for (const queryValue of this.#queryValues) { if (queryValue.toLowerCase().includes(query.toLowerCase())) { return true; } } - for (const queryValue of this.#queryValues[1]) { - if (queryValue === query) { - return true; - } - } return false; }