Added empty spool weight as an option field for the vendor

This commit is contained in:
Matt Gerega
2024-03-26 20:35:50 -04:00
parent 83fd3073ec
commit e68f88da2a
4 changed files with 40 additions and 2 deletions

View File

@@ -48,6 +48,9 @@ async def create(
vendor_item: Optional[models.Vendor] = None
if vendor_id is not None:
vendor_item = await vendor.get_by_id(db, vendor_id)
# default spool weight from vendor
if spool_weight is None and vendor_item.empty_spool_weight is not None:
spool_weight = vendor_item.empty_spool_weight
filament = models.Filament(
name=name,

View File

@@ -18,6 +18,7 @@ class Vendor(Base):
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
registered: Mapped[datetime] = mapped_column()
name: Mapped[str] = mapped_column(String(64))
empty_spool_weight: Mapped[Optional[float]] = mapped_column(comment="The weight of an empty spool.")
comment: Mapped[Optional[str]] = mapped_column(String(1024))
filaments: Mapped[list["Filament"]] = relationship(back_populates="vendor")
extra: Mapped[list["VendorField"]] = relationship(
@@ -64,8 +65,8 @@ class Spool(Base):
price: Mapped[Optional[float]] = mapped_column()
filament_id: Mapped[int] = mapped_column(ForeignKey("filament.id"))
filament: Mapped["Filament"] = relationship(back_populates="spools")
initial_weight: Mapped[float] = mapped_column()
empty_weight: Mapped[float] = mapped_column()
initial_weight: Mapped[Optional[float]] = mapped_column()
empty_weight: Mapped[Optional[float]] = mapped_column()
used_weight: Mapped[float] = mapped_column()
location: Mapped[Optional[str]] = mapped_column(String(64))
lot_nr: Mapped[Optional[str]] = mapped_column(String(64))

View File

@@ -235,6 +235,7 @@ async def use_weight_safe(db: AsyncSession, spool_id: int, weight: float) -> Non
db (AsyncSession): Database session
spool_id (int): Spool ID
weight (float): Filament weight to consume, in grams
"""
await db.execute(
sqlalchemy.update(models.Spool)
@@ -261,6 +262,7 @@ async def use_weight(db: AsyncSession, spool_id: int, weight: float) -> models.S
Returns:
models.Spool: Updated spool object
"""
await use_weight_safe(db, spool_id, weight)
@@ -288,6 +290,7 @@ async def use_length(db: AsyncSession, spool_id: int, length: float) -> models.S
Returns:
models.Spool: Updated spool object
"""
# Get filament diameter and density
result = await db.execute(