Fixed the search queries to be case-insensitive.
This commit is contained in:
parent
03265a1232
commit
77787eee9f
@ -40,11 +40,11 @@ def get_account_query() -> list[Account]:
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
l10n: list[AccountL10n] = AccountL10n.query\
|
||||
.filter(AccountL10n.title.contains(k)).all()
|
||||
.filter(AccountL10n.title.icontains(k)).all()
|
||||
l10n_matches: set[str] = {x.account_id for x in l10n}
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [Account.base_code.contains(k),
|
||||
Account.title_l10n.contains(k),
|
||||
Account.title_l10n.icontains(k),
|
||||
code.contains(k),
|
||||
Account.id.in_(l10n_matches)]
|
||||
if k in gettext("Needs Offset"):
|
||||
|
@ -35,10 +35,10 @@ def get_base_account_query() -> list[BaseAccount]:
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
l10n: list[BaseAccountL10n] = BaseAccountL10n.query\
|
||||
.filter(BaseAccountL10n.title.contains(k)).all()
|
||||
.filter(BaseAccountL10n.title.icontains(k)).all()
|
||||
l10n_matches: set[str] = {x.account_code for x in l10n}
|
||||
conditions.append(sa.or_(BaseAccount.code.contains(k),
|
||||
BaseAccount.title_l10n.contains(k),
|
||||
BaseAccount.title_l10n.icontains(k),
|
||||
BaseAccount.code.in_(l10n_matches)))
|
||||
return BaseAccount.query.filter(*conditions)\
|
||||
.order_by(BaseAccount.code).all()
|
||||
|
@ -35,10 +35,10 @@ def get_currency_query() -> list[Currency]:
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
l10n: list[CurrencyL10n] = CurrencyL10n.query\
|
||||
.filter(CurrencyL10n.name.contains(k)).all()
|
||||
.filter(CurrencyL10n.name.icontains(k)).all()
|
||||
l10n_matches: set[str] = {x.account_code for x in l10n}
|
||||
conditions.append(sa.or_(Currency.code.contains(k),
|
||||
Currency.name_l10n.contains(k),
|
||||
conditions.append(sa.or_(Currency.code.icontains(k),
|
||||
Currency.name_l10n.icontains(k),
|
||||
Currency.code.in_(l10n_matches)))
|
||||
return Currency.query.filter(*conditions)\
|
||||
.order_by(Currency.code).all()
|
||||
|
@ -57,7 +57,7 @@ class LineItemCollector:
|
||||
conditions: list[sa.BinaryExpression] = []
|
||||
for k in keywords:
|
||||
sub_conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntryLineItem.description.contains(k),
|
||||
= [JournalEntryLineItem.description.icontains(k),
|
||||
JournalEntryLineItem.account_id.in_(
|
||||
self.__get_account_condition(k)),
|
||||
JournalEntryLineItem.currency_code.in_(
|
||||
@ -92,10 +92,10 @@ class LineItemCollector:
|
||||
sa.func.char_length(sa.cast(Account.no,
|
||||
sa.String)) + 1)
|
||||
select_l10n: sa.Select = sa.select(AccountL10n.account_id)\
|
||||
.filter(AccountL10n.title.contains(k))
|
||||
.filter(AccountL10n.title.icontains(k))
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [Account.base_code.contains(k),
|
||||
Account.title_l10n.contains(k),
|
||||
Account.title_l10n.icontains(k),
|
||||
code.contains(k),
|
||||
Account.id.in_(select_l10n)]
|
||||
if k in gettext("Needs Offset"):
|
||||
@ -110,10 +110,10 @@ class LineItemCollector:
|
||||
:return: The condition to filter the currency.
|
||||
"""
|
||||
select_l10n: sa.Select = sa.select(CurrencyL10n.currency_code)\
|
||||
.filter(CurrencyL10n.name.contains(k))
|
||||
.filter(CurrencyL10n.name.icontains(k))
|
||||
return sa.select(Currency.code).filter(
|
||||
sa.or_(Currency.code.contains(k),
|
||||
Currency.name_l10n.contains(k),
|
||||
sa.or_(Currency.code.icontains(k),
|
||||
Currency.name_l10n.icontains(k),
|
||||
Currency.code.in_(select_l10n)))
|
||||
|
||||
@staticmethod
|
||||
@ -123,7 +123,8 @@ class LineItemCollector:
|
||||
:param k: The keyword.
|
||||
:return: The condition to filter the journal entry.
|
||||
"""
|
||||
conditions: list[sa.BinaryExpression] = [JournalEntry.note.contains(k)]
|
||||
conditions: list[sa.BinaryExpression] \
|
||||
= [JournalEntry.note.icontains(k)]
|
||||
journal_entry_date: datetime
|
||||
try:
|
||||
journal_entry_date = datetime.strptime(k, "%Y")
|
||||
|
Loading…
Reference in New Issue
Block a user