From 875519d215e392734541465255c859496d708859 Mon Sep 17 00:00:00 2001 From: Gal Ziv Date: Sat, 11 Apr 2026 10:07:52 +0300 Subject: [PATCH] feat: add capped percentage discount helper for demo review Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- demo_app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/demo_app.py b/demo_app.py index 3c15001..21c3dd5 100644 --- a/demo_app.py +++ b/demo_app.py @@ -39,3 +39,16 @@ def calculate_total_with_percentage_discount( discounted_subtotal = subtotal * (1 - discount_rate) return calculate_total(discounted_subtotal, sales_tax_rate=sales_tax_rate) + + +def calculate_total_with_capped_percentage_discount( + subtotal: float, + sales_tax_rate: float, + discount_rate: float, + max_discount_amount: float, +) -> float: + """Apply a percentage discount before tax, capped by an absolute amount.""" + + discount_amount = min(subtotal * discount_rate, max_discount_amount) + discounted_subtotal = subtotal - discount_amount + return calculate_total(discounted_subtotal, sales_tax_rate=sales_tax_rate)