Fix Decimal precision issue
This commit is contained in:
parent
43ce42052e
commit
3655e8eb53
@ -28,7 +28,7 @@ CREATE TABLE `catering_menu_items` (
|
||||
`catering_menu_item_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(45) NOT NULL,
|
||||
`additional_info` varchar(300) DEFAULT '',
|
||||
`price` int(11) NOT NULL DEFAULT 0,
|
||||
`price` varchar(45) NOT NULL DEFAULT '0',
|
||||
`category` varchar(80) NOT NULL,
|
||||
`is_disabled` tinyint(4) DEFAULT 0,
|
||||
PRIMARY KEY (`catering_menu_item_id`)
|
||||
|
||||
@ -13,6 +13,7 @@ from src.ez_lan_manager.types.Seat import Seat
|
||||
|
||||
logger = logging.getLogger(__name__.split(".")[-1])
|
||||
|
||||
|
||||
class CateringOrderInfoPopup(Component):
|
||||
order: Optional[CateringOrder] = None
|
||||
close_cb: Optional[Callable] = None
|
||||
@ -30,7 +31,8 @@ class CateringOrderInfoPopup(Component):
|
||||
rows = []
|
||||
is_contrast_line = True
|
||||
for item, amount in self.order.items.items():
|
||||
style = TextStyle(fill=self.session.theme.secondary_color if is_contrast_line else self.session.theme.neutral_color)
|
||||
style = TextStyle(
|
||||
fill=self.session.theme.secondary_color if is_contrast_line else self.session.theme.neutral_color)
|
||||
is_contrast_line = not is_contrast_line
|
||||
rows.append(
|
||||
Row(
|
||||
@ -44,7 +46,8 @@ class CateringOrderInfoPopup(Component):
|
||||
Text(f"Bestellung {self.order.order_id}", style=TextStyle(font_size=1.2), margin_bottom=1),
|
||||
*rows,
|
||||
Spacer(),
|
||||
Row(Text("Gesamtpreis:"), Spacer(), Text(self.session[AccountingService].make_euro_string_from_int(self.order.price)))
|
||||
Row(Text("Gesamtpreis:"), Spacer(),
|
||||
Text(self.session[AccountingService].make_euro_string_from_decimal(self.order.price)))
|
||||
),
|
||||
margin=1,
|
||||
color=self.session.theme.hud_color,
|
||||
@ -56,11 +59,13 @@ class CateringOrderInfoPopup(Component):
|
||||
colorize_on_hover=False
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CateringOrderWithSeat:
|
||||
catering_order: CateringOrder
|
||||
seat: Optional[Seat]
|
||||
|
||||
|
||||
class ManageCateringPage(Component):
|
||||
all_orders: list[CateringOrderWithSeat] = field(default_factory=list)
|
||||
last_updated: Optional[datetime] = None
|
||||
@ -73,7 +78,6 @@ class ManageCateringPage(Component):
|
||||
self.all_orders = await self.populate_seating(await self.session[CateringService].get_orders())
|
||||
self.last_updated = datetime.now()
|
||||
|
||||
|
||||
@event.periodic(30)
|
||||
async def update_orders(self) -> None:
|
||||
polled_orders = await self.session[CateringService].get_orders()
|
||||
@ -88,12 +92,16 @@ class ManageCateringPage(Component):
|
||||
return result
|
||||
|
||||
def get_all_pending_orders(self) -> list[CateringOrderWithSeat]:
|
||||
filtered_list = list(filter(lambda o: o.catering_order.status != CateringOrderStatus.COMPLETED and o.catering_order.status != CateringOrderStatus.CANCELED, self.all_orders))
|
||||
filtered_list = list(filter(lambda
|
||||
o: o.catering_order.status != CateringOrderStatus.COMPLETED and o.catering_order.status != CateringOrderStatus.CANCELED,
|
||||
self.all_orders))
|
||||
sorted_list = sorted(filtered_list, key=lambda o: o.catering_order.order_date)
|
||||
return sorted_list
|
||||
|
||||
def get_all_completed_orders(self) -> list[CateringOrderWithSeat]:
|
||||
filtered_list = list(filter(lambda o: o.catering_order.status == CateringOrderStatus.COMPLETED or o.catering_order.status == CateringOrderStatus.CANCELED, self.all_orders))
|
||||
filtered_list = list(filter(lambda
|
||||
o: o.catering_order.status == CateringOrderStatus.COMPLETED or o.catering_order.status == CateringOrderStatus.CANCELED,
|
||||
self.all_orders))
|
||||
sorted_list = sorted(filtered_list, key=lambda o: o.catering_order.order_date)
|
||||
return sorted_list
|
||||
|
||||
@ -154,7 +162,8 @@ class ManageCateringPage(Component):
|
||||
margin_bottom=1,
|
||||
on_press=self.update_orders
|
||||
),
|
||||
*[CateringManagementOrderDisplay(v.catering_order, v.seat, self.order_clicked) for v in self.get_all_pending_orders()],
|
||||
*[CateringManagementOrderDisplay(v.catering_order, v.seat, self.order_clicked) for v in
|
||||
self.get_all_pending_orders()],
|
||||
)
|
||||
),
|
||||
MainViewContentBox(
|
||||
@ -169,7 +178,8 @@ class ManageCateringPage(Component):
|
||||
margin_bottom=0.2,
|
||||
align_x=0.5
|
||||
),
|
||||
*[CateringManagementOrderDisplay(v.catering_order, v.seat, self.order_clicked) for v in self.get_all_completed_orders()],
|
||||
*[CateringManagementOrderDisplay(v.catering_order, v.seat, self.order_clicked) for v in
|
||||
self.get_all_completed_orders()],
|
||||
)
|
||||
),
|
||||
Spacer()
|
||||
|
||||
@ -485,7 +485,7 @@ class DatabaseService:
|
||||
item_id=menu_item_raw[0],
|
||||
name=menu_item_raw[1],
|
||||
additional_info=menu_item_raw[2],
|
||||
price=menu_item_raw[3],
|
||||
price=Decimal(menu_item_raw[3]),
|
||||
category=CateringMenuItemCategory(menu_item_raw[4]),
|
||||
is_disabled=bool(menu_item_raw[5])
|
||||
))
|
||||
@ -515,7 +515,7 @@ class DatabaseService:
|
||||
item_id=raw_data[0],
|
||||
name=raw_data[1],
|
||||
additional_info=raw_data[2],
|
||||
price=raw_data[3],
|
||||
price=Decimal(raw_data[3]),
|
||||
category=CateringMenuItemCategory(raw_data[4]),
|
||||
is_disabled=bool(raw_data[5])
|
||||
)
|
||||
@ -707,7 +707,7 @@ class DatabaseService:
|
||||
item_id=order_catering_menu_item_raw[1],
|
||||
name=order_catering_menu_item_raw[4],
|
||||
additional_info=order_catering_menu_item_raw[5],
|
||||
price=order_catering_menu_item_raw[6],
|
||||
price=Decimal(order_catering_menu_item_raw[6]),
|
||||
category=CateringMenuItemCategory(order_catering_menu_item_raw[7]),
|
||||
is_disabled=bool(order_catering_menu_item_raw[8])
|
||||
)] = order_catering_menu_item_raw[2]
|
||||
|
||||
@ -18,6 +18,7 @@ class CateringOrderStatus(StrEnum):
|
||||
COMPLETED = "COMPLETED"
|
||||
CANCELED = "CANCELED"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CateringOrder:
|
||||
order_id: int
|
||||
@ -31,7 +32,7 @@ class CateringOrder:
|
||||
def price(self) -> Decimal:
|
||||
total = Decimal("0")
|
||||
for item, amount in self.items.items():
|
||||
total += (item.price * Decimal(amount))
|
||||
total += (item.price * amount)
|
||||
return total
|
||||
|
||||
@staticmethod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user