fix: zero amount/factor on monetary components incorrectly rejected as missing#3699
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaces truthiness checks with explicit ChangesZero-value amount/factor fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a Python truthiness bug where
Confidence Score: 5/5All three changed code paths are narrow, well-understood boolean-guard corrections with no side effects beyond the intended fix. The change is a targeted swap of truthy checks for No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "test: add factor=0 regression coverage p..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@care/emr/tests/test_charge_item_api.py`:
- Around line 1986-1997: The test `test_factor_based_components_still_work` only
covers a non-zero tax factor, so it misses the regression path where `factor=0`
broke. Update the `test_factor_based_components_still_work` coverage in
`test_charge_item_api.py` by adding a zero-factor case around
`sync_charge_item_costs` and asserting the expected `charge_item.total_price`
for that scenario, using the existing `_build_charge_item` helper and the same
monetary component structure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 78cd3c81-1030-4727-875c-f5092cb85e22
📒 Files selected for processing (3)
care/emr/resources/charge_item/sync_charge_item_costs.pycare/emr/resources/common/monetary_component.pycare/emr/tests/test_charge_item_api.py
|
@greptile-apps[bot] Confirmed! Added the regression test for |
|
Hey @vigneshhari, could you please take a look at this when you get a chance? Reviewed by both CodeRabbit and Greptile and came back clean. Could you please review the changes i made. |
Proposed Changes
amountorfactorof exactly0were incorrectly rejected as if neither value were present.calculate_amount()incare/emr/resources/charge_item/sync_charge_item_costs.py, and thecheck_amount_and_factor/check_amount_or_factorvalidators onMonetaryComponentincare/emr/resources/common/monetary_component.py, used truthy checks (if component.amount:,if component.factor:) onDecimalfields.Decimal("0")is falsy in Python, so a zero-value component was treated as missing, incorrectly raising"Either 'amount' or 'factor' must be present."/"Amount or factor is required"even though zero is a valid, schema-allowed value (nogt=0constraint exists on either field).amount: 0rather than omitted, or a0%/0-value surcharge kept for auditability — would crash charge item creation entirely.is not Nonechecks, consistent with howamountwas already checked correctly elsewhere in the same file (e.g.check_tax_included_amount_and_amount).amountandfactorstill correctly raises.Associated Issue
Merge Checklist
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
0amounts/factors as valid (instead of interpreting them as missing).Tests
amountand zerofactorscenarios, and for validation errors when both are missing.