fixup! WIP

This commit is contained in:
2025-12-09 13:25:34 +09:00
parent aaa5a6c556
commit c6ecb6fae9
2 changed files with 5 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
from sqlalchemy import and_, literal, or_, select
from sqlalchemy import and_, literal, not_, or_, select
from sqlalchemy.orm import Session
from dibbler.models import Product
@@ -7,7 +7,7 @@ from dibbler.models import Product
def search_product(
string: str,
sql_session: Session,
find_hidden_products=True,
find_hidden_products=False,
) -> Product | list[Product]:
exact_match = sql_session.scalars(
select(Product).where(
@@ -15,7 +15,7 @@ def search_product(
Product.bar_code == string,
and_(
Product.name == string,
literal(True) if find_hidden_products else not Product.hidden,
literal(True) if find_hidden_products else not_(Product.hidden),
),
)
)
@@ -30,7 +30,7 @@ def search_product(
Product.bar_code.ilike(f"%{string}%"),
and_(
Product.name.ilike(f"%{string}%"),
literal(True) if find_hidden_products else not Product.hidden,
literal(True) if find_hidden_products else not_(Product.hidden),
),
)
)

View File

@@ -37,7 +37,7 @@ def test_search_product_name_exact_match(sql_session: Session) -> None:
def test_search_product_name_partial_match(sql_session: Session) -> None:
insert_test_data(sql_session)
result = search_product("Product", sql_session)
result = search_product("Test Product", sql_session)
assert isinstance(result, list)
assert len(result) == 2
names = {product.name for product in result}