Files
belden-inventory/inventory/pages/checkout_page.py
2025-09-29 15:44:11 -05:00

100 lines
3.1 KiB
Python

from __future__ import annotations
from typing import * # type: ignore
import rio
import datetime
from mac_vendor_lookup import AsyncMacLookup
from db_classes import *
from .. import components as comps
import asyncio
class CheckoutPage(rio.Component):
code: str = ""
popup_message: str = ""
popup_show: bool = False
popup_color: str = 'warning'
description: str = ""
name: str = ""
user_code: str = ""
loc_code: str = ""
loc: str = ""
async def _update_location(self, event: rio.TextInputChangeEvent):
print("Checking " + self.loc)
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
async def _update_user(self, event: rio.TextInputChangeEvent):
print("Checking " + self.name)
if get_location_id(self.name) != False:
self.user_code = self.name
print("Found user " + 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)):
self.popup_message = "\n Item checked out! \n\n"
self.popup_show = True
self.popup_color = 'success'
self.name: str = ""
self.user_code: str = ""
self.code: str = ""
self.loc_code: str = ""
self.loc: str = ""
await asyncio.sleep(2)
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.popup_show = False
def build(self) -> rio.Component:
return rio.Column(
rio.Popup(
anchor=rio.Text(
text="Check out devices from storage:",
style='heading1',
align_x = 0.5
),
color=self.bind().popup_color,
is_open=self.bind().popup_show,
content=rio.Text(
text=self.bind().popup_message,
),
),
rio.TextInput(
label="Barcode",
text=self.bind().code
),
rio.TextInput(
label="New location",
text=self.bind().loc,
on_change=self._update_location
),
rio.TextInput(
label="User",
text=self.bind().name,
on_confirm=self._checkout_item_enter
),
rio.Button(
content="Go"
),
spacing=2,
min_width=60,
margin_bottom=4,
align_x=0.5,
align_y=0,
)