many changes
This commit is contained in:
@@ -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"
|
||||
|
@@ -30,7 +30,7 @@ class AddLocationPage(rio.Component):
|
||||
if get_location_id(self.parent) != False:
|
||||
self.parent_code = self.parent
|
||||
print("Found location " + get_location_id(self.parent).name)
|
||||
self.parent = get_location_id(self.parent).name
|
||||
self.parent = '*' + get_location_id(self.parent).name
|
||||
|
||||
async def add_part(self):
|
||||
if self.code == "":
|
||||
@@ -88,16 +88,19 @@ class AddLocationPage(rio.Component):
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Barcode",
|
||||
text=self.bind().code
|
||||
text=self.bind().code,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Parent Location (optional)",
|
||||
text=self.bind().parent,
|
||||
on_change=self._update_location
|
||||
on_change=self._update_location,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Location Name",
|
||||
text=self.bind().name
|
||||
text=self.bind().name,
|
||||
on_confirm=self._add_part_enter
|
||||
),
|
||||
rio.MultiLineTextInput(
|
||||
label="Description (optional)",
|
||||
|
@@ -81,8 +81,11 @@ class AddPage(rio.Component):
|
||||
self.popup_message = "\n Duplicate barcode! \n\n"
|
||||
self.popup_show = True
|
||||
self.popup_color = 'warning'
|
||||
await asyncio.sleep(2)
|
||||
await asyncio.sleep(5)
|
||||
self.popup_show = False
|
||||
self.session.navigate_to("/")
|
||||
await asyncio.sleep(0.01)
|
||||
self.session.navigate_to("/add")
|
||||
else:
|
||||
self.popup_message = "\n Part added! \n\n"
|
||||
self.popup_show = True
|
||||
@@ -99,8 +102,12 @@ class AddPage(rio.Component):
|
||||
self.description: str = ""
|
||||
self.location: str = ""
|
||||
self.location_code: str = ""
|
||||
await asyncio.sleep(2)
|
||||
await asyncio.sleep(1)
|
||||
self.session.navigate_to("/")
|
||||
await asyncio.sleep(0.01)
|
||||
self.session.navigate_to("/add")
|
||||
self.popup_show = False
|
||||
#self.session.navigate_to("/add",replace=True)
|
||||
|
||||
|
||||
async def _add_part_enter(self, event: rio.TextInputConfirmEvent):
|
||||
@@ -134,7 +141,7 @@ class AddPage(rio.Component):
|
||||
if get_location_id(self.location) != False:
|
||||
self.location_code = self.location
|
||||
print("Found location " + get_location_id(self.location).name)
|
||||
self.location = get_location_id(self.location).name
|
||||
self.location = '*' + get_location_id(self.location).name
|
||||
|
||||
|
||||
def _update_partnum(self, event: rio.TextInputChangeEvent):
|
||||
@@ -230,7 +237,8 @@ class AddPage(rio.Component):
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Barcode",
|
||||
text=self.bind().code
|
||||
text=self.bind().code,
|
||||
auto_focus=True
|
||||
),
|
||||
rio.TextInput(
|
||||
label="Full part number",
|
||||
|
@@ -146,7 +146,7 @@ class BrowsePage(rio.Component):
|
||||
self.edit_show = False
|
||||
self.info_show = True
|
||||
self.force_refresh()
|
||||
await delete_item_id(self.ibarcode)
|
||||
delete_item_id(self.ibarcode)
|
||||
await self._search()
|
||||
await asyncio.sleep(1)
|
||||
self.popup_show = False
|
||||
@@ -230,7 +230,7 @@ class BrowsePage(rio.Component):
|
||||
if get_location_id(self.elocation) != False:
|
||||
self.elocation_code = self.elocation
|
||||
print("Found location " + get_location_id(self.elocation).name)
|
||||
self.elocation = get_location_id(self.elocation).name
|
||||
self.elocation = '*' + get_location_id(self.elocation).name
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
searchview: rio.ListView = rio.ListView(grow_y=True)
|
||||
|
@@ -1,7 +1,8 @@
|
||||
peewee
|
||||
pymysql
|
||||
#rio-ui==0.10.4
|
||||
rio-ui==0.11.1
|
||||
rio-ui==0.11.2rc7
|
||||
meilisearch #==0.31.5
|
||||
mac-vendor-lookup
|
||||
cryptography
|
||||
|
||||
|
Reference in New Issue
Block a user