diff --git a/app.py b/app.py index c714bdd..4084af0 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ from __future__ import annotations import path_setup # noqa: F401 # adds shared_lib to sys.path +from decimal import Decimal from pathlib import Path from quart import g, abort @@ -61,7 +62,7 @@ async def cart_context() -> dict: # Global counts for cart-mini (always global) cart_qty = sum(ci.quantity for ci in all_cart) if all_cart else 0 ctx["cart_count"] = cart_qty + len(all_cal) + len(all_tickets) - ctx["cart_total"] = (total(all_cart) or 0) + (calendar_total(all_cal) or 0) + (ticket_total(all_tickets) or 0) + ctx["cart_total"] = (total(all_cart) or Decimal(0)) + (calendar_total(all_cal) or Decimal(0)) + (ticket_total(all_tickets) or Decimal(0)) # Page-scoped data when viewing a page cart page_post = getattr(g, "page_post", None) diff --git a/bp/cart/services/calendar_cart.py b/bp/cart/services/calendar_cart.py index 82b5c86..febd778 100644 --- a/bp/cart/services/calendar_cart.py +++ b/bp/cart/services/calendar_cart.py @@ -1,5 +1,7 @@ from __future__ import annotations +from decimal import Decimal + from shared.services.registry import services from .identity import current_cart_identity @@ -17,12 +19,12 @@ async def get_calendar_cart_entries(session): ) -def calendar_total(entries) -> float: +def calendar_total(entries) -> Decimal: """ Total cost of pending calendar entries. """ return sum( - (e.cost or 0) + (Decimal(str(e.cost)) if e.cost else Decimal(0)) for e in entries if e.cost is not None ) @@ -38,6 +40,6 @@ async def get_ticket_cart_entries(session): ) -def ticket_total(tickets) -> float: +def ticket_total(tickets) -> Decimal: """Total cost of reserved tickets.""" - return sum(float(t.price or 0) for t in tickets) + return sum((Decimal(str(t.price)) if t.price else Decimal(0) for t in tickets), Decimal(0))