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:
@@ -388,6 +388,29 @@ class Spool(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
class SpoolAdjustment(BaseModel):
|
||||
"""Record of a spool weight/length adjustment."""
|
||||
|
||||
id: int = Field(description="Unique internal ID of this adjustment.")
|
||||
spool_id: int = Field(description="The spool this adjustment belongs to.")
|
||||
timestamp: SpoolmanDateTime = Field(description="When the adjustment was made. UTC Timezone.")
|
||||
adjustment_type: str = Field(description="Type of adjustment: 'weight' or 'length'.")
|
||||
value: float = Field(description="Amount adjusted (negative = used, positive = added).")
|
||||
comment: Optional[str] = Field(None, description="Optional user comment about this adjustment.")
|
||||
|
||||
@staticmethod
|
||||
def from_db(item: models.SpoolAdjustment) -> "SpoolAdjustment":
|
||||
"""Create a new Pydantic SpoolAdjustment object from a database object."""
|
||||
return SpoolAdjustment(
|
||||
id=item.id,
|
||||
spool_id=item.spool_id,
|
||||
timestamp=item.timestamp,
|
||||
adjustment_type=item.adjustment_type,
|
||||
value=item.value,
|
||||
comment=item.comment,
|
||||
)
|
||||
|
||||
|
||||
class Info(BaseModel):
|
||||
version: str = Field(examples=["0.7.0"])
|
||||
debug_mode: bool = Field(examples=[False])
|
||||
|
||||
Reference in New Issue
Block a user