Initial commit.
This commit is contained in:
commit
189f73b7c2
34 changed files with 1064 additions and 0 deletions
73
models/inventory.py
Normal file
73
models/inventory.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
from typing import Any, List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .brands import Brand
|
||||
from .items import Item
|
||||
from .users import User
|
||||
from .work_log import WorkLog
|
||||
from .rooms import Room
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKeyConstraint, ForeignKey, Identity, Index, Integer, PrimaryKeyConstraint, String, Unicode, text
|
||||
from sqlalchemy.dialects.mssql import DATETIME2, MONEY
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
import datetime
|
||||
|
||||
from . import db
|
||||
|
||||
class Inventory(db.Model):
|
||||
__tablename__ = 'Inventory'
|
||||
__table_args__ = (
|
||||
Index('Inventory$Bar Code', 'Bar Code'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
timestamp: Mapped[datetime.datetime] = mapped_column('Date Entered', DATETIME2)
|
||||
condition: Mapped[str] = mapped_column('Working Condition', Unicode(255))
|
||||
needed: Mapped[str] = mapped_column("Needed", Unicode(255))
|
||||
type_id: Mapped[int] = mapped_column('Item Type', Integer, ForeignKey("Items.ID"))
|
||||
inventory_name: Mapped[Optional[str]] = mapped_column('Inventory #', Unicode(255))
|
||||
serial: Mapped[Optional[str]] = mapped_column('Serial #', Unicode(255))
|
||||
model: Mapped[Optional[str]] = mapped_column('Model #', Unicode(255))
|
||||
notes: Mapped[Optional[str]] = mapped_column('Notes', Unicode(255))
|
||||
owner_id = mapped_column('Owner', Integer, ForeignKey('Users.ID'))
|
||||
brand_id: Mapped[Optional[int]] = mapped_column("Brand", Integer, ForeignKey("Brands.ID"))
|
||||
# Photo: Mapped[Optional[str]] = mapped_column(String(8000)) Will be replacing with something that actually works.
|
||||
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("Rooms.ID"))
|
||||
barcode: Mapped[Optional[str]] = mapped_column('Bar Code', Unicode(255))
|
||||
shared: Mapped[Optional[bool]] = mapped_column(Boolean, server_default=text('((0))'))
|
||||
|
||||
location: Mapped[Optional['Room']] = relationship('Room', back_populates='inventory')
|
||||
owner = relationship('User', back_populates='inventory')
|
||||
brand: Mapped[Optional['Brand']] = relationship('Brand', back_populates='inventory')
|
||||
item: Mapped['Item'] = relationship('Item', back_populates='inventory')
|
||||
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='work_item')
|
||||
|
||||
def __repr__(self):
|
||||
parts = [f"id={self.id}"]
|
||||
|
||||
if self.inventory_name:
|
||||
parts.append(f"name={repr(self.inventory_name)}")
|
||||
|
||||
if self.item:
|
||||
parts.append(f"item={repr(self.item.description)}")
|
||||
|
||||
if self.notes:
|
||||
parts.append(f"notes={repr(self.notes)}")
|
||||
|
||||
if self.owner:
|
||||
parts.append(f"owner={repr(self.owner.full_name)}")
|
||||
|
||||
if self.location:
|
||||
parts.append(f"location={repr(self.location.full_name)}")
|
||||
|
||||
return f"<Inventory({', '.join(parts)})>"
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
if self.inventory_name:
|
||||
return f"Name: {self.inventory_name}"
|
||||
elif self.barcode:
|
||||
return f"Bar: {self.barcode}"
|
||||
elif self.serial:
|
||||
return f"Serial: {self.serial}"
|
||||
else:
|
||||
return f"ID: {self.id}"
|
Loading…
Add table
Add a link
Reference in a new issue