Display tax info per line, and totals

This commit is contained in:
Lance Edgar 2023-10-07 16:32:26 -05:00
parent d15f521679
commit fb4206e5a9
2 changed files with 65 additions and 11 deletions

View file

@ -65,6 +65,8 @@ class WuttaTxnItem(WuttaControl):
self.sales_total = ft.TextSpan(style=self.sales_total_style) self.sales_total = ft.TextSpan(style=self.sales_total_style)
self.tax_flag = ft.TextSpan(style=self.major_style)
# set initial text display values # set initial text display values
self.refresh(update=False) self.refresh(update=False)
@ -83,6 +85,8 @@ class WuttaTxnItem(WuttaControl):
ft.Text( ft.Text(
spans=[ spans=[
self.sales_total, self.sales_total,
ft.TextSpan(" "),
self.tax_flag,
], ],
), ),
@ -115,11 +119,13 @@ class WuttaTxnItem(WuttaControl):
if self.row.void: if self.row.void:
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
self.major_style.weight = None
self.minor_style.color = 'red' self.minor_style.color = 'red'
self.minor_style.decoration = ft.TextDecoration.LINE_THROUGH self.minor_style.decoration = ft.TextDecoration.LINE_THROUGH
else: else:
self.major_style.color = None self.major_style.color = None
self.major_style.decoration = None self.major_style.decoration = None
self.major_style.weight = ft.FontWeight.BOLD
self.minor_style.color = None self.minor_style.color = None
self.minor_style.decoration = None self.minor_style.decoration = None
@ -127,16 +133,19 @@ class WuttaTxnItem(WuttaControl):
self.quantity.text = self.app.render_quantity(self.row.quantity) self.quantity.text = self.app.render_quantity(self.row.quantity)
self.txn_price.text = self.app.render_currency(self.row.txn_price) self.txn_price.text = self.app.render_currency(self.row.txn_price)
self.sales_total.text = self.app.render_currency(self.row.sales_total) self.sales_total.text = self.app.render_currency(self.row.sales_total)
self.tax_flag.text = f"T{self.row.tax_code}" if self.row.tax_code else ""
if self.row.void: if self.row.void:
self.sales_total_style.color = 'red' self.sales_total_style.color = 'red'
self.sales_total_style.decoration = ft.TextDecoration.LINE_THROUGH self.sales_total_style.decoration = ft.TextDecoration.LINE_THROUGH
self.sales_total_style.weight = None
else: else:
if self.row.txn_price < self.row.reg_price: if self.row.txn_price < self.row.reg_price:
self.sales_total_style.color = 'green' self.sales_total_style.color = 'blue'
else: else:
self.sales_total_style.color = None self.sales_total_style.color = None
self.sales_total_style.decoration = None self.sales_total_style.decoration = None
self.sales_total_style.weight = ft.FontWeight.BOLD
if update: if update:
self.update() self.update()

View file

@ -98,6 +98,7 @@ class POSView(WuttaView):
self.page.session.set('cust_uuid', customer.uuid) self.page.session.set('cust_uuid', customer.uuid)
self.page.session.set('cust_display', handler.get_screen_cust_display(customer=customer)) self.page.session.set('cust_display', handler.get_screen_cust_display(customer=customer))
self.informed_refresh() self.informed_refresh()
self.refresh_totals( batch)
self.show_snackbar(f"CUSTOMER SET: {customer}", bgcolor='green') self.show_snackbar(f"CUSTOMER SET: {customer}", bgcolor='green')
@ -111,6 +112,32 @@ class POSView(WuttaView):
else: else:
self.item_lookup() self.item_lookup()
def refresh_totals(self, batch):
reg = ft.TextStyle(size=22)
bold = ft.TextStyle(size=24, weight=ft.FontWeight.BOLD)
self.subtotals.spans.clear()
self.subtotals.spans.append(ft.TextSpan("Sales ", style=reg))
total = self.app.render_currency(batch.sales_total or 0)
self.subtotals.spans.append(ft.TextSpan(total, style=bold))
for btax in sorted(batch.taxes.values(),
key=lambda t: t.tax_code):
if btax.tax_total:
self.subtotals.spans.append(ft.TextSpan(f" Tax {btax.tax_code} ", style=reg))
total = self.app.render_currency(btax.tax_total)
self.subtotals.spans.append(ft.TextSpan(total, style=bold))
if batch.tender_total:
self.subtotals.spans.append(ft.TextSpan(f" Tend ", style=reg))
total = self.app.render_currency(batch.tender_total)
self.subtotals.spans.append(ft.TextSpan(total, style=bold))
self.txn_balance.value = self.app.render_currency(batch.get_balance() or 0)
self.totals_row.bgcolor = 'orange'
def attempt_add_product(self, uuid=None, record_badscan=False): def attempt_add_product(self, uuid=None, record_badscan=False):
session = self.app.make_session() session = self.app.make_session()
handler = self.get_batch_handler() handler = self.get_batch_handler()
@ -143,7 +170,7 @@ class POSView(WuttaView):
else: else:
self.add_row_item(row) self.add_row_item(row)
self.items.scroll_to(offset=-1, duration=100) self.items.scroll_to(offset=-1, duration=100)
self.txn_total.value = self.app.render_currency(batch.get_balance()) self.refresh_totals(batch)
self.reset() self.reset()
else: else:
@ -154,6 +181,7 @@ class POSView(WuttaView):
self.show_snackbar(f"PRODUCT NOT FOUND: {entry}", bgcolor='yellow') self.show_snackbar(f"PRODUCT NOT FOUND: {entry}", bgcolor='yellow')
session.commit() session.commit()
self.refresh_totals(batch)
session.close() session.close()
self.page.update() self.page.update()
return bool(row) return bool(row)
@ -547,15 +575,27 @@ class POSView(WuttaView):
height=800, height=800,
) )
self.txn_total = ft.Text("", size=40) self.subtotals = ft.Text(spans=[])
self.txn_balance = ft.Text("", size=40, weight=ft.FontWeight.BOLD)
self.totals_row = ft.Container(
ft.Row(
[
self.subtotals,
self.txn_balance,
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
),
padding=ft.padding.only(10, 0, 10, 0),
)
self.items_column = ft.Column( self.items_column = ft.Column(
controls=[ controls=[
ft.Container( ft.Container(
content=self.items, content=self.items,
padding=ft.padding.only(10, 0, 10, 0)), padding=ft.padding.only(10, 0, 10, 0)),
ft.Row([self.txn_total], self.totals_row,
alignment=ft.MainAxisAlignment.END),
], ],
expand=1, expand=1,
) )
@ -789,7 +829,7 @@ class POSView(WuttaView):
self.add_row_item(row) self.add_row_item(row)
self.items.scroll_to(offset=-1, duration=100) self.items.scroll_to(offset=-1, duration=100)
self.txn_total.value = self.app.render_currency(batch.get_balance()) self.refresh_totals(batch)
else: else:
self.page.session.set('txn_display', None) self.page.session.set('txn_display', None)
@ -866,7 +906,7 @@ class POSView(WuttaView):
# update screen to reflect new balance # update screen to reflect new balance
batch = row.batch batch = row.batch
self.txn_total.value = self.app.render_currency(batch.get_balance()) self.refresh_totals(batch)
# update item display # update item display
self.selected_item.data['row'] = row self.selected_item.data['row'] = row
@ -1094,6 +1134,7 @@ class POSView(WuttaView):
session = self.app.make_session() session = self.app.make_session()
handler = self.get_batch_handler() handler = self.get_batch_handler()
user = self.get_current_user(session) user = self.get_current_user(session)
batch = self.get_current_batch(session, user=user)
# void line # void line
row = self.selected_item.data['row'] row = self.selected_item.data['row']
@ -1116,7 +1157,7 @@ class POSView(WuttaView):
self.selected_item.content.row = row self.selected_item.content.row = row
self.selected_item.content.refresh() self.selected_item.content.refresh()
self.clear_item_selection() self.clear_item_selection()
self.txn_total.value = self.app.render_currency(row.batch.get_balance()) self.refresh_totals(batch)
session.close() session.close()
self.reset() self.reset()
@ -1235,7 +1276,7 @@ class POSView(WuttaView):
# update screen to reflect new items/balance # update screen to reflect new items/balance
for row in rows: for row in rows:
self.add_row_item(row) self.add_row_item(row)
self.txn_total.value = self.app.render_currency(batch.get_balance()) self.refresh_totals(batch)
# executed batch means txn was finalized # executed batch means txn was finalized
if batch.executed: if batch.executed:
@ -1249,7 +1290,7 @@ class POSView(WuttaView):
bs.open = False bs.open = False
bs.update() bs.update()
self.clear_all() self.clear_all()
self.page.update() self.reset()
bs = ft.BottomSheet( bs = ft.BottomSheet(
ft.Container( ft.Container(
@ -1305,7 +1346,11 @@ class POSView(WuttaView):
def clear_all(self): def clear_all(self):
self.items.controls.clear() self.items.controls.clear()
self.txn_total.value = None
self.subtotals.spans.clear()
self.txn_balance.value = None
self.totals_row.bgcolor = None
self.page.session.set('txn_display', None) self.page.session.set('txn_display', None)
self.page.session.set('cust_uuid', None) self.page.session.set('cust_uuid', None)
self.page.session.set('cust_display', None) self.page.session.set('cust_display', None)