enable optional receipt

This commit is contained in:
David Rodenkirchen
2026-05-09 15:02:40 +02:00
parent 3b16004f73
commit b99d2e1944
2 changed files with 14 additions and 7 deletions
+11 -5
View File
@@ -1,10 +1,11 @@
import logging import logging
from asyncio import sleep, create_task from asyncio import sleep, create_task
from decimal import Decimal from decimal import Decimal
from functools import partial
from typing import Optional, Callable from typing import Optional, Callable
from rio import Column, Component, event, TextStyle, Text, Spacer, Revealer, ProgressCircle, ScrollContainer, Row, Popup, List, Rectangle, PointerEventListener, \ 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 import ConfigurationService, CateringService, AccountingService
from src.ezgg_lan_manager.components.CateringCartItem import CateringCartItem from src.ezgg_lan_manager.components.CateringCartItem import CateringCartItem
@@ -26,6 +27,7 @@ class Cart(Component):
popup_message: str = "" popup_message: str = ""
popup_is_shown: bool = False popup_is_shown: bool = False
popup_is_error: bool = True popup_is_error: bool = True
print_receipt: bool = True
async def on_remove_item(self, list_id: int) -> None: async def on_remove_item(self, list_id: int) -> None:
try: try:
@@ -62,7 +64,7 @@ class Cart(Component):
except KeyError: except KeyError:
items_with_amounts[item] = 1 items_with_amounts[item] = 1
try: 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: except CateringError as catering_error:
logger.error(catering_error) logger.error(catering_error)
if catering_error.error_type == CateringErrorType.INCLUDES_DISABLED_ITEM: if catering_error.error_type == CateringErrorType.INCLUDES_DISABLED_ITEM:
@@ -151,7 +153,7 @@ class NewPosOrderPage(Component):
user_id: Optional[int] = None user_id: Optional[int] = None
all_menu_items: Optional[list[CateringMenuItem]] = None all_menu_items: Optional[list[CateringMenuItem]] = None
cart: List[CateringMenuItem] = List() cart: List[CateringMenuItem] = List()
print_receipt: bool = True
@event.on_populate @event.on_populate
async def on_populate(self) -> None: async def on_populate(self) -> None:
@@ -203,8 +205,12 @@ class NewPosOrderPage(Component):
margin_bottom=0.5, margin_bottom=0.5,
align_x=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), Row(
Cart(cart=self.cart, user_id=self.user_id, clear_cb=self.clear_user_id_input) 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() ) if is_team_member else Spacer()
@@ -36,7 +36,7 @@ class CateringService:
# ORDERS # ORDERS
async def place_order(self, menu_items: CateringMenuItemsWithAmount, user_id: int, 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: for menu_item in menu_items:
if menu_item.is_disabled: if menu_item.is_disabled:
raise CateringError("Order includes disabled items", CateringErrorType.INCLUDES_DISABLED_ITEM) 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}") await self._accounting_service.remove_balance(user_id, total_price, f"CATERING - {order.order_id}")
logger.info( 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)}") 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._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 # await self.cancel_order(order) # ToDo: Check if commented out before commit. Un-comment to auto-cancel every placed order
return order return order