Adding on_website and preferred part indicators

This commit is contained in:
Ian Roddis committed 2026-09-21 14:01:23 -03:00
1 parent 13b64a2d17
commit 4fd2bb1b58
13 files changed
+331 -6

No files matched your search

+18 -1
View File
@@ -10,7 +10,14 @@ from app.models.part_type import PartType
from app.models.scope_model import ScopeModel
from app.models.sub_part_type import SubPartType
_RELATIONSHIPS = ["colour", "manufacturer", "scope_model", "part_type", "sub_part_type"]
_RELATIONSHIPS = [
"colour",
"manufacturer",
"scope_model",
"part_type",
"sub_part_type",
"notes",
]
# Sortable columns for the admin list, keyed by the query-string "sort" value.
# Columns backed by a related table's name require an outer join (the FK may be
@@ -87,6 +94,7 @@ async def list_filtered(
part_type_id: int | None = None,
sub_part_type_id: int | None = None,
include_archived: bool = False,
on_website: bool = False,
sort: str = "description",
direction: str = "asc",
skip: int = 0,
@@ -110,6 +118,8 @@ async def list_filtered(
q = q.where(AugmentedPart.sub_part_type_id == sub_part_type_id)
if not include_archived:
q = q.where(AugmentedPart.archived.is_(False))
if on_website:
q = q.where(AugmentedPart.on_website.is_(True))
q = _apply_sort(q, sort, direction)
result = await db.execute(q.offset(skip).limit(limit))
return list(result.scalars().all())
@@ -124,6 +134,7 @@ async def count_filtered(
part_type_id: int | None = None,
sub_part_type_id: int | None = None,
include_archived: bool = False,
on_website: bool = False,
) -> int:
from sqlalchemy import func
@@ -145,6 +156,8 @@ async def count_filtered(
q = q.where(AugmentedPart.sub_part_type_id == sub_part_type_id)
if not include_archived:
q = q.where(AugmentedPart.archived.is_(False))
if on_website:
q = q.where(AugmentedPart.on_website.is_(True))
result = await db.execute(q)
return result.scalar_one()
@@ -220,6 +233,8 @@ async def create(
scope_model_id: int | None,
part_type_id: int,
sub_part_type_id: int | None,
on_website: bool = False,
preferred_part: bool = False,
) -> AugmentedPart:
ap = AugmentedPart(
sku=sku,
@@ -229,6 +244,8 @@ async def create(
scope_model_id=scope_model_id,
part_type_id=part_type_id,
sub_part_type_id=sub_part_type_id,
on_website=on_website,
preferred_part=preferred_part,
)
db.add(ap)
await db.commit()