2 Commits

Author SHA1 Message Date
David Rodenkirchen 1dd1e8a730 stupid shit 2026-05-09 16:19:20 +02:00
David Rodenkirchen b99d2e1944 enable optional receipt 2026-05-09 15:02:40 +02:00
3 changed files with 25 additions and 11 deletions
+11 -5
View File
@@ -1,10 +1,11 @@
import logging
from asyncio import sleep, create_task
from decimal import Decimal
from functools import partial
from typing import Optional, Callable
from rio import Column, Component, event, TextStyle, Text, Spacer, Revealer, ProgressCircle, ScrollContainer, Row, Popup, List, Rectangle, PointerEventListener, \
PointerEvent, TextInput, TextInputChangeEvent
PointerEvent, TextInput, TextInputChangeEvent, Color, Button, Checkbox, Switch
from src.ezgg_lan_manager import ConfigurationService, CateringService, AccountingService
from src.ezgg_lan_manager.components.CateringCartItem import CateringCartItem
@@ -26,6 +27,7 @@ class Cart(Component):
popup_message: str = ""
popup_is_shown: bool = False
popup_is_error: bool = True
print_receipt: bool = True
async def on_remove_item(self, list_id: int) -> None:
try:
@@ -62,7 +64,7 @@ class Cart(Component):
except KeyError:
items_with_amounts[item] = 1
try:
await self.session[CateringService].place_order(items_with_amounts, self.user_id, is_delivery=False)
await self.session[CateringService].place_order(items_with_amounts, self.user_id, is_delivery=False, print_receipt=self.print_receipt)
except CateringError as catering_error:
logger.error(catering_error)
if catering_error.error_type == CateringErrorType.INCLUDES_DISABLED_ITEM:
@@ -151,7 +153,7 @@ class NewPosOrderPage(Component):
user_id: Optional[int] = None
all_menu_items: Optional[list[CateringMenuItem]] = None
cart: List[CateringMenuItem] = List()
print_receipt: bool = True
@event.on_populate
async def on_populate(self) -> None:
@@ -203,8 +205,12 @@ class NewPosOrderPage(Component):
margin_bottom=0.5,
align_x=0.5
),
TextInput(text=self.bind().user_id_input_value, label="Nutzer ID", on_change=self.on_user_id_input_change, change_delay=1, margin_bottom=0.5, margin_left=5, margin_right=5),
Cart(cart=self.cart, user_id=self.user_id, clear_cb=self.clear_user_id_input)
Row(
TextInput(text=self.bind().user_id_input_value, label="Nutzer ID", on_change=self.on_user_id_input_change, change_delay=1, margin_bottom=0.5, margin_left=1, margin_right=1, min_width=20),
Text("Bon drucken?:", margin_right=0, margin_left=0, style=TextStyle(fill=self.session.theme.background_color)),
Switch(is_on=self.bind().print_receipt, margin_right=1)
),
Cart(cart=self.cart, user_id=self.user_id, clear_cb=self.clear_user_id_input, print_receipt=self.print_receipt)
)
) if is_team_member else Spacer()
@@ -22,6 +22,13 @@ class MatchInfo(Component):
opponent_2_seat: str = ""
winner: str = ""
def calculate_font_size(self, txt: str) -> float:
if len(txt) < 14:
return 0.9
elif len(txt) < 20:
return 0.7
return 0.6
def build(self) -> Component:
return Rectangle(
content=Column(
@@ -33,13 +40,13 @@ class MatchInfo(Component):
style=TextStyle(fill=self.session.theme.success_color if self.winner == self.opponent_1 else self.session.theme.background_color),
justify="left",
margin_right=0.6,
font_size=0.9
font_size=self.calculate_font_size(self.opponent_1)
),
Text(
text=f"({self.opponent_1_seat})" if self.opponent_1_seat else "Freilos",
style=TextStyle(fill=self.session.theme.background_color),
justify="left",
font_size=0.9
font_size=self.calculate_font_size(self.opponent_1)
)
),
Spacer(),
@@ -49,13 +56,13 @@ class MatchInfo(Component):
style=TextStyle(fill=self.session.theme.success_color if self.winner == self.opponent_2 else self.session.theme.background_color),
justify="right",
margin_right=0.6,
font_size=0.9
font_size=self.calculate_font_size(self.opponent_2)
),
Text(
text=f"({self.opponent_2_seat})" if self.opponent_2_seat else "Freilos",
style=TextStyle(fill=self.session.theme.background_color),
justify="right",
font_size=0.9
font_size=self.calculate_font_size(self.opponent_2)
)
),
margin=0.3
@@ -36,7 +36,7 @@ class CateringService:
# ORDERS
async def place_order(self, menu_items: CateringMenuItemsWithAmount, user_id: int,
is_delivery: bool = True) -> CateringOrder:
is_delivery: bool = True, print_receipt: bool = True) -> CateringOrder:
for menu_item in menu_items:
if menu_item.is_disabled:
raise CateringError("Order includes disabled items", CateringErrorType.INCLUDES_DISABLED_ITEM)
@@ -54,6 +54,7 @@ class CateringService:
await self._accounting_service.remove_balance(user_id, total_price, f"CATERING - {order.order_id}")
logger.info(
f"User '{order.customer.user_name}' (ID:{order.customer.user_id}) ordered from catering for {self._accounting_service.make_euro_string_from_decimal(total_price)}")
if print_receipt:
await self._receipt_printing_service.print_order(user, order)
# await self.cancel_order(order) # ToDo: Check if commented out before commit. Un-comment to auto-cancel every placed order
return order