Revised the search report to match the amount when the query keyword is a number, instead of matching the amount as a text string. For example, "0150.00" matches 150, while "50" does not match 150.

This commit is contained in:
依瑪貓 2023-03-08 13:59:00 +08:00
parent 196a115c99
commit 8a3df7a689

View File

@ -183,14 +183,19 @@ class Search(BaseReport):
return [] return []
conditions: list[sa.BinaryExpression] = [] conditions: list[sa.BinaryExpression] = []
for k in keywords: for k in keywords:
conditions.append(sa.or_( sub_conditions: list[sa.BinaryExpression] \
JournalEntry.summary.contains(k), = [JournalEntry.summary.contains(k),
sa.cast(JournalEntry.amount, sa.String).contains(k), JournalEntry.account_id.in_(
JournalEntry.account_id.in_(self.__get_account_condition(k)), self.__get_account_condition(k)),
JournalEntry.currency_code.in_( JournalEntry.currency_code.in_(
self.__get_currency_condition(k)), self.__get_currency_condition(k)),
JournalEntry.transaction_id.in_( JournalEntry.transaction_id.in_(
self.__get_transaction_condition(k)))) self.__get_transaction_condition(k))]
try:
sub_conditions.append(JournalEntry.amount == Decimal(k))
except ArithmeticError:
pass
conditions.append(sa.or_(*sub_conditions))
return [Entry(x) for x in JournalEntry.query.filter(*conditions)] return [Entry(x) for x in JournalEntry.query.filter(*conditions)]
@staticmethod @staticmethod