Fix TypeError: Decimal + float in cart_total computation
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 49s

ticket_total() returned float while total() returns Decimal, causing
a crash when summing cart totals. Standardise all total functions to
return Decimal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-21 09:36:22 +00:00
parent fd89426ed9
commit 28c10a3411
2 changed files with 8 additions and 5 deletions

View File

@@ -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))