Fix checkin/out pages, add location refresh, and misc bugfix
This commit is contained in:
@@ -10,6 +10,13 @@ class ReconnectMySQLDatabase(ReconnectMixin, MySQLDatabase):
|
||||
db = ReconnectMySQLDatabase('inventory', thread_safe=True, user='inventory', password='nfrwnfprifbwef', host='database', port=3306)
|
||||
search = None
|
||||
|
||||
USERS = [
|
||||
("Costa Aralis", "COSTA"),
|
||||
("Mike Fisher", "MIKE"),
|
||||
("Mark Lueck", "MARK"),
|
||||
("Cole Deck", "COLE")
|
||||
]
|
||||
|
||||
class user(Model):
|
||||
name = CharField()
|
||||
username = CharField(unique=True, primary_key=True)
|
||||
@@ -88,13 +95,15 @@ def init():
|
||||
print("Checking & creating tables...")
|
||||
db.create_tables([location, office, item, component, user])
|
||||
print("Database initialized.")
|
||||
for usr in USERS:
|
||||
create_user(usr[0],usr[1],"12345")
|
||||
global search
|
||||
print("Creating cache index...", end='', flush=True)
|
||||
print("Creating cache index")
|
||||
search = ivs()
|
||||
add = item.select().dicts()
|
||||
#print(add)
|
||||
#print(type(add))
|
||||
for itm in add:
|
||||
for idx,itm in enumerate(add):
|
||||
try:
|
||||
itm["location"] = fancy_location(item.select().where(item.barcode==itm["barcode"])[0].loc)
|
||||
except:
|
||||
@@ -102,9 +111,11 @@ def init():
|
||||
#print(itm)
|
||||
#print(type(itm))
|
||||
search.add_document(itm)
|
||||
print('.',end='',flush=True)
|
||||
print(f'{idx}/{len(add)}')
|
||||
print(" " + str(len(add)), "items added.")
|
||||
print("Cache build complete.")
|
||||
|
||||
|
||||
# locations_list()
|
||||
|
||||
def search_item(query, filters: dict={}) -> list:
|
||||
@@ -153,7 +164,10 @@ def fancy_location(loc):
|
||||
# print(out)
|
||||
return out
|
||||
except:
|
||||
return loc.name
|
||||
if loc:
|
||||
return loc.name
|
||||
else:
|
||||
return ""
|
||||
|
||||
def find_item_location(barcode):
|
||||
try:
|
||||
@@ -296,6 +310,9 @@ def checkout(user, barcode, loc=None):
|
||||
itm.checkout_user = user
|
||||
itm.checkout_loc = loc
|
||||
itm.save()
|
||||
itmdict = item.select().where(item.barcode==itm.barcode).dicts()[0]
|
||||
itmdict["location"] = fancy_location(item.select().where(item.barcode==itm["barcode"])[0].loc)
|
||||
search.add_document(itmdict)
|
||||
return itm
|
||||
else:
|
||||
return False
|
||||
@@ -305,11 +322,15 @@ def checkin(user, barcode, loc=None):
|
||||
if loc == False:
|
||||
loc = None
|
||||
if itm:
|
||||
print("Found", itm.fullname)
|
||||
itm.checkout = False
|
||||
itm.last_user = user
|
||||
if loc is not None:
|
||||
itm.loc = loc
|
||||
itm.save()
|
||||
itmdict = item.select().where(item.barcode==itm.barcode).dicts()[0]
|
||||
itmdict["location"] = fancy_location(item.select().where(item.barcode==itm["barcode"])[0].loc)
|
||||
search.add_document(itmdict)
|
||||
return itm
|
||||
else:
|
||||
return False
|
||||
@@ -370,12 +391,15 @@ def get_location_id(barcode):
|
||||
def get_user(name):
|
||||
query = user.select().where(user.username == name)
|
||||
if len(query) == 1:
|
||||
print("Found", query[0].name)
|
||||
return query[0]
|
||||
|
||||
query = user.select().where(user.name == name)
|
||||
if len(query) == 1:
|
||||
print("Found", query[0].name)
|
||||
return query[0]
|
||||
|
||||
print(f"Did not find a user: {name}")
|
||||
return False
|
||||
|
||||
def user_login(username, password):
|
||||
@@ -410,7 +434,7 @@ def dump_csv():
|
||||
out = "Barcode,Part Number,Serial,MAC,FW Version,Manufacturer,Description,Location,Office,Checked out,Checkout location,Checkout user,Checkout start time,Checkout end time\r\n"
|
||||
query = item.select()
|
||||
for itm in query:
|
||||
out += f"\"{itm.barcode}\",\"{itm.fullname}\",\"{itm.serial}\",\"{itm.mac}\",\"{itm.fwver}\",\"{itm.manufacturer}\",\"{itm.description}\",\"{itm.loc}\",\"{itm.office}\",\"{itm.checkout}\",\"{itm.checkout_loc}\",\"{itm.checkout_user}\",\"{itm.checkout_start}\",\"{itm.checkout_end}\"\r\n"
|
||||
out += f"\"{itm.barcode}\",\"{itm.fullname}\",\"{itm.serial}\",\"{itm.mac}\",\"{itm.fwver}\",\"{itm.manufacturer}\",\"{itm.description}\",\"{fancy_location(itm.loc)}\",\"{itm.office.name}\",\"{itm.checkout}\",\"{itm.checkout_loc}\",\"{itm.checkout_user}\",\"{itm.checkout_start}\",\"{itm.checkout_end}\"\r\n"
|
||||
|
||||
return out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user