v1.2 scaffold
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from app.models.assumption import FreightCostRule, PackagingCostRule, ProcessCostRule
|
||||
from app.models.mix import Mix, MixIngredient
|
||||
from app.models.product import Product
|
||||
from app.models.raw_material import RawMaterial, RawMaterialPriceVersion
|
||||
from app.models.scenario import CostingResult, Scenario
|
||||
|
||||
__all__ = [
|
||||
"CostingResult",
|
||||
"FreightCostRule",
|
||||
"Mix",
|
||||
"MixIngredient",
|
||||
"PackagingCostRule",
|
||||
"ProcessCostRule",
|
||||
"Product",
|
||||
"RawMaterial",
|
||||
"RawMaterialPriceVersion",
|
||||
"Scenario",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Float, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class ProcessCostRule(Base):
|
||||
__tablename__ = "process_cost_rules"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
process_name: Mapped[str] = mapped_column(String(64), unique=True)
|
||||
grading_cost: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
bagging_cost: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
cracking_cost: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
|
||||
class PackagingCostRule(Base):
|
||||
__tablename__ = "packaging_cost_rules"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
sale_type: Mapped[str] = mapped_column(String(64))
|
||||
unit_of_measure: Mapped[str] = mapped_column(String(64))
|
||||
own_bag: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
bag_cost: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
|
||||
class FreightCostRule(Base):
|
||||
__tablename__ = "freight_cost_rules"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
sale_type: Mapped[str] = mapped_column(String(64))
|
||||
unit_of_measure: Mapped[str] = mapped_column(String(64))
|
||||
cost_per_unit: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
@@ -0,0 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Float, ForeignKey, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class Mix(Base):
|
||||
__tablename__ = "mixes"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), default="default")
|
||||
client_name: Mapped[str] = mapped_column(String(255))
|
||||
name: Mapped[str] = mapped_column(String(255), index=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="draft")
|
||||
version: Mapped[int] = mapped_column(default=1)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
ingredients: Mapped[list["MixIngredient"]] = relationship(
|
||||
back_populates="mix",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
products: Mapped[list["Product"]] = relationship(back_populates="mix")
|
||||
|
||||
|
||||
class MixIngredient(Base):
|
||||
__tablename__ = "mix_ingredients"
|
||||
__table_args__ = (UniqueConstraint("mix_id", "raw_material_id", name="uq_mix_ingredient"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
mix_id: Mapped[int] = mapped_column(ForeignKey("mixes.id"), index=True)
|
||||
raw_material_id: Mapped[int] = mapped_column(ForeignKey("raw_materials.id"), index=True)
|
||||
quantity_kg: Mapped[float] = mapped_column(Float)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
mix: Mapped[Mix] = relationship(back_populates="ingredients")
|
||||
raw_material: Mapped["RawMaterial"] = relationship()
|
||||
|
||||
|
||||
from app.models.product import Product # noqa: E402
|
||||
from app.models.raw_material import RawMaterial # noqa: E402
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), default="default")
|
||||
client_name: Mapped[str] = mapped_column(String(255))
|
||||
item_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
name: Mapped[str] = mapped_column(String(255), index=True)
|
||||
mix_id: Mapped[int] = mapped_column(ForeignKey("mixes.id"))
|
||||
sale_type: Mapped[str] = mapped_column(String(64), default="standard")
|
||||
own_bag: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
unit_of_measure: Mapped[str] = mapped_column(String(64), default="20kg bag")
|
||||
items_per_pallet: Mapped[int] = mapped_column(Integer, default=50)
|
||||
bagging_process: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
distributor_margin: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
wholesale_margin: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
mix: Mapped["Mix"] = relationship(back_populates="products")
|
||||
|
||||
|
||||
from app.models.mix import Mix # noqa: E402
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import Date, DateTime, Float, ForeignKey, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class RawMaterial(Base):
|
||||
__tablename__ = "raw_materials"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), default="default")
|
||||
name: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
||||
supplier: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
unit_of_measure: Mapped[str] = mapped_column(String(64))
|
||||
kg_per_unit: Mapped[float] = mapped_column(Float)
|
||||
status: Mapped[str] = mapped_column(String(32), default="active")
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
price_versions: Mapped[list["RawMaterialPriceVersion"]] = relationship(
|
||||
back_populates="raw_material",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="desc(RawMaterialPriceVersion.effective_date)",
|
||||
)
|
||||
|
||||
|
||||
class RawMaterialPriceVersion(Base):
|
||||
__tablename__ = "raw_material_price_versions"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
raw_material_id: Mapped[int] = mapped_column(ForeignKey("raw_materials.id"), index=True)
|
||||
market_value: Mapped[float] = mapped_column(Float)
|
||||
waste_percentage: Mapped[float] = mapped_column(Float, default=0.0)
|
||||
effective_date: Mapped[date] = mapped_column(Date, default=date.today)
|
||||
status: Mapped[str] = mapped_column(String(32), default="active")
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
raw_material: Mapped[RawMaterial] = relationship(back_populates="price_versions")
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Float, ForeignKey, JSON, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class Scenario(Base):
|
||||
__tablename__ = "scenarios"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(255), unique=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="draft")
|
||||
description: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
overrides: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
results: Mapped[list["CostingResult"]] = relationship(
|
||||
back_populates="scenario",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class CostingResult(Base):
|
||||
__tablename__ = "costing_results"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
scenario_id: Mapped[int] = mapped_column(ForeignKey("scenarios.id"), index=True)
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), index=True)
|
||||
finished_product_delivered: Mapped[float] = mapped_column(Float)
|
||||
distributor_price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
wholesale_price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
warnings: Mapped[list[str]] = mapped_column(JSON, default=list)
|
||||
details: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
scenario: Mapped[Scenario] = relationship(back_populates="results")
|
||||
|
||||
Reference in New Issue
Block a user