Fixed the search queries to be case-insensitive.

This commit is contained in:
依瑪貓 2023-03-20 23:35:19 +08:00
parent 03265a1232
commit 77787eee9f
4 changed files with 15 additions and 14 deletions

View File

@ -40,11 +40,11 @@ def get_account_query() -> list[Account]:
conditions: list[sa.BinaryExpression] = [] conditions: list[sa.BinaryExpression] = []
for k in keywords: for k in keywords:
l10n: list[AccountL10n] = AccountL10n.query\ 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} l10n_matches: set[str] = {x.account_id for x in l10n}
sub_conditions: list[sa.BinaryExpression] \ sub_conditions: list[sa.BinaryExpression] \
= [Account.base_code.contains(k), = [Account.base_code.contains(k),
Account.title_l10n.contains(k), Account.title_l10n.icontains(k),
code.contains(k), code.contains(k),
Account.id.in_(l10n_matches)] Account.id.in_(l10n_matches)]
if k in gettext("Needs Offset"): if k in gettext("Needs Offset"):

View File

@ -35,10 +35,10 @@ def get_base_account_query() -> list[BaseAccount]:
conditions: list[sa.BinaryExpression] = [] conditions: list[sa.BinaryExpression] = []
for k in keywords: for k in keywords:
l10n: list[BaseAccountL10n] = BaseAccountL10n.query\ 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} l10n_matches: set[str] = {x.account_code for x in l10n}
conditions.append(sa.or_(BaseAccount.code.contains(k), conditions.append(sa.or_(BaseAccount.code.contains(k),
BaseAccount.title_l10n.contains(k), BaseAccount.title_l10n.icontains(k),
BaseAccount.code.in_(l10n_matches))) BaseAccount.code.in_(l10n_matches)))
return BaseAccount.query.filter(*conditions)\ return BaseAccount.query.filter(*conditions)\
.order_by(BaseAccount.code).all() .order_by(BaseAccount.code).all()

View File

@ -35,10 +35,10 @@ def get_currency_query() -> list[Currency]:
conditions: list[sa.BinaryExpression] = [] conditions: list[sa.BinaryExpression] = []
for k in keywords: for k in keywords:
l10n: list[CurrencyL10n] = CurrencyL10n.query\ 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} l10n_matches: set[str] = {x.account_code for x in l10n}
conditions.append(sa.or_(Currency.code.contains(k), conditions.append(sa.or_(Currency.code.icontains(k),
Currency.name_l10n.contains(k), Currency.name_l10n.icontains(k),
Currency.code.in_(l10n_matches))) Currency.code.in_(l10n_matches)))
return Currency.query.filter(*conditions)\ return Currency.query.filter(*conditions)\
.order_by(Currency.code).all() .order_by(Currency.code).all()

View File

@ -57,7 +57,7 @@ class LineItemCollector:
conditions: list[sa.BinaryExpression] = [] conditions: list[sa.BinaryExpression] = []
for k in keywords: for k in keywords:
sub_conditions: list[sa.BinaryExpression] \ sub_conditions: list[sa.BinaryExpression] \
= [JournalEntryLineItem.description.contains(k), = [JournalEntryLineItem.description.icontains(k),
JournalEntryLineItem.account_id.in_( JournalEntryLineItem.account_id.in_(
self.__get_account_condition(k)), self.__get_account_condition(k)),
JournalEntryLineItem.currency_code.in_( JournalEntryLineItem.currency_code.in_(
@ -92,10 +92,10 @@ class LineItemCollector:
sa.func.char_length(sa.cast(Account.no, sa.func.char_length(sa.cast(Account.no,
sa.String)) + 1) sa.String)) + 1)
select_l10n: sa.Select = sa.select(AccountL10n.account_id)\ select_l10n: sa.Select = sa.select(AccountL10n.account_id)\
.filter(AccountL10n.title.contains(k)) .filter(AccountL10n.title.icontains(k))
conditions: list[sa.BinaryExpression] \ conditions: list[sa.BinaryExpression] \
= [Account.base_code.contains(k), = [Account.base_code.contains(k),
Account.title_l10n.contains(k), Account.title_l10n.icontains(k),
code.contains(k), code.contains(k),
Account.id.in_(select_l10n)] Account.id.in_(select_l10n)]
if k in gettext("Needs Offset"): if k in gettext("Needs Offset"):
@ -110,10 +110,10 @@ class LineItemCollector:
:return: The condition to filter the currency. :return: The condition to filter the currency.
""" """
select_l10n: sa.Select = sa.select(CurrencyL10n.currency_code)\ 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( return sa.select(Currency.code).filter(
sa.or_(Currency.code.contains(k), sa.or_(Currency.code.icontains(k),
Currency.name_l10n.contains(k), Currency.name_l10n.icontains(k),
Currency.code.in_(select_l10n))) Currency.code.in_(select_l10n)))
@staticmethod @staticmethod
@ -123,7 +123,8 @@ class LineItemCollector:
:param k: The keyword. :param k: The keyword.
:return: The condition to filter the journal entry. :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 journal_entry_date: datetime
try: try:
journal_entry_date = datetime.strptime(k, "%Y") journal_entry_date = datetime.strptime(k, "%Y")