Add basic support for training mode

make it obvious when in effect, mark batches accordingly etc.
This commit is contained in:
Lance Edgar 2023-10-19 20:53:07 -05:00
parent 22894b6c7a
commit 0e5ad257c8
3 changed files with 116 additions and 19 deletions

View file

@ -234,6 +234,10 @@ def main(page: ft.Page):
# TODO: this may be too hacky but is useful for now/dev # TODO: this may be too hacky but is useful for now/dev
if not config.production(): if not config.production():
training = page.client_storage.get('training')
page.session.set('training', training)
user = None user = None
uuid = page.client_storage.get('user_uuid') uuid = page.client_storage.get('user_uuid')
if uuid: if uuid:

View file

@ -43,18 +43,28 @@ class WuttaHeader(WuttaControl):
def build(self): def build(self):
self.txn_display = ft.Text("Txn: N", weight=ft.FontWeight.BOLD, size=20) self.txn_display = ft.Text("Txn: N", weight=ft.FontWeight.BOLD, size=20)
self.cust_display = ft.Text("Cust: N", weight=ft.FontWeight.BOLD, size=20) self.cust_display = ft.Text("Cust: N", weight=ft.FontWeight.BOLD, size=20)
self.training_mode = ft.Text(size=40, weight=ft.FontWeight.BOLD, bgcolor='yellow')
self.user_display = ft.Text("User: N", weight=ft.FontWeight.BOLD, size=20) self.user_display = ft.Text("User: N", weight=ft.FontWeight.BOLD, size=20)
self.logout_button = ft.OutlinedButton("Logout", on_click=self.logout_click, visible=False) self.logout_button = ft.OutlinedButton("Logout", on_click=self.logout_click, visible=False)
self.logout_divider = ft.VerticalDivider(visible=False) self.logout_divider = ft.VerticalDivider(visible=False)
self.title_button = ft.FilledButton(self.app.get_title(), on_click=self.title_click) self.title_button = ft.FilledButton(self.app.get_title(), on_click=self.title_click)
controls = [ return ft.Row(
[
ft.Row(
[
self.txn_display, self.txn_display,
ft.VerticalDivider(), ft.VerticalDivider(),
self.cust_display, self.cust_display,
ft.VerticalDivider(), ft.VerticalDivider(),
WuttaTimestamp(self.config, expand=True, WuttaTimestamp(self.config, weight=ft.FontWeight.BOLD, size=20),
weight=ft.FontWeight.BOLD, size=20), ],
),
self.training_mode,
ft.Row(
[
self.user_display, self.user_display,
ft.VerticalDivider(), ft.VerticalDivider(),
self.logout_button, self.logout_button,
@ -62,9 +72,11 @@ class WuttaHeader(WuttaControl):
ft.Text(f"Term: {self.term_display}", weight=ft.FontWeight.BOLD, size=20), ft.Text(f"Term: {self.term_display}", weight=ft.FontWeight.BOLD, size=20),
ft.VerticalDivider(), ft.VerticalDivider(),
self.title_button, self.title_button,
] ],
),
return ft.Row(controls) ],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
)
def did_mount(self): def did_mount(self):
self.informed_refresh() self.informed_refresh()
@ -73,6 +85,7 @@ class WuttaHeader(WuttaControl):
self.update_txn_display() self.update_txn_display()
self.update_cust_display() self.update_cust_display()
self.update_user_display() self.update_user_display()
self.update_training_display()
self.update() self.update()
def update_txn_display(self): def update_txn_display(self):
@ -87,6 +100,12 @@ class WuttaHeader(WuttaControl):
cust_display = self.page.session.get('cust_display') cust_display = self.page.session.get('cust_display')
self.cust_display.value = f"Cust: {cust_display or 'N'}" self.cust_display.value = f"Cust: {cust_display or 'N'}"
def update_training_display(self):
if self.page.session.get('training'):
self.training_mode.value = "TRAINING MODE"
else:
self.training_mode.value = ""
def update_user_display(self): def update_user_display(self):
user_display = None user_display = None
if self.page: if self.page:

View file

@ -680,7 +680,7 @@ class POSView(WuttaView):
ft.Row( ft.Row(
[ [
meta_button("ITEM", bgcolor='blue', on_click=self.item_click), meta_button("ITEM", bgcolor='blue', on_click=self.item_click),
meta_button("MGR", bgcolor='yellow', on_click=self.not_supported), meta_button("MGR", bgcolor='yellow', on_click=self.manager_click),
], ],
spacing=0, spacing=0,
), ),
@ -1019,7 +1019,9 @@ class POSView(WuttaView):
if not user: if not user:
user = self.get_current_user(session) user = self.get_current_user(session)
batch, created = handler.get_current_batch(user, create=create, return_created=True) training = bool(self.page.session.get('training'))
batch, created = handler.get_current_batch(user, training_mode=training,
create=create, return_created=True)
if created: if created:
self.page.session.set('txn_display', handler.get_screen_txn_display(batch)) self.page.session.set('txn_display', handler.get_screen_txn_display(batch))
@ -1027,6 +1029,12 @@ class POSView(WuttaView):
return batch return batch
def refresh_training(self):
if self.page.session.get('training'):
self.bgcolor = '#E4D97C'
else:
self.bgcolor = None
def did_mount(self): def did_mount(self):
session = self.app.make_session() session = self.app.make_session()
batch = self.get_current_batch(session, create=False) batch = self.get_current_batch(session, create=False)
@ -1038,6 +1046,8 @@ class POSView(WuttaView):
self.page.session.set('cust_display', None) self.page.session.set('cust_display', None)
self.informed_refresh() self.informed_refresh()
self.refresh_training()
# TODO: i think commit() was for when it auto-created the # TODO: i think commit() was for when it auto-created the
# batch, so that can go away now..right? # batch, so that can go away now..right?
#session.commit() #session.commit()
@ -1303,6 +1313,70 @@ class POSView(WuttaView):
dlg.open = True dlg.open = True
self.page.update() self.page.update()
def toggle_training_mode(self, user):
was_training = self.page.session.get('training')
now_training = not was_training
# TODO: hacky but works for now
if not self.config.production():
self.page.client_storage.set('training', now_training)
self.page.session.set('training', now_training)
self.refresh_training()
self.informed_refresh()
self.reset()
def manager_click(self, e):
def toggle_training(e):
dlg.open = False
self.page.update()
session = self.app.make_session()
batch = self.get_current_batch(session, create=False)
session.close()
if batch:
self.show_snackbar("TRANSACTION IN PROGRESS")
self.reset()
else:
# nb. do this just in case we must show login dialog
# cf. https://github.com/flet-dev/flet/issues/1670
time.sleep(0.1)
training = self.page.session.get('training')
toggle = "End" if training else "Start"
self.authorized_action('pos.toggle_training', self.toggle_training_mode,
message=f"{toggle} Training Mode")
def cancel(e):
dlg.open = False
self.reset()
font_size = 32
toggle = "End" if self.page.session.get('training') else "Start"
dlg = ft.AlertDialog(
title=ft.Text("Manager Menu"),
content=ft.Text("What would you like to do?", size=20),
actions=[
self.make_button(f"{toggle} Training",
font_size=font_size,
height=self.default_button_size,
width=self.default_button_size * 2.5,
bgcolor='purple',
on_click=toggle_training),
self.make_button("Cancel",
font_size=font_size,
height=self.default_button_size,
width=self.default_button_size * 2.5,
on_click=cancel),
])
self.page.dialog = dlg
dlg.open = True
self.page.update()
def nosale_click(self, e): def nosale_click(self, e):
session = self.app.make_session() session = self.app.make_session()
batch = self.get_current_batch(session, create=False) batch = self.get_current_batch(session, create=False)