Add initial buttons, items list for main POS screen

savepoint
This commit is contained in:
Lance Edgar 2023-09-23 08:27:22 -05:00
parent a789bb3b14
commit c3c8ae7e94

View file

@ -37,12 +37,146 @@ class POSView(WuttaView):
def build_controls(self):
self.main_input = ft.TextField(on_submit=self.main_submit,
text_size=24,
text_style=ft.TextStyle(weight=ft.FontWeight.BOLD),
autofocus=True)
def make_text(*args, **kwargs):
kwargs['weight'] = ft.FontWeight.BOLD
kwargs['size'] = 20
return ft.Text(*args, **kwargs)
self.items = ft.ListView()
self.items_container = ft.Container(content=self.items,
padding=ft.padding.only(10, 0, 10, 0),
expand=1)
def tenkey_click(e):
value = e.control.content.value
if value == 'ENTER':
print('TODO: handle enter')
elif value == '': # backspace
if self.main_input.value:
self.main_input.value = self.main_input.value[:-1]
self.page.update()
elif value == '':
pass # TODO
elif value == '':
pass # TODO
else:
self.main_input.value = f"{self.main_input.value or ''}{value}"
self.page.update()
# TODO: should be configurable?
tenkey_button_size = 100
tenkey_font_size = 40
def tenkey_button(text, width=tenkey_button_size):
return ft.Container(content=ft.Text(text, size=tenkey_font_size,
weight=ft.FontWeight.BOLD),
height=tenkey_button_size,
width=width,
on_click=tenkey_click,
alignment=ft.alignment.center,
border=ft.border.all(1, 'black'),
border_radius=ft.border_radius.all(5),
bgcolor='green')
self.tenkey_menu = ft.Container(
content=ft.Column(
[
ft.Row(
[
tenkey_button("1"),
tenkey_button("2"),
tenkey_button("3"),
tenkey_button(""),
],
spacing=0,
),
ft.Row(
[
tenkey_button("4"),
tenkey_button("5"),
tenkey_button("6"),
tenkey_button(""),
],
spacing=0,
),
ft.Row(
[
tenkey_button("7"),
tenkey_button("8"),
tenkey_button("9"),
tenkey_button(""),
],
spacing=0,
),
ft.Row(
[
tenkey_button("0"),
tenkey_button("00"),
tenkey_button("ENTER", width=tenkey_button_size * 2),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
spacing=0,
),
],
spacing=0,
),
expand=0)
meta_button_height = tenkey_button_size
meta_button_width = meta_button_height * 2
meta_font_size = tenkey_font_size
def meta_button(text):
return ft.Container(content=ft.Text(text, size=meta_font_size,
weight=ft.FontWeight.BOLD),
height=meta_button_height,
width=meta_button_width,
# on_click=meta_click,
alignment=ft.alignment.center,
border=ft.border.all(1, 'black'),
border_radius=ft.border_radius.all(5),
bgcolor='orange')
self.meta_menu = ft.Container(
content=ft.Column(
[
ft.Row(
[
meta_button("MGR"),
meta_button("VOID"),
],
spacing=0,
),
ft.Row(
[
meta_button("ITEM"),
meta_button("CUST"),
],
spacing=0,
),
ft.Row(
[
meta_button("TODO"),
meta_button("TODO"),
],
spacing=0,
),
ft.Row(
[
meta_button("TODO"),
meta_button("TODO"),
],
spacing=0,
),
],
spacing=0,
),
expand=0)
return [
self.build_header(),
@ -57,46 +191,54 @@ class POSView(WuttaView):
ft.Row(),
ft.Row(
[ft.Text("TODO: need lots of things yet here...somewhere..")],
alignment=ft.MainAxisAlignment.CENTER,
),
ft.Row(
[ft.Text("TODO: for instance, items rang up might go here")],
),
ft.DataTable(
columns=[
ft.DataColumn(make_text("UPC")),
ft.DataColumn(make_text("Description")),
ft.DataColumn(make_text("Price"), numeric=True),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(make_text("0007430500132-1")),
ft.DataCell(make_text("Apple Cider Vinegar 32oz")),
ft.DataCell(make_text("$5.99")),
],
),
ft.DataRow(
cells=[
ft.DataCell(make_text("0007430500116-1")),
ft.DataCell(make_text("Apple Cider Vinegar 16oz")),
ft.DataCell(make_text("$3.59")),
],
),
[
self.items_container,
self.tenkey_menu,
self.meta_menu,
],
vertical_alignment=ft.CrossAxisAlignment.START,
),
]
def make_text(self, *args, **kwargs):
kwargs.setdefault('weight', ft.FontWeight.BOLD)
kwargs.setdefault('size', 24)
return ft.Text(*args, **kwargs)
def main_submit(self, e):
value = self.main_input.value.upper()
self.page.snack_bar = ft.SnackBar(ft.Text(f"submit: {value}", color='black',
weight=ft.FontWeight.BOLD),
bgcolor='yellow',
duration=1500)
self.page.snack_bar.open = True
value = self.main_input.value
session = self.app.make_session()
product = self.app.get_products_handler().locate_product_for_entry(session, value)
if product:
price = product.current_price or product.regular_price
pretty_price = self.app.render_currency(price.price)
self.items.controls.append(
ft.Container(
content=ft.Row(
[
ft.Row([
self.make_text(f"{product}"),
self.make_text(f"× 1 @ {pretty_price}", weight=None, italic=True),
]),
self.make_text(pretty_price),
],
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
),
border=ft.border.only(bottom=ft.border.BorderSide(1, 'gray')),
padding=ft.padding.only(0, 5, 0, 5)))
else:
self.page.snack_bar = ft.SnackBar(ft.Text(f"UNRECOGNIZED: {value}",
color='black',
weight=ft.FontWeight.BOLD),
bgcolor='yellow',
duration=1500)
self.page.snack_bar.open = True
session.close()
self.main_input.value = ""
self.main_input.focus()
self.page.update()