Refactor inventory model and related routes to standardize field names and improve clarity
This commit is contained in:
parent
ac05373f95
commit
65dcbbfb0b
6 changed files with 31 additions and 38 deletions
|
@ -14,24 +14,23 @@ from . import db
|
|||
class Inventory(db.Model):
|
||||
__tablename__ = 'Inventory'
|
||||
__table_args__ = (
|
||||
Index('Inventory$Bar Code', 'Bar Code'),
|
||||
Index('Inventory$Barcode', 'barcode'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column("ID", Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
timestamp: Mapped[datetime.datetime] = mapped_column('Date Entered', DateTime)
|
||||
condition: Mapped[str] = mapped_column('Working Condition', Unicode(255))
|
||||
needed: Mapped[str] = mapped_column("Needed", Unicode(255))
|
||||
type_id: Mapped[Optional[int]] = mapped_column('Item Type', Integer, ForeignKey("Items.ID"), nullable=True)
|
||||
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'))
|
||||
id: Mapped[int] = mapped_column(Integer, Identity(start=1, increment=1), primary_key=True)
|
||||
timestamp: Mapped[datetime.datetime] = mapped_column(DateTime)
|
||||
condition: Mapped[str] = mapped_column(Unicode(255))
|
||||
type_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("Items.ID"), nullable=True)
|
||||
name: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
serial: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
model: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
notes: Mapped[Optional[str]] = mapped_column(Unicode(255))
|
||||
owner_id = mapped_column(Integer, ForeignKey('Users.ID'))
|
||||
brand_id: Mapped[Optional[int]] = mapped_column(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("Shared", Boolean, server_default=text('((0))'))
|
||||
barcode: Mapped[Optional[str]] = mapped_column(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')
|
||||
|
@ -39,16 +38,15 @@ class Inventory(db.Model):
|
|||
item: Mapped['Item'] = relationship('Item', back_populates='inventory')
|
||||
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='work_item')
|
||||
|
||||
def __init__(self, timestamp: datetime.datetime, condition: str, needed: str, type_id: Optional[int] = None,
|
||||
inventory_name: Optional[str] = None, serial: Optional[str] = None,
|
||||
def __init__(self, timestamp: datetime.datetime, condition: str, type_id: Optional[int] = None,
|
||||
name: Optional[str] = None, serial: Optional[str] = None,
|
||||
model: Optional[str] = None, notes: Optional[str] = None, owner_id: Optional[int] = None,
|
||||
brand_id: Optional[int] = None, location_id: Optional[str] = None, barcode: Optional[str] = None,
|
||||
shared: bool = False):
|
||||
self.timestamp = timestamp
|
||||
self.condition = condition
|
||||
self.needed = needed
|
||||
self.type_id = type_id
|
||||
self.inventory_name = inventory_name
|
||||
self.name = name
|
||||
self.serial = serial
|
||||
self.model = model
|
||||
self.notes = notes
|
||||
|
@ -61,8 +59,8 @@ class Inventory(db.Model):
|
|||
def __repr__(self):
|
||||
parts = [f"id={self.id}"]
|
||||
|
||||
if self.inventory_name:
|
||||
parts.append(f"name={repr(self.inventory_name)}")
|
||||
if self.name:
|
||||
parts.append(f"name={repr(self.name)}")
|
||||
|
||||
if self.item:
|
||||
parts.append(f"item={repr(self.item.description)}")
|
||||
|
@ -80,8 +78,8 @@ class Inventory(db.Model):
|
|||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
if self.inventory_name:
|
||||
return f"Name: {self.inventory_name}"
|
||||
if self.name:
|
||||
return f"Name: {self.name}"
|
||||
elif self.barcode:
|
||||
return f"Bar: {self.barcode}"
|
||||
elif self.serial:
|
||||
|
@ -94,9 +92,8 @@ class Inventory(db.Model):
|
|||
'id': self.id,
|
||||
'timestamp': self.timestamp.isoformat() if self.timestamp else None,
|
||||
'condition': self.condition,
|
||||
'needed': self.needed,
|
||||
'type_id': self.type_id,
|
||||
'inventory_name': self.inventory_name,
|
||||
'name': self.name,
|
||||
'serial': self.serial,
|
||||
'model': self.model,
|
||||
'notes': self.notes,
|
||||
|
@ -114,9 +111,8 @@ class Inventory(db.Model):
|
|||
return cls(
|
||||
timestamp = datetime.datetime.fromisoformat(str(timestamp_str)) if timestamp_str else datetime.datetime.now(),
|
||||
condition=data.get("condition", "Unverified"),
|
||||
needed=data.get("needed", ""),
|
||||
type_id=data["type_id"],
|
||||
inventory_name=data.get("inventory_name"),
|
||||
name=data.get("name"),
|
||||
serial=data.get("serial"),
|
||||
model=data.get("model"),
|
||||
notes=data.get("notes"),
|
||||
|
|
|
@ -20,7 +20,7 @@ class WorkLog(db.Model):
|
|||
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_id: Mapped[Optional[int]] = mapped_column(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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue