From 5c929574205816b6aabbb21716b581107d269101 Mon Sep 17 00:00:00 2001 From: Adam Moussa Date: Thu, 3 Sep 2026 17:59:58 -0400 Subject: [PATCH] fix(meals): round checkcomponents amounts half-up Keep SQS deduction amounts on the same rounding path as submit_order so extra-precision totals cannot diverge by a cent. --- functions/aggregate_orders/handler.py | 6 ++++-- tests/test_aggregate_orders.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/functions/aggregate_orders/handler.py b/functions/aggregate_orders/handler.py index 97de085..7094328 100644 --- a/functions/aggregate_orders/handler.py +++ b/functions/aggregate_orders/handler.py @@ -5,7 +5,7 @@ import logging import os from collections import defaultdict from datetime import datetime -from decimal import Decimal +from decimal import Decimal, ROUND_HALF_UP from zoneinfo import ZoneInfo import boto3 @@ -101,7 +101,9 @@ def build_checkcomponents_payload(week: str, orders: list[dict]) -> dict: lines.append( { "employee_email": email, - "amount": format(amount.quantize(Decimal("0.01")), "f"), + "amount": format( + amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP), "f" + ), } ) week_token = week if str(week).upper().startswith("WEEK#") else f"WEEK#{week}" diff --git a/tests/test_aggregate_orders.py b/tests/test_aggregate_orders.py index 431d852..d11ab2e 100644 --- a/tests/test_aggregate_orders.py +++ b/tests/test_aggregate_orders.py @@ -558,6 +558,20 @@ class TestCheckcomponentsPayload: ) assert payload["week"] == "WEEK#2026-W20" + def test_rounds_amount_half_up(self, handler_module): + payload = handler_module.build_checkcomponents_payload( + "2026-W20", + [ + _make_order( + "Alice", + "alice@x.com", + [_make_item("Burger")], + total=Decimal("10.025"), + ) + ], + ) + assert payload["lines"][0]["amount"] == "10.03" + class TestCheckcomponentsSend: @patch("functions.aggregate_orders.handler.put_summary")