From 0e5ad257c8981ce34b07a90762c0a7de468e47c9 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 19 Oct 2023 20:53:07 -0500 Subject: [PATCH] Add basic support for training mode make it obvious when in effect, mark batches accordingly etc. --- wuttapos/app.py | 4 ++ wuttapos/controls/header.py | 53 +++++++++++++++++-------- wuttapos/views/pos.py | 78 ++++++++++++++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 19 deletions(-) diff --git a/wuttapos/app.py b/wuttapos/app.py index 9c4ed5c..876e539 100644 --- a/wuttapos/app.py +++ b/wuttapos/app.py @@ -234,6 +234,10 @@ def main(page: ft.Page): # TODO: this may be too hacky but is useful for now/dev if not config.production(): + + training = page.client_storage.get('training') + page.session.set('training', training) + user = None uuid = page.client_storage.get('user_uuid') if uuid: diff --git a/wuttapos/controls/header.py b/wuttapos/controls/header.py index b2641e1..74e3918 100644 --- a/wuttapos/controls/header.py +++ b/wuttapos/controls/header.py @@ -43,28 +43,40 @@ class WuttaHeader(WuttaControl): def build(self): 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.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.logout_button = ft.OutlinedButton("Logout", on_click=self.logout_click, visible=False) self.logout_divider = ft.VerticalDivider(visible=False) self.title_button = ft.FilledButton(self.app.get_title(), on_click=self.title_click) - controls = [ - self.txn_display, - ft.VerticalDivider(), - self.cust_display, - ft.VerticalDivider(), - WuttaTimestamp(self.config, expand=True, - weight=ft.FontWeight.BOLD, size=20), - self.user_display, - ft.VerticalDivider(), - self.logout_button, - self.logout_divider, - ft.Text(f"Term: {self.term_display}", weight=ft.FontWeight.BOLD, size=20), - ft.VerticalDivider(), - self.title_button, - ] - - return ft.Row(controls) + return ft.Row( + [ + ft.Row( + [ + self.txn_display, + ft.VerticalDivider(), + self.cust_display, + ft.VerticalDivider(), + WuttaTimestamp(self.config, weight=ft.FontWeight.BOLD, size=20), + ], + ), + self.training_mode, + ft.Row( + [ + self.user_display, + ft.VerticalDivider(), + self.logout_button, + self.logout_divider, + ft.Text(f"Term: {self.term_display}", weight=ft.FontWeight.BOLD, size=20), + ft.VerticalDivider(), + self.title_button, + ], + ), + ], + alignment=ft.MainAxisAlignment.SPACE_BETWEEN, + ) def did_mount(self): self.informed_refresh() @@ -73,6 +85,7 @@ class WuttaHeader(WuttaControl): self.update_txn_display() self.update_cust_display() self.update_user_display() + self.update_training_display() self.update() def update_txn_display(self): @@ -87,6 +100,12 @@ class WuttaHeader(WuttaControl): cust_display = self.page.session.get('cust_display') 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): user_display = None if self.page: diff --git a/wuttapos/views/pos.py b/wuttapos/views/pos.py index 467dc1a..a204353 100644 --- a/wuttapos/views/pos.py +++ b/wuttapos/views/pos.py @@ -680,7 +680,7 @@ class POSView(WuttaView): ft.Row( [ 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, ), @@ -1019,7 +1019,9 @@ class POSView(WuttaView): if not user: 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: self.page.session.set('txn_display', handler.get_screen_txn_display(batch)) @@ -1027,6 +1029,12 @@ class POSView(WuttaView): return batch + def refresh_training(self): + if self.page.session.get('training'): + self.bgcolor = '#E4D97C' + else: + self.bgcolor = None + def did_mount(self): session = self.app.make_session() batch = self.get_current_batch(session, create=False) @@ -1038,6 +1046,8 @@ class POSView(WuttaView): self.page.session.set('cust_display', None) self.informed_refresh() + self.refresh_training() + # TODO: i think commit() was for when it auto-created the # batch, so that can go away now..right? #session.commit() @@ -1303,6 +1313,70 @@ class POSView(WuttaView): dlg.open = True 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): session = self.app.make_session() batch = self.get_current_batch(session, create=False)