Making text search apply to both description and sku in imported parts and augmented parts

This commit is contained in:
Ian Roddis committed 2026-08-17 16:05:01 -03:00
1 parent 292830ae0f
commit ce2bdc43a8
7 files changed
+53 -30

No files matched your search

+9 -3
View File
@@ -1,4 +1,4 @@
from sqlalchemy import distinct, insert, select, update
from sqlalchemy import distinct, insert, or_, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.imported_part import ImportedPart
@@ -61,7 +61,10 @@ async def list_filtered(
) -> list[ImportedPart]:
q = select(ImportedPart)
if description.strip():
q = q.where(ImportedPart.Description.ilike(f"%{description.strip()}%"))
term = f"%{description.strip()}%"
q = q.where(
or_(ImportedPart.Description.ilike(term), ImportedPart.InventoryID.ilike(term))
)
q = _apply_sort(q, sort, direction)
result = await db.execute(q.offset(skip).limit(limit))
return list(result.scalars().all())
@@ -88,7 +91,10 @@ async def count_filtered(db: AsyncSession, description: str = "") -> int:
q = select(func.count()).select_from(ImportedPart)
if description.strip():
q = q.where(ImportedPart.Description.ilike(f"%{description.strip()}%"))
term = f"%{description.strip()}%"
q = q.where(
or_(ImportedPart.Description.ilike(term), ImportedPart.InventoryID.ilike(term))
)
result = await db.execute(q)
return result.scalar_one()