Fix TypeError: Decimal + float in cart_total computation
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 49s
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:
3
app.py
3
app.py
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import path_setup # noqa: F401 # adds shared_lib to sys.path
|
import path_setup # noqa: F401 # adds shared_lib to sys.path
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from quart import g, abort
|
from quart import g, abort
|
||||||
@@ -61,7 +62,7 @@ async def cart_context() -> dict:
|
|||||||
# Global counts for cart-mini (always global)
|
# Global counts for cart-mini (always global)
|
||||||
cart_qty = sum(ci.quantity for ci in all_cart) if all_cart else 0
|
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_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-scoped data when viewing a page cart
|
||||||
page_post = getattr(g, "page_post", None)
|
page_post = getattr(g, "page_post", None)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
from shared.services.registry import services
|
from shared.services.registry import services
|
||||||
from .identity import current_cart_identity
|
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.
|
Total cost of pending calendar entries.
|
||||||
"""
|
"""
|
||||||
return sum(
|
return sum(
|
||||||
(e.cost or 0)
|
(Decimal(str(e.cost)) if e.cost else Decimal(0))
|
||||||
for e in entries
|
for e in entries
|
||||||
if e.cost is not None
|
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."""
|
"""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))
|
||||||
|
|||||||
Reference in New Issue
Block a user