From b99d2e19443c678e45245ce1cb427691077e894c Mon Sep 17 00:00:00 2001 From: David Rodenkirchen Date: Sat, 9 May 2026 15:02:40 +0200 Subject: [PATCH] enable optional receipt --- src/ezgg_lan_manager/pages/NewPosOrderPage.py | 16 +++++++++++----- src/ezgg_lan_manager/services/CateringService.py | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ezgg_lan_manager/pages/NewPosOrderPage.py b/src/ezgg_lan_manager/pages/NewPosOrderPage.py index abe0dd8..dda092f 100644 --- a/src/ezgg_lan_manager/pages/NewPosOrderPage.py +++ b/src/ezgg_lan_manager/pages/NewPosOrderPage.py @@ -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() diff --git a/src/ezgg_lan_manager/services/CateringService.py b/src/ezgg_lan_manager/services/CateringService.py index f35f58f..e8837a7 100644 --- a/src/ezgg_lan_manager/services/CateringService.py +++ b/src/ezgg_lan_manager/services/CateringService.py @@ -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,7 +54,8 @@ 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)}") - await self._receipt_printing_service.print_order(user, order) + 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