Added archived field to spools

Resolves #13
This commit is contained in:
Donkie
2023-07-14 14:19:57 +02:00
parent 061061cd31
commit f89cf8ecd4
6 changed files with 42 additions and 1 deletions

View File

@@ -57,3 +57,4 @@ class Spool(Base):
location: Mapped[Optional[str]] = mapped_column(String(64))
lot_nr: Mapped[Optional[str]] = mapped_column(String(64))
comment: Mapped[Optional[str]] = mapped_column(String(1024))
archived: Mapped[Optional[bool]] = mapped_column()

View File

@@ -30,6 +30,7 @@ async def create(
location: Optional[str] = None,
lot_nr: Optional[str] = None,
comment: Optional[str] = None,
archived: bool = False,
) -> models.Spool:
"""Add a new spool to the database. Leave weight empty to assume full spool."""
filament_item = await filament.get_by_id(db, filament_id)
@@ -55,6 +56,7 @@ async def create(
location=location,
lot_nr=lot_nr,
comment=comment,
archived=archived,
)
db.add(db_item)
await db.flush()
@@ -83,6 +85,7 @@ async def find(
vendor_id: Optional[int] = None,
location: Optional[str] = None,
lot_nr: Optional[str] = None,
allow_archived: bool = False,
) -> list[models.Spool]:
"""Find a list of spool objects by search criteria."""
stmt = (
@@ -105,6 +108,8 @@ async def find(
stmt = stmt.where(models.Spool.location.ilike(f"%{location}%"))
if lot_nr is not None:
stmt = stmt.where(models.Spool.lot_nr.ilike(f"%{lot_nr}%"))
if not allow_archived:
stmt = stmt.where(models.Spool.archived != True) # noqa: E712
rows = await db.execute(stmt)
return list(rows.scalars().all())