Files
data-entry-app/backend/app/models/mix_calculator.py
T
adminandClaude Opus 4.8 2de82776cb v0.1.19 - Throughput overview & responsive header
- Throughput: new "Throughput Overview" header with Gauge icon and brand-green
  badge icons on each card (Today, This week, 4-week average, Horse Mix, Grain Mix)
- Throughput: inline rolling-range selector (7d / 4w / 6w / 12w, default 4 weeks)
  driving the customer-mix cards; stats window widened to 12 weeks so switching
  range is a pure client-side re-filter
- Throughput: cards collapse to a single even 5-across row on laptop and up,
  with container-query value text that scales to each card's width
- Throughput: date logic pinned to Australian Eastern time (fixes the day-early
  date); This week subtitle shows the Mon-Sun date range
- Throughput: subtler tinted add-form; removed the inline-entry kicker and the
  "Open full form" link
- Topbar: fix cramped laptop header - action toggles no longer wrap above the
  user button; search drops to its own row earlier

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 10:01:10 +12:00

60 lines
3.0 KiB
Python

from __future__ import annotations
from datetime import date, datetime
from sqlalchemy import Date, DateTime, Float, ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.session import Base
class MixCalculatorSession(Base):
__tablename__ = "mix_calculator_sessions"
__table_args__ = (UniqueConstraint("tenant_id", "session_number", name="uq_mix_calculator_session_number"),)
id: Mapped[int] = mapped_column(primary_key=True)
tenant_id: Mapped[str] = mapped_column(String(64), default="default", index=True)
session_number: Mapped[str] = mapped_column(String(32), index=True)
client_name: Mapped[str] = mapped_column(String(255), index=True)
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), index=True)
product_name: Mapped[str] = mapped_column(String(255))
mix_id: Mapped[int] = mapped_column(ForeignKey("mixes.id"), index=True)
mix_name: Mapped[str] = mapped_column(String(255))
mix_date: Mapped[date] = mapped_column(Date, index=True)
batch_size_kg: Mapped[float] = mapped_column(Float)
total_bags: Mapped[float] = mapped_column(Float)
total_kg: Mapped[float] = mapped_column(Float)
product_unit_of_measure: Mapped[str] = mapped_column(String(64))
product_unit_size_kg: Mapped[float] = mapped_column(Float)
prepared_by_user_id: Mapped[int | None] = mapped_column(ForeignKey("client_users.id"), nullable=True, index=True)
prepared_by_name: Mapped[str] = mapped_column(String(255))
created_by: Mapped[str] = mapped_column(String(255))
status: Mapped[str] = mapped_column(String(32), default="saved")
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
lines: Mapped[list["MixCalculatorSessionLine"]] = relationship(
back_populates="session",
cascade="all, delete-orphan",
order_by="MixCalculatorSessionLine.sort_order",
)
class MixCalculatorSessionLine(Base):
__tablename__ = "mix_calculator_session_lines"
id: Mapped[int] = mapped_column(primary_key=True)
tenant_id: Mapped[str] = mapped_column(String(64), default="default", index=True)
session_id: Mapped[int] = mapped_column(ForeignKey("mix_calculator_sessions.id"), index=True)
raw_material_id: Mapped[int | None] = mapped_column(nullable=True)
raw_material_name: Mapped[str] = mapped_column(String(255))
required_kg: Mapped[float] = mapped_column(Float)
mix_percentage: Mapped[float] = mapped_column(Float)
unit: Mapped[str] = mapped_column(String(64))
# Snapshot of the ingredient's rounding setting at save time.
rounding_decimals: Mapped[int] = mapped_column(Integer, default=2)
sort_order: Mapped[int] = mapped_column(Integer, default=0)
session: Mapped[MixCalculatorSession] = relationship(back_populates="lines")