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')
|
||||
|
|
|
@ -5,7 +5,7 @@ from ..models import Inventory
|
|||
inventory_headers = {
|
||||
"Date Entered": lambda i: {"text": i.timestamp.strftime("%Y-%m-%d") if i.timestamp else None},
|
||||
"Identifier": lambda i: {"text": i.identifier},
|
||||
"Inventory #": lambda i: {"text": i.inventory_name},
|
||||
"Inventory #": lambda i: {"text": i.name},
|
||||
"Serial #": lambda i: {"text": i.serial},
|
||||
"Bar Code #": lambda i: {"text": i.barcode},
|
||||
"Brand": lambda i: {"text": i.brand.name} if i.brand else {"text": None},
|
||||
|
|
|
@ -17,7 +17,7 @@ def list_inventory():
|
|||
|
||||
query = db.session.query(Inventory)
|
||||
query = eager_load_inventory_relationships(query)
|
||||
# query = query.order_by(Inventory.inventory_name, Inventory.barcode, Inventory.serial)
|
||||
# query = query.order_by(Inventory.name, Inventory.barcode, Inventory.serial)
|
||||
|
||||
if filter_by and id:
|
||||
column = FILTER_MAP.get(filter_by)
|
||||
|
@ -126,7 +126,6 @@ def new_inventory_item():
|
|||
item = Inventory(
|
||||
timestamp=datetime.datetime.now(),
|
||||
condition="Unverified",
|
||||
needed="",
|
||||
type_id=None,
|
||||
)
|
||||
|
||||
|
@ -169,9 +168,8 @@ def update_inventory_item(id):
|
|||
|
||||
item.timestamp = datetime.datetime.fromisoformat(data.get("timestamp")) if data.get("timestamp") else item.timestamp
|
||||
item.condition = data.get("condition", item.condition)
|
||||
item.needed = data.get("needed", item.needed)
|
||||
item.type_id = data.get("type_id", item.type_id)
|
||||
item.inventory_name = data.get("inventory_name", item.inventory_name)
|
||||
item.name = data.get("name", item.name)
|
||||
item.serial = data.get("serial", item.serial)
|
||||
item.model = data.get("model", item.model)
|
||||
item.notes = data.get("notes", item.notes)
|
||||
|
|
|
@ -20,7 +20,7 @@ def search():
|
|||
|
||||
inventory_query = eager_load_inventory_relationships(db.session.query(Inventory).join(UserAlias, Inventory.owner)).filter(
|
||||
or_(
|
||||
Inventory.inventory_name.ilike(f"%{query}%"),
|
||||
Inventory.name.ilike(f"%{query}%"),
|
||||
Inventory.serial.ilike(f"%{query}%"),
|
||||
Inventory.barcode.ilike(f"%{query}%"),
|
||||
Inventory.notes.ilike(f"%{query}%"),
|
||||
|
@ -41,7 +41,7 @@ def search():
|
|||
WorkLog.notes.ilike(f"%{query}%"),
|
||||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%"),
|
||||
InventoryAlias.inventory_name.ilike(f"%{query}%"),
|
||||
InventoryAlias.name.ilike(f"%{query}%"),
|
||||
InventoryAlias.serial.ilike(f"%{query}%"),
|
||||
InventoryAlias.barcode.ilike(f"%{query}%")
|
||||
))
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="inventory_name" class="form-label">Inventory #</label>
|
||||
<input type="text" class="form-control" name="inventory_name" placeholder="-"
|
||||
value="{{ item.inventory_name or '' }}">
|
||||
<label for="name" class="form-label">Inventory #</label>
|
||||
<input type="text" class="form-control" name="name" placeholder="-"
|
||||
value="{{ item.name or '' }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="serial" class="form-label">Serial #</label>
|
||||
|
@ -140,9 +140,8 @@
|
|||
const payload = {
|
||||
timestamp: document.querySelector("input[name='timestamp']").value,
|
||||
condition: document.querySelector("select[name='condition']").value,
|
||||
needed: "", // ← either add a field for this or drop it if obsolete
|
||||
type_id: parseInt(document.querySelector("select[name='type']").value),
|
||||
inventory_name: document.querySelector("input[name='inventory_name']").value || null,
|
||||
name: document.querySelector("input[name='name']").value || null,
|
||||
serial: document.querySelector("input[name='serial']").value || null,
|
||||
model: document.querySelector("input[name='model']").value || null,
|
||||
notes: document.querySelector("textarea[name='notes']").value || null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue