From f793bd01e1de8637eca7e2d153696c6eb78b1327 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Thu, 9 Apr 2026 17:16:56 -0500 Subject: [PATCH] Fix checkin/out pages, add location refresh, and misc bugfix --- db_classes.py | 34 +++++++++++++++++++++++++----- inventory/pages/add_location.py | 14 ++++++++++--- inventory/pages/add_page.py | 2 +- inventory/pages/browse_page.py | 11 +++++----- inventory/pages/checkin_page.py | 36 +++++++++++++++++++++++--------- inventory/pages/checkout_page.py | 32 +++++++++++++++++++++------- 6 files changed, 97 insertions(+), 32 deletions(-) diff --git a/db_classes.py b/db_classes.py index 1ab51ab..ca5be69 100644 --- a/db_classes.py +++ b/db_classes.py @@ -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 diff --git a/inventory/pages/add_location.py b/inventory/pages/add_location.py index 37ec988..3d95c7f 100644 --- a/inventory/pages/add_location.py +++ b/inventory/pages/add_location.py @@ -51,6 +51,9 @@ class AddLocationPage(rio.Component): self.popup_show = True self.popup_color = 'warning' await asyncio.sleep(2) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/addlocation") self.popup_show = False else: self.popup_message = "\n Location added! \n\n" @@ -61,7 +64,10 @@ class AddLocationPage(rio.Component): self.description: str = "" self.parent_code: str = "" self.parent: str = "" - await asyncio.sleep(2) + await asyncio.sleep(1) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/addlocation") self.popup_show = False @@ -89,7 +95,8 @@ class AddLocationPage(rio.Component): rio.TextInput( label="Barcode", text=self.bind().code, - on_confirm=self._add_part_enter + on_confirm=self._add_part_enter, + auto_focus=True ), rio.TextInput( label="Parent Location (optional)", @@ -104,7 +111,8 @@ class AddLocationPage(rio.Component): ), rio.MultiLineTextInput( label="Description (optional)", - text=self.bind().description + text=self.bind().description, + on_confirm=self._add_part_enter ), rio.Button( content="Add", diff --git a/inventory/pages/add_page.py b/inventory/pages/add_page.py index 70a2e8a..57857a1 100644 --- a/inventory/pages/add_page.py +++ b/inventory/pages/add_page.py @@ -7,7 +7,7 @@ import rio import datetime from mac_vendor_lookup import AsyncMacLookup, MacLookup mac = MacLookup() -print("Updating vendors...") +print("Updating MAC vendors...") try: mac.update_vendors() print("Update complete!") diff --git a/inventory/pages/browse_page.py b/inventory/pages/browse_page.py index 3d380a9..3235273 100644 --- a/inventory/pages/browse_page.py +++ b/inventory/pages/browse_page.py @@ -124,7 +124,8 @@ class BrowsePage(rio.Component): async def _close_edit_popup(self): await self._open_info_popup(self.ibarcode) - self.force_refresh() + # self._search(self.searchtext) + # self.force_refresh() async def _save_edit_popup(self): self.edit_show = False @@ -133,11 +134,11 @@ class BrowsePage(rio.Component): await self._add_part_button() await asyncio.sleep(1) await self._open_info_popup(self.ibarcode, skip_display=True) - await self._search() + await self._search(self.searchtext) await asyncio.sleep(1) self.popup_show = False await self._open_info_popup(self.ibarcode, skip_display=True) - await self._search() + await self._search(self.searchtext) @@ -149,10 +150,10 @@ class BrowsePage(rio.Component): self.info_show = False self.force_refresh() delete_item_id(self.ibarcode) - await self._search() + await self._search(self.searchtext) await asyncio.sleep(1) self.popup_show = False - await self._search() + await self._search(self.searchtext) async def _open_edit_popup(self, code: str) -> str | None: diff --git a/inventory/pages/checkin_page.py b/inventory/pages/checkin_page.py index 3cc7937..4e3a0be 100644 --- a/inventory/pages/checkin_page.py +++ b/inventory/pages/checkin_page.py @@ -15,8 +15,8 @@ class CheckinPage(rio.Component): popup_message: str = "" popup_show: bool = False popup_color: str = 'warning' - name: str = "" user_code: str = "" + name: str = "" loc_code: str = "" loc: str = "" @@ -25,35 +25,43 @@ class CheckinPage(rio.Component): if get_location_id(self.loc) != False: self.loc_code = self.loc print("Found location " + get_location_id(self.loc).name) - self.loc = get_location_id(self.loc).name + self.loc = '* ' + fancy_location(get_location_id(self.loc)) async def _update_user(self, event: rio.TextInputChangeEvent): print("Checking " + self.name) - if get_location_id(self.name) != False: + if get_user(self.name) != False: self.user_code = self.name print("Found user " + get_user(self.name).name) - self.name = get_user(self.name).name + self.name = '* ' + get_user(self.name).name async def _checkin_item_enter(self, event: rio.TextInputConfirmEvent): await self.check_in() async def check_in(self): - if checkin(get_user(self.user_code), self.code, get_location_id(self.loc_code)): + user = get_user(self.user_code) + loc = get_location_id(self.loc_code) + if user is not False and checkin(user, self.code, loc): self.popup_message = "\n Item checked in! \n\n" self.popup_show = True self.popup_color = 'success' - self.name: str = "" self.user_code: str = "" + self.name: str = "" self.code: str = "" self.loc_code: str = "" self.loc: str = "" - await asyncio.sleep(2) + await asyncio.sleep(0.5) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/in") self.popup_show = False else: self.popup_message = "\n Error! Check item & location! \n\n" self.popup_show = True self.popup_color = 'warning' await asyncio.sleep(2) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/in") self.popup_show = False def build(self) -> rio.Component: @@ -73,7 +81,8 @@ class CheckinPage(rio.Component): ), rio.TextInput( label="Barcode", - text=self.bind().code + text=self.bind().code, + auto_focus=True ), rio.TextInput( label="New location", @@ -83,10 +92,17 @@ class CheckinPage(rio.Component): rio.TextInput( label="User", text=self.bind().name, - on_confirm=self._checkin_item_enter + on_confirm=self.check_in, + on_change=self._update_user ), + # rio.TextInput( + # label="N/A", + # text="", + # on_confirm=self.check_in, + # ), rio.Button( - content="Go" + content="Go", + on_press=self.check_in ), spacing=2, diff --git a/inventory/pages/checkout_page.py b/inventory/pages/checkout_page.py index d12bb54..209c229 100644 --- a/inventory/pages/checkout_page.py +++ b/inventory/pages/checkout_page.py @@ -26,20 +26,22 @@ class CheckoutPage(rio.Component): if get_location_id(self.loc) != False: self.loc_code = self.loc print("Found location " + get_location_id(self.loc).name) - self.loc = get_location_id(self.loc).name + self.loc = '* ' + fancy_location(get_location_id(self.loc)) async def _update_user(self, event: rio.TextInputChangeEvent): print("Checking " + self.name) - if get_location_id(self.name) != False: + if get_user(self.name) != False: self.user_code = self.name print("Found user " + get_user(self.name).name) - self.name = get_user(self.name).name + self.name = '* ' + get_user(self.name).name async def _checkout_item_enter(self, event: rio.TextInputConfirmEvent): await self.check_out() async def check_out(self): - if checkout(get_user(self.user_code), self.code, get_location_id(self.loc_code)): + user = get_user(self.user_code) + loc = get_location_id(self.loc_code) + if user is not False and checkout(user, self.code, loc): self.popup_message = "\n Item checked out! \n\n" self.popup_show = True self.popup_color = 'success' @@ -48,13 +50,19 @@ class CheckoutPage(rio.Component): self.code: str = "" self.loc_code: str = "" self.loc: str = "" - await asyncio.sleep(2) + await asyncio.sleep(0.5) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/out") self.popup_show = False else: self.popup_message = "\n Error! Check item & location! \n\n" self.popup_show = True self.popup_color = 'warning' await asyncio.sleep(2) + self.session.navigate_to("/") + await asyncio.sleep(0.01) + self.session.navigate_to("/out") self.popup_show = False def build(self) -> rio.Component: @@ -74,7 +82,8 @@ class CheckoutPage(rio.Component): ), rio.TextInput( label="Barcode", - text=self.bind().code + text=self.bind().code, + auto_focus=True ), rio.TextInput( label="New location", @@ -84,10 +93,17 @@ class CheckoutPage(rio.Component): rio.TextInput( label="User", text=self.bind().name, - on_confirm=self._checkout_item_enter + on_confirm=self.check_out, + on_change=self._update_user ), + # rio.TextInput( + # label="N/A", + # text="", + # on_confirm=self.check_out, + # ), rio.Button( - content="Go" + content="Go", + on_press=self.check_out, ), spacing=2,