many changes

This commit is contained in:
2025-09-29 20:54:29 -05:00
parent 67a999c418
commit 97cb5a6e3e
5 changed files with 65 additions and 16 deletions

View File

@@ -82,7 +82,8 @@ def init():
try:
db.connect()
break
except:
except Exception as e:
print(e)
time.sleep(1)
print("Checking & creating tables...")
db.create_tables([location, office, item, component, user])
@@ -95,7 +96,7 @@ def init():
#print(type(add))
for itm in add:
try:
itm["location"] = item.select().where(item.barcode==itm["barcode"])[0].loc.name
itm["location"] = fancy_location(item.select().where(item.barcode==itm["barcode"])[0].loc)
except:
pass
#print(itm)
@@ -104,6 +105,7 @@ def init():
print('.',end='',flush=True)
print(" " + str(len(add)), "items added.")
print("Cache build complete.")
# locations_list()
def search_item(query, filters: dict={}):
#print(filters)
@@ -132,7 +134,26 @@ def search_item(query, filters: dict={}):
return search.search(query, "")["hits"]
def find_item(barcode):
return search.get_barcode(barcode)
res = search.get_barcode(barcode)
try:
res["location"] = fancy_location(get_location(res["location"].split(' -> ')[-1]))
except:
pass
return res
def fancy_location(loc):
try:
loc_str = [loc.name]
while loc.parent:
loc_str.append(loc.parent.name)
loc = loc.parent
loc_str.reverse()
# print(loc_str)
out = " -> ".join(loc_str)
# print(out)
return out
except:
return loc.name
def find_item_location(barcode):
try:
@@ -158,7 +179,7 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript
itm.save(force_insert=True)
itmdict= item.select().where(item.barcode==barcode).dicts()[0]
try:
itmdict["location"] = loc.name
itmdict["location"] = fancy_location(loc)
#print(locationid)
#print(itmdict["location"])
except:
@@ -189,7 +210,7 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript
itm.save()
itmdict= item.select().where(item.barcode==barcode).dicts()[0]
try:
itmdict["location"] = loc.name
itmdict["location"] = fancy_location(loc)
#print(locationid)
#print(itmdict["location"])
except:
@@ -295,6 +316,8 @@ def checkin(user, barcode, loc=None):
def create_location(name, barcode, parent=None, description=None):
try:
if name == "" or barcode == "":
return False
loc = location(name=name, locationid=barcode, parent=parent, description=description)
loc.save(force_insert=True)
print(loc.name, loc.locationid)
@@ -367,6 +390,20 @@ def check_db_connection():
# require the query to fire by checking it's return length
pass
def locations_list():
query = location.select()
for entry in query:
if entry.parent:
p = entry.parent.name
else:
p=""
if entry.name == "":
entry.delete_instance()
else:
print(entry.name, "Parent:", p)
def test():
costa = create_user("Costa Aralis", "caralpwtwfpis", "12345")
costa.username = "caralis"