diff --git a/wuttapos/views/pos.py b/wuttapos/views/pos.py index 32bed80..d8b130b 100644 --- a/wuttapos/views/pos.py +++ b/wuttapos/views/pos.py @@ -74,10 +74,9 @@ class POSView(WuttaView): handler = self.get_batch_handler() handler.set_customer(batch, customer) - key_field = self.app.get_customer_key_field() - customer_key = getattr(customer, key_field) + self.page.session.set('txn_display', handler.get_screen_txn_display(batch)) self.page.session.set('cust_uuid', customer.uuid) - self.page.session.set('cust_display', str(customer_key or '')) + self.page.session.set('cust_display', handler.get_screen_cust_display(customer=customer)) self.informed_refresh() self.page.snack_bar = ft.SnackBar(ft.Text(f"CUSTOMER SET: {customer}", @@ -685,16 +684,27 @@ class POSView(WuttaView): def did_mount(self): session = self.app.make_session() - batch = self.get_current_batch(session) - self.page.session.set('txn_display', batch.id_str) + batch = self.get_current_batch(session, create=False) + if batch: - self.items.controls.clear() - for row in batch.active_rows(): - self.add_row_item(row) + handler = self.get_batch_handler() + self.page.session.set('txn_display', handler.get_screen_txn_display(batch)) + self.page.session.set('cust_uuid', batch.customer_uuid) + self.page.session.set('cust_display', handler.get_screen_cust_display(batch=batch)) - self.items.scroll_to(offset=-1, duration=100) + self.items.controls.clear() + for row in batch.active_rows(): + self.add_row_item(row) + self.items.scroll_to(offset=-1, duration=100) - self.txn_total.value = self.app.render_currency(batch.sales_total) + self.txn_total.value = self.app.render_currency(batch.sales_total) + + else: + self.page.session.set('txn_display', None) + self.page.session.set('cust_uuid', None) + self.page.session.set('cust_display', None) + + self.informed_refresh() session.commit() session.close() @@ -747,16 +757,10 @@ class POSView(WuttaView): # void current batch handler.void_batch(batch, user) - session.flush() - self.clear_all() - - # make new batch - batch = handler.get_current_batch(user, create=True) - self.page.session.set('txn_display', batch.id_str) - session.commit() session.close() + self.clear_all() self.main_input.focus() self.page.update() @@ -805,17 +809,10 @@ class POSView(WuttaView): # tender / execute batch tender = e.control.content.value handler.tender_and_execute(batch, user, tender) - self.clear_all() - - # make new batch - batch = handler.get_current_batch(user, create=True) - self.page.session.set('txn_display', batch.id_str) - self.header.update_txn_display() - self.header.update() - session.commit() session.close() + self.clear_all() self.main_input.focus() self.page.update() @@ -840,7 +837,10 @@ class POSView(WuttaView): model = self.model user = session.get(model.User, self.page.session.get('user_uuid')) - batch = handler.get_current_batch(user) + batch, created = handler.get_current_batch(user, return_created=True) + if created: + self.page.session.set('txn_display', handler.get_screen_txn_display(batch)) + self.informed_refresh() kwargs = {} if self.set_quantity.data is not None: