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:
parent
196a115c99
commit
8a3df7a689
@ -183,14 +183,19 @@ class Search(BaseReport):
|
||||
return []
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
conditions.append(sa.or_(
|
||||
JournalEntry.summary.contains(k),
|
||||
sa.cast(JournalEntry.amount, sa.String).contains(k),
|
||||
JournalEntry.account_id.in_(self.__get_account_condition(k)),
|
||||
JournalEntry.currency_code.in_(
|
||||
self.__get_currency_condition(k)),
|
||||
JournalEntry.transaction_id.in_(
|
||||
self.__get_transaction_condition(k))))
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.summary.contains(k),
|
||||
JournalEntry.account_id.in_(
|
||||
self.__get_account_condition(k)),
|
||||
JournalEntry.currency_code.in_(
|
||||
self.__get_currency_condition(k)),
|
||||
JournalEntry.transaction_id.in_(
|
||||
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)]
|
||||
|
||||
@staticmethod
|
||||
|
Loading…
Reference in New Issue
Block a user