Initial commit.
This commit is contained in:
commit
189f73b7c2
34 changed files with 1064 additions and 0 deletions
11
models/__init__.py
Normal file
11
models/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from .. import db # If you're in an actual module
|
||||
from .areas import Area
|
||||
from .brands import Brand
|
||||
from .items import Item
|
||||
from .inventory import Inventory
|
||||
from .room_functions import RoomFunction
|
||||
from .users import User
|
||||
from .work_log import WorkLog
|
||||
from .rooms import Room
|
BIN
models/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
models/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/areas.cpython-313.pyc
Normal file
BIN
models/__pycache__/areas.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/brands.cpython-313.pyc
Normal file
BIN
models/__pycache__/brands.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/inventory.cpython-313.pyc
Normal file
BIN
models/__pycache__/inventory.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/items.cpython-313.pyc
Normal file
BIN
models/__pycache__/items.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/room_functions.cpython-313.pyc
Normal file
BIN
models/__pycache__/room_functions.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/rooms.cpython-313.pyc
Normal file
BIN
models/__pycache__/rooms.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/users.cpython-313.pyc
Normal file
BIN
models/__pycache__/users.cpython-313.pyc
Normal file
Binary file not shown.
BIN
models/__pycache__/work_log.cpython-313.pyc
Normal file
BIN
models/__pycache__/work_log.cpython-313.pyc
Normal file
Binary file not shown.
19
models/areas.py
Normal file
19
models/areas.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .rooms import Room
|
||||
|
||||
from sqlalchemy import Identity, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class Area(db.Model):
|
||||
__tablename__ = 'Areas'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column("Area", Unicode(255), nullable=True)
|
||||
|
||||
rooms: Mapped[List['Room']] = relationship('Room', back_populates='area')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Area(id={self.id}, name={repr(self.name)})>"
|
19
models/brands.py
Normal file
19
models/brands.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
|
||||
from sqlalchemy import Identity, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class Brand(db.Model):
|
||||
__tablename__ = 'Brands'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column("Brand", Unicode(255), nullable=True)
|
||||
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='brand')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Brand(id={self.id}, name={repr(self.name)})>"
|
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}"
|
20
models/items.py
Normal file
20
models/items.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
|
||||
from sqlalchemy import Identity, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class Item(db.Model):
|
||||
__tablename__ = 'Items'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
description: Mapped[Optional[str]] = mapped_column("Description", Unicode(255), nullable=True)
|
||||
category: Mapped[Optional[str]] = mapped_column("Category", Unicode(255), nullable=True)
|
||||
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='item')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Item(id={self.id}, description={repr(self.description)}, category={repr(self.category)})>"
|
19
models/room_functions.py
Normal file
19
models/room_functions.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .rooms import Room
|
||||
|
||||
from sqlalchemy import Identity, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class RoomFunction(db.Model):
|
||||
__tablename__ = 'Room Functions'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
description: Mapped[Optional[str]] = mapped_column("Function", Unicode(255), nullable=True)
|
||||
|
||||
rooms: Mapped[List['Room']] = relationship('Room', back_populates='room_function')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<RoomFunction(id={self.id}, description={repr(self.description)})>"
|
34
models/rooms.py
Normal file
34
models/rooms.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from typing import Optional, TYPE_CHECKING, List
|
||||
if TYPE_CHECKING:
|
||||
from .areas import Area
|
||||
from .room_functions import RoomFunction
|
||||
from .inventory import Inventory
|
||||
from .users import User
|
||||
|
||||
from sqlalchemy import ForeignKey, Identity, Integer, Unicode
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class Room(db.Model):
|
||||
__tablename__ = 'Rooms'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
name: Mapped[Optional[str]] = mapped_column("Room", Unicode(255), nullable=True)
|
||||
area_id: Mapped[Optional[int]] = mapped_column("Area", Integer, ForeignKey("Areas.ID"))
|
||||
function_id: Mapped[Optional[int]] = mapped_column("Function", Integer, ForeignKey("Room Functions.ID"))
|
||||
|
||||
area: Mapped[Optional['Area']] = relationship('Area', back_populates='rooms')
|
||||
room_function: Mapped[Optional['RoomFunction']] = relationship('RoomFunction', back_populates='rooms')
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='location')
|
||||
users: Mapped[List['User']] = relationship('User', back_populates='location')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Room(id={self.id}, room={repr(self.name)}, area_id={self.area_id}, function_id={self.function_id})>"
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
name = self.name or ""
|
||||
func = self.room_function.description if self.room_function else ""
|
||||
return f"{name} - {func}".strip(" -")
|
||||
|
36
models/users.py
Normal file
36
models/users.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from typing import List, Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
from .rooms import Room
|
||||
from .work_log import WorkLog
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, Identity, Integer, Unicode, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from . import db
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = 'Users'
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
staff: Mapped[Optional[bool]] = mapped_column("Staff", Boolean, server_default=text('((0))'))
|
||||
active: Mapped[Optional[bool]] = mapped_column("Active", Boolean, server_default=text('((0))'))
|
||||
last_name: Mapped[Optional[str]] = mapped_column("Last", Unicode(255), nullable=True)
|
||||
first_name: Mapped[Optional[str]] = mapped_column("First", Unicode(255), nullable=True)
|
||||
location_id: Mapped[Optional[str]] = mapped_column(ForeignKey("Rooms.ID"))
|
||||
supervisor_id: Mapped[Optional[int]] = mapped_column("Supervisor", Integer, ForeignKey("Users.ID"))
|
||||
|
||||
supervisor: Mapped[Optional['User']] = relationship('User', remote_side='User.id', back_populates='subordinates')
|
||||
subordinates: Mapped[List['User']] = relationship('User', back_populates='supervisor')
|
||||
|
||||
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='contact')
|
||||
location: Mapped[Optional['Room']] = relationship('Room', back_populates='users')
|
||||
inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='owner')
|
||||
|
||||
@property
|
||||
def full_name(self) -> str:
|
||||
return f"{self.first_name or ''} {self.last_name or ''}".strip()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User(id={self.id}, first_name={repr(self.first_name)}, last_name={repr(self.last_name)}, " \
|
||||
f"location={repr(self.location)}, staff={self.staff}, active={self.active})>"
|
35
models/work_log.py
Normal file
35
models/work_log.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from typing import Optional, TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from .inventory import Inventory
|
||||
from .inventory import User
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKeyConstraint, Identity, Integer, ForeignKey, Unicode, text
|
||||
from sqlalchemy.dialects.mssql import DATETIME2
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
import datetime
|
||||
|
||||
from . import db
|
||||
|
||||
class WorkLog(db.Model):
|
||||
__tablename__ = 'Work Log'
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(['Work Item'], ['Inventory.ID'], name='Work Log$InventoryWork Log'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
start_time: Mapped[Optional[datetime.datetime]] = mapped_column('Start Timestamp', DATETIME2)
|
||||
end_time: Mapped[Optional[datetime.datetime]] = mapped_column('End Timestamp', DATETIME2)
|
||||
notes: Mapped[Optional[str]] = mapped_column('Description & Notes', Unicode())
|
||||
complete: Mapped[Optional[bool]] = mapped_column("Complete", Boolean, server_default=text('((0))'))
|
||||
followup: Mapped[Optional[bool]] = mapped_column('Needs Follow-Up', Boolean, server_default=text('((0))'))
|
||||
contact_id: Mapped[Optional[int]] = mapped_column('Point of Contact', Integer, ForeignKey("Users.ID"))
|
||||
analysis: Mapped[Optional[bool]] = mapped_column('Needs Quick Analysis', Boolean, server_default=text('((0))'))
|
||||
work_item_id: Mapped[Optional[int]] = mapped_column("Work Item", Integer, ForeignKey("Inventory.ID"))
|
||||
|
||||
work_item: Mapped[Optional['Inventory']] = relationship('Inventory', back_populates='work_logs')
|
||||
contact: Mapped[Optional['User']] = relationship('User', back_populates='work_logs')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<WorkLog(id={self.id}, start_time={self.start_time}, end_time={self.end_time}, " \
|
||||
f"notes={repr(self.notes)}, complete={self.complete}, followup={self.followup}, " \
|
||||
f"contact_id={self.contact_id}, analysis={self.analysis}, work_item_id={self.work_item_id})>"
|
Loading…
Add table
Add a link
Reference in a new issue