-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add minimum charge helper for final demo #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,15 @@ def calculate_total_with_capped_percentage_discount( | |
| 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) | ||
|
|
||
|
|
||
| def calculate_total_with_minimum_charge( | ||
| subtotal: float, | ||
| sales_tax_rate: float, | ||
| discount_amount: float, | ||
| minimum_charge: float = 0.0, | ||
| ) -> float: | ||
| """Apply a discount before tax, but never reduce the subtotal below a floor.""" | ||
|
|
||
| adjusted_subtotal = max(subtotal - discount_amount, minimum_charge) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should validate minimum_charge here. If it is negative or greater than the subtotal, this helper can either produce negative pre-tax amounts or increase the charge instead of only enforcing a floor. |
||
| return calculate_total(adjusted_subtotal, sales_tax_rate=sales_tax_rate) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would normalize the floored subtotal here and then delegate to the existing discount helper so one path stays responsible for discount clamping rules instead of spreading pricing math across multiple helpers.
Comment on lines
+57
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Missing input validation calculate_total_with_minimum_charge accepts negative discount_amount and/or minimum_charge, which can silently increase the subtotal (negative discount) or allow negative totals (negative minimum_charge). This is inconsistent with calculate_total_with_discount, which rejects negative discounts, and can lead to incorrect financial charges. Agent Prompt
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document whether minimum_charge is a pre-tax subtotal floor or a final customer-facing total floor. That distinction affects pricing policy, invoicing, and refunds, so it should be explicit in the docstring.