feat: Add spool adjustment history tracking (#6)
Track history of all spool weight/length adjustments with timestamps and comments:
Backend:
- Add SpoolAdjustment database model with spool_id, timestamp, type, value, comment
- Add Alembic migration for spool_adjustment table
- Add SpoolAdjustment Pydantic model for API responses
- Update use_weight, use_length, and measure functions to record adjustments
- Add GET /api/v1/spool/{id}/adjustments endpoint for history retrieval
- Add optional comment parameter to use/measure endpoints
Frontend:
- Add ISpoolAdjustment interface to spool model
- Add collapsible adjustment history table to spool show page
- Display timestamp, type (weight/length), amount, and comment
- Add translation keys for history table
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,25 @@ class Spool(Base):
|
||||
cascade="save-update, merge, delete, delete-orphan",
|
||||
lazy="joined",
|
||||
)
|
||||
adjustments: Mapped[list["SpoolAdjustment"]] = relationship(
|
||||
back_populates="spool",
|
||||
cascade="save-update, merge, delete, delete-orphan",
|
||||
lazy="noload", # Don't load by default, only on explicit request
|
||||
)
|
||||
|
||||
|
||||
class SpoolAdjustment(Base):
|
||||
"""Track history of spool weight/length adjustments."""
|
||||
|
||||
__tablename__ = "spool_adjustment"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
spool_id: Mapped[int] = mapped_column(ForeignKey("spool.id", ondelete="CASCADE"), index=True)
|
||||
spool: Mapped["Spool"] = relationship(back_populates="adjustments")
|
||||
timestamp: Mapped[datetime] = mapped_column(comment="When the adjustment was made.")
|
||||
adjustment_type: Mapped[str] = mapped_column(String(16), comment="Type: 'weight' or 'length'.")
|
||||
value: Mapped[float] = mapped_column(comment="Amount adjusted (negative = used, positive = added).")
|
||||
comment: Mapped[Optional[str]] = mapped_column(String(256), comment="Optional user comment.")
|
||||
|
||||
|
||||
class Setting(Base):
|
||||
|
||||
Reference in New Issue
Block a user