Files
inventory/backend/app/models/object.py
jze9 d6a7ac0a68 Replace box picker with free-text location in audit scan
"Where found" during inventory audit is now a plain text field
(e.g. "каб. 305") stored on the object instead of assigning it to a
box, since audit walks often use room/office labels that don't map
to the box/shelf hierarchy used elsewhere. Box assignment via the
regular object form is unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-22 15:41:30 +05:00

37 lines
1.6 KiB
Python

import uuid
from datetime import datetime
from typing import TYPE_CHECKING
from sqlalchemy import DateTime, ForeignKey, String, Text, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base
if TYPE_CHECKING:
from app.models.box import Box
from app.models.object_photo import ObjectPhoto
class InventoryObject(Base):
__tablename__ = "objects"
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
inventory_number: Mapped[str] = mapped_column(String(128), unique=True, index=True, nullable=False)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
box_id: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True), ForeignKey("boxes.id", ondelete="SET NULL"), nullable=True, index=True
)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
last_seen_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
last_seen_location: Mapped[str | None] = mapped_column(String(255), nullable=True)
box: Mapped["Box | None"] = relationship(back_populates="objects")
photos: Mapped[list["ObjectPhoto"]] = relationship(
back_populates="object", cascade="all, delete-orphan", order_by="ObjectPhoto.position"
)