Show tender line items on screen; add "change back" alert

This commit is contained in:
Lance Edgar 2023-10-01 17:39:02 -05:00
parent 7a8dce69b3
commit 9268d939eb
4 changed files with 120 additions and 32 deletions

View file

@ -34,6 +34,7 @@ class WuttaControl(ft.UserControl):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.config = config self.config = config
self.app = config.get_app() self.app = config.get_app()
self.enum = self.app.enum
def informed_refresh(self, **kwargs): def informed_refresh(self, **kwargs):
pass pass

View file

@ -55,22 +55,26 @@ class WuttaTxnItem(WuttaControl):
italic=True, italic=True,
**kw) **kw)
if self.row.row_type == self.enum.POS_ROW_TYPE_SELL:
return self.build_item_sell()
elif self.row.row_type in (self.enum.POS_ROW_TYPE_TENDER,
self.enum.POS_ROW_TYPE_CHANGE_BACK):
return self.build_item_tender()
def build_item_sell(self):
quantity = self.app.render_quantity(self.row.quantity) quantity = self.app.render_quantity(self.row.quantity)
pretty_price = self.app.render_currency(self.row.txn_price) pretty_price = self.app.render_currency(self.row.txn_price)
return ft.Row( return ft.Row(
[ [
ft.Row([ ft.Text(
spans=[
ft.Text( ft.TextSpan(f"{self.row.description}",
spans=[ style=self.major_style),
ft.TextSpan(f"{self.row.description}", ft.TextSpan(f"× {quantity} @ {pretty_price}",
style=self.major_style), style=self.minor_style),
ft.TextSpan(f"× {quantity} @ {pretty_price}", ],
style=self.minor_style), ),
],
),
]),
ft.Text( ft.Text(
spans=[ spans=[
ft.TextSpan(self.app.render_currency(self.row.sales_total), ft.TextSpan(self.app.render_currency(self.row.sales_total),
@ -82,8 +86,31 @@ class WuttaTxnItem(WuttaControl):
alignment=ft.MainAxisAlignment.SPACE_BETWEEN, alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
) )
def build_item_tender(self):
return ft.Row(
[
ft.Text(
spans=[
ft.TextSpan(f"{self.row.description}",
style=self.major_style),
],
),
ft.Text(
spans=[
ft.TextSpan(self.app.render_currency(self.row.tender_total),
style=self.major_style),
],
),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
)
def mark_void(self): def mark_void(self):
# TODO: how to properly handle this restriction?
assert self.row.row_type == self.enum.POS_ROW_TYPE_SELL
self.major_style.color = 'red' self.major_style.color = 'red'
self.major_style.decoration = ft.TextDecoration.LINE_THROUGH self.major_style.decoration = ft.TextDecoration.LINE_THROUGH

View file

@ -31,7 +31,7 @@ from rattail.files import resource_path
import flet as ft import flet as ft
from wuttapos.controls.header import WuttaHeader from wuttapos.controls.header import WuttaHeader
from wuttapos.util import get_pos_batch_handler from wuttapos.util import get_pos_batch_handler, make_button
class WuttaView(ft.View): class WuttaView(ft.View):
@ -66,6 +66,9 @@ class WuttaView(ft.View):
def get_batch_handler(self): def get_batch_handler(self):
return get_pos_batch_handler(self.config) return get_pos_batch_handler(self.config)
def make_button(self, *args, **kwargs):
return make_button(*args, **kwargs)
def reset(self, *args, **kwargs): def reset(self, *args, **kwargs):
pass pass

View file

@ -917,7 +917,9 @@ class POSView(WuttaView):
def add_row_item(self, row): def add_row_item(self, row):
# TODO: row types ugh # TODO: row types ugh
if row.row_type not in ('sell',): if row.row_type not in (self.enum.POS_ROW_TYPE_SELL,
self.enum.POS_ROW_TYPE_TENDER,
self.enum.POS_ROW_TYPE_CHANGE_BACK):
return return
self.items.controls.append( self.items.controls.append(
@ -955,7 +957,28 @@ class POSView(WuttaView):
# void line # void line
row = self.selected_item.data['row'] row = self.selected_item.data['row']
if not row.void: if row.void:
# cannot void an already void line
self.page.snack_bar = ft.SnackBar(ft.Text("LINE ALREADY VOID",
color='black',
size=20,
weight=ft.FontWeight.BOLD),
bgcolor='yellow',
duration=1500)
self.page.snack_bar.open = True
elif row.row_type != self.enum.POS_ROW_TYPE_SELL:
# cannot void line unless of type 'sell'
self.page.snack_bar = ft.SnackBar(ft.Text("LINE DOES NOT ALLOW VOID",
color='black',
size=20,
weight=ft.FontWeight.BOLD),
bgcolor='yellow',
duration=1500)
self.page.snack_bar.open = True
else:
# okay, void the line
row = session.get(row.__class__, row.uuid) row = session.get(row.__class__, row.uuid)
handler.void_row(row, user) handler.void_row(row, user)
self.selected_item.data['row'] = row self.selected_item.data['row'] = row
@ -966,17 +989,6 @@ class POSView(WuttaView):
# update screen to reflect new balance # update screen to reflect new balance
self.txn_total.value = self.app.render_currency(batch.get_balance()) self.txn_total.value = self.app.render_currency(batch.get_balance())
else:
self.page.snack_bar = ft.SnackBar(ft.Text("LINE ALREADY VOID",
color='black',
size=20,
weight=ft.FontWeight.BOLD),
bgcolor='yellow',
duration=1500)
self.page.snack_bar.open = True
else: else:
# void txn # void txn
handler.void_batch(batch, user) handler.void_batch(batch, user)
@ -1147,13 +1159,58 @@ class POSView(WuttaView):
else: else:
session.commit() session.commit()
# TODO: maybe shouldn't clear screen so immediately? # update screen to reflect new items/balance
if batch.executed: for row in rows:
self.clear_all() self.add_row_item(row)
self.txn_total.value = self.app.render_currency(batch.get_balance())
else: # executed batch means txn was finalized
# update screen to reflect new balance if batch.executed:
self.txn_total.value = self.app.render_currency(batch.get_balance())
# look for "change back" row, if found then show alert
last_row = rows[-1]
if last_row.row_type == self.enum.POS_ROW_TYPE_CHANGE_BACK:
def close_bs(e):
# user dismissed the change back alert; clear screen
bs.open = False
bs.update()
self.clear_all()
self.page.update()
bs = ft.BottomSheet(
ft.Container(
ft.Column(
[
ft.Text("Change Back", size=24,
weight=ft.FontWeight.BOLD),
ft.Divider(),
ft.Text("Please give customer change back:",
size=20),
ft.Text(self.app.render_currency(last_row.tender_total),
size=32, weight=ft.FontWeight.BOLD),
ft.Container(
content=self.make_button("Dismiss", on_click=close_bs,
height=80, width=120),
alignment=ft.alignment.center,
expand=1,
),
],
),
bgcolor='green',
padding=20,
),
open=True,
dismissible=False,
)
# show change back alert
# nb. we do *not* clear screen yet
self.page.overlay.append(bs)
else:
# txn finalized but no change back; clear screen
self.clear_all()
finally: finally:
session.close() session.close()