Skip to content

feat: add minimum charge helper for final demo#10

Merged
Galzi1 merged 1 commit into
mainfrom
demo/minimum-charge-helper
Apr 11, 2026
Merged

feat: add minimum charge helper for final demo#10
Galzi1 merged 1 commit into
mainfrom
demo/minimum-charge-helper

Conversation

@Galzi1

@Galzi1 Galzi1 commented Apr 11, 2026

Copy link
Copy Markdown
Owner

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.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@qodo-code-review

Copy link
Copy Markdown
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Add minimum charge pricing helper function

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Adds minimum charge helper function for pricing validation
• Ensures subtotal never falls below specified floor amount
• Supports discount application with minimum charge constraint
Diagram
flowchart LR
  A["Subtotal + Discount"] --> B["Apply Discount"]
  B --> C["Enforce Minimum Charge Floor"]
  C --> D["Calculate Total with Tax"]
Loading

Grey Divider

File Changes

1. demo_app.py ✨ Enhancement +12/-0

Add minimum charge pricing helper function

• Adds new calculate_total_with_minimum_charge() function
• Applies discount to subtotal with minimum charge floor constraint
• Returns final total including sales tax on adjusted subtotal
• Complements existing discount calculation functions

demo_app.py


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Apr 11, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2)   📘 Rule violations (0)   📎 Requirement gaps (0)   🎨 UX Issues (0)
🐞\ ≡ Correctness (2)

Grey Divider


Action required

1. Missing input validation 🐞
Description
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.
Code

demo_app.py[R57-66]

+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)
Evidence
The existing absolute-discount helper explicitly guards against negative discounts, but the new
helper performs subtraction directly with no validation, so a negative discount increases the
subtotal and gets taxed. Similarly, a negative minimum_charge can let adjusted_subtotal go negative
and then calculate_total will return a negative taxed total.

demo_app.py[23-31]
demo_app.py[57-66]
demo_app.py[8-21]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### 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



Remediation recommended

2. Minimum charge may surcharge 🐞
Description
If minimum_charge is greater than subtotal, adjusted_subtotal becomes minimum_charge even when
discount_amount is 0, which increases the charge despite the helper describing a discount flow. This
ambiguity can cause accidental overcharging unless the behavior is clarified or constrained.
Code

demo_app.py[R63-65]

+    """Apply a discount before tax, but never reduce the subtotal below a floor."""
+
+    adjusted_subtotal = max(subtotal - discount_amount, minimum_charge)
Evidence
The implementation uses max(subtotal - discount_amount, minimum_charge), which mathematically can
exceed the original subtotal when minimum_charge > subtotal. The docstring frames the helper as
applying a discount with a floor, which commonly implies it should not raise the pre-discount
subtotal.

demo_app.py[57-66]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`minimum_charge` currently acts as a hard floor on the post-discount subtotal, which can *increase* the subtotal if `minimum_charge > subtotal`.

### Issue Context
The function docstring describes applying a discount with a floor, but doesn’t explicitly state whether it is allowed to raise the charge above the original subtotal (i.e., a true “minimum order charge”).

### Fix Focus Areas
- demo_app.py[57-66]

### Options to fix
Pick one and make it explicit:
1) If surcharging is NOT intended: clamp/validate so it cannot exceed the original subtotal (e.g., raise if `minimum_charge > subtotal`, or compute `max(subtotal - discount_amount, min(minimum_charge, subtotal))`).
2) If surcharging IS intended: update the docstring/name to clearly state it enforces a minimum final pre-tax charge and may increase small subtotals.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread demo_app.py
) -> float:
"""Apply a discount before tax, but never reduce the subtotal below a floor."""

adjusted_subtotal = max(subtotal - discount_amount, minimum_charge)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The 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.

Comment thread demo_app.py
"""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)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The 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 thread demo_app.py
discount_amount: float,
minimum_charge: float = 0.0,
) -> float:
"""Apply a discount before tax, but never reduce the subtotal below a floor."""

Copy link
Copy Markdown
Owner Author

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.

@Galzi1 Galzi1 merged commit 0223826 into main Apr 11, 2026
Comment thread demo_app.py
Comment on lines +57 to +66
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant