feat: add minimum charge helper for final demo#10
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan Review Summary by QodoAdd minimum charge pricing helper function
WalkthroughsDescription• Adds minimum charge helper function for pricing validation • Ensures subtotal never falls below specified floor amount • Supports discount application with minimum charge constraint Diagramflowchart LR
A["Subtotal + Discount"] --> B["Apply Discount"]
B --> C["Enforce Minimum Charge Floor"]
C --> D["Calculate Total with Tax"]
File Changes1. demo_app.py
|
Code Review by Qodo
|
| ) -> float: | ||
| """Apply a discount before tax, but never reduce the subtotal below a floor.""" | ||
|
|
||
| adjusted_subtotal = max(subtotal - discount_amount, minimum_charge) |
There was a problem hiding this comment.
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.
| """Apply a discount before tax, but never reduce the subtotal below a floor.""" | ||
|
|
||
| adjusted_subtotal = max(subtotal - discount_amount, minimum_charge) | ||
| return calculate_total(adjusted_subtotal, sales_tax_rate=sales_tax_rate) |
There was a problem hiding this comment.
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.
| discount_amount: float, | ||
| minimum_charge: float = 0.0, | ||
| ) -> float: | ||
| """Apply a discount before tax, but never reduce the subtotal below a floor.""" |
There was a problem hiding this comment.
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.
| 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) | ||
| return calculate_total(adjusted_subtotal, sales_tax_rate=sales_tax_rate) |
There was a problem hiding this comment.
1. Missing input validation 🐞 Bug ≡ Correctness
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
### Issue description
`calculate_total_with_minimum_charge()` currently allows invalid negative inputs.
- `discount_amount < 0` makes the function *increase* the subtotal (`subtotal - (-x)`), leading to overcharging.
- `minimum_charge < 0` can produce negative subtotals/totals.
### Issue Context
`calculate_total_with_discount()` already treats negative discounts as an error, so the new helper should match that contract to avoid surprising callers.
### Fix Focus Areas
- demo_app.py[57-66]
- demo_app.py[23-31]
### Suggested change
Add guards similar to:
- `if discount_amount < 0: raise ValueError(...)`
- `if minimum_charge < 0: raise ValueError(...)`
Optionally consider validating `subtotal >= 0` if this module assumes non-negative subtotals elsewhere.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Adds a small pricing helper so we can validate the full github-pr-kb flow on the final extractor behavior with new review comments and new comment IDs.