56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, Unicode
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from crudkit.core.base import Base, CRUDMixin
|
|
|
|
class Inventory(Base, CRUDMixin):
|
|
__tablename__ = "inventory"
|
|
|
|
barcode: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
|
name: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
|
serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
|
|
|
condition: Mapped[str] = mapped_column(Unicode(255))
|
|
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
|
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
|
shared: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
|
timestamp: Mapped[DateTime] = mapped_column(DateTime)
|
|
|
|
brand: Mapped[Optional['Brand']] = relationship('Brand', back_populates='inventory')
|
|
brand_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('brand.id'), nullable=True, index=True)
|
|
|
|
device_type: Mapped[Optional['DeviceType']] = relationship('DeviceType', back_populates='inventory')
|
|
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("item.id"), nullable=True, index=True)
|
|
|
|
image: Mapped[Optional['Image']] = relationship('Image', back_populates='inventory', passive_deletes=True)
|
|
image_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('images.id', ondelete='SET NULL'), nullable=True, index=True)
|
|
|
|
location: Mapped[Optional['Room']] = relationship('Room', back_populates='inventory')
|
|
location_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('rooms.id'), nullable=True, index=True)
|
|
|
|
owner: Mapped[Optional['User']] = relationship('User', back_populates='inventory')
|
|
owner_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), nullable=True, index=True)
|
|
|
|
work_logs: Mapped[Optional[List['WorkLog']]] = relationship('WorkLog', back_populates='work_item')
|
|
|
|
def __repr__(self):
|
|
parts = [f"id={self.id}"]
|
|
|
|
if self.name:
|
|
parts.append(f"name={repr(self.name)}")
|
|
|
|
if self.device_type:
|
|
parts.append(f"item={repr(self.device_type.description)}")
|
|
|
|
if self.notes:
|
|
parts.append(f"notes={repr(self.notes)}")
|
|
|
|
if self.owner:
|
|
parts.append(f"owner={repr(self.owner.identifier)}")
|
|
|
|
if self.location:
|
|
parts.append(f"location={repr(self.location.identifier)}")
|
|
|
|
return f"<Inventory({', '.join(parts)})>"
|