mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-03 17:43:15 +00:00
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.
This commit is contained in:
parent
684c9aa8f6
commit
5c92957420
2 changed files with 18 additions and 2 deletions
|
|
@ -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}"
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue