generated from gilles/template-webapp
import ali
This commit is contained in:
@@ -8,7 +8,7 @@ from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Date, DateTime, Enum, ForeignKey, Integer, Numeric, String, Text
|
||||
from sqlalchemy import Date, DateTime, Enum, ForeignKey, Integer, JSON, Numeric, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
@@ -18,6 +18,7 @@ if TYPE_CHECKING:
|
||||
from app.models.category import Category
|
||||
from app.models.document import Document
|
||||
from app.models.location import Location
|
||||
from app.models.shop import Shop
|
||||
|
||||
import enum
|
||||
|
||||
@@ -27,6 +28,7 @@ class ItemStatus(str, enum.Enum):
|
||||
|
||||
IN_STOCK = "in_stock" # En stock (non utilisé)
|
||||
IN_USE = "in_use" # En cours d'utilisation
|
||||
INTEGRATED = "integrated" # Intégré dans un autre objet
|
||||
BROKEN = "broken" # Cassé/HS
|
||||
SOLD = "sold" # Vendu
|
||||
LENT = "lent" # Prêté
|
||||
@@ -79,6 +81,9 @@ class Item(Base):
|
||||
price: Mapped[Decimal | None] = mapped_column(Numeric(10, 2), nullable=True)
|
||||
purchase_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
||||
|
||||
# Caractéristiques techniques (clé-valeur, ex: {"RAM": "16 Go", "CPU": "i7"})
|
||||
characteristics: Mapped[dict | None] = mapped_column(JSON, nullable=True, default=None)
|
||||
|
||||
# Notes
|
||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
@@ -89,6 +94,12 @@ class Item(Base):
|
||||
location_id: Mapped[int] = mapped_column(
|
||||
Integer, ForeignKey("locations.id", ondelete="RESTRICT"), nullable=False, index=True
|
||||
)
|
||||
parent_item_id: Mapped[int | None] = mapped_column(
|
||||
Integer, ForeignKey("items.id", ondelete="SET NULL"), nullable=True, index=True
|
||||
)
|
||||
shop_id: Mapped[int | None] = mapped_column(
|
||||
Integer, ForeignKey("shops.id", ondelete="SET NULL"), nullable=True, index=True
|
||||
)
|
||||
|
||||
# Timestamps
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
@@ -107,6 +118,13 @@ class Item(Base):
|
||||
documents: Mapped[list["Document"]] = relationship(
|
||||
"Document", back_populates="item", cascade="all, delete-orphan"
|
||||
)
|
||||
shop: Mapped["Shop | None"] = relationship("Shop", back_populates="items")
|
||||
parent_item: Mapped["Item | None"] = relationship(
|
||||
"Item", remote_side=[id], foreign_keys=[parent_item_id], back_populates="children"
|
||||
)
|
||||
children: Mapped[list["Item"]] = relationship(
|
||||
"Item", back_populates="parent_item", foreign_keys=[parent_item_id]
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Représentation string de l'objet."""
|
||||
|
||||
Reference in New Issue
Block a user