diff --git a/app/crud/augmented_part.py b/app/crud/augmented_part.py index 7f06de3..87dda10 100644 --- a/app/crud/augmented_part.py +++ b/app/crud/augmented_part.py @@ -1,4 +1,4 @@ -from sqlalchemy import distinct, select +from sqlalchemy import distinct, or_, select from sqlalchemy.ext.asyncio import AsyncSession from app.models.associations import augmented_part_imported_parts @@ -89,10 +89,19 @@ async def list_filtered( direction: str = "asc", skip: int = 0, limit: int = 100, + match_sku: bool = False, ) -> list[AugmentedPart]: q = select(AugmentedPart) if description.strip(): - q = q.where(AugmentedPart.description.ilike(f"%{description.strip()}%")) + term = f"%{description.strip()}%" + if match_sku: + q = q.where( + or_( + AugmentedPart.description.ilike(term), AugmentedPart.sku.ilike(term) + ) + ) + else: + q = q.where(AugmentedPart.description.ilike(term)) if colour_id is not None: q = q.where(AugmentedPart.colour_id == colour_id) if manufacturer_id is not None: diff --git a/app/services/scope_guide.py b/app/services/scope_guide.py index daa6504..52cc129 100644 --- a/app/services/scope_guide.py +++ b/app/services/scope_guide.py @@ -33,8 +33,9 @@ async def build( """Return the context for ``scopes.html``. The scope rows are narrowed by the scope-attribute filters (``description`` - matches the scope's description; the ``*_id`` filters match exactly). - ``fits_part_type_id`` keeps only scopes that have at least one (non-``none``) + matches either the scope's description or its SKU/product ID; the ``*_id`` + filters match exactly). ``fits_part_type_id`` keeps only scopes that have + at least one (non-``none``) fit for that part type. Callers that paginate should slice ``rows`` themselves — this always returns the full filtered set, since ``fits_part_type_id`` is a post-filter that can't be pushed into the DB query. @@ -71,6 +72,7 @@ async def build( sub_part_type_id=sub_part_type_id, part_type_id=scope_type.id, limit=1000, + match_sku=True, ) scope_ids = {s.id for s in scopes} if not scope_ids: diff --git a/app/templates/scopes.html b/app/templates/scopes.html index 05609c4..4f6e6f5 100644 --- a/app/templates/scopes.html +++ b/app/templates/scopes.html @@ -15,7 +15,7 @@ hx-target="#scopes-table-card" hx-trigger="input delay:300ms, change" hx-swap="outerHTML"> -