[ENG-342] fix cancel dispense order#3656
Conversation
📝 WalkthroughWalkthroughThe PR corrects a charge-item cancellation loop in ChangesDispense Order Cancellation and Status Management
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 bug in
Confidence Score: 3/5The one-line variable fix is correct, but the null guard in the same function remains incomplete and can crash mid-cancellation when a dispense has no charge item. The fix to care/emr/api/viewsets/inventory/dispense_order.py — the cancel loop's null guard needs to cover all four Important Files Changed
Reviews (1): Last reviewed commit: "fix cancel dispense order" | 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/api/viewsets/inventory/dispense_order.py`:
- Around line 39-42: The code guards dispense.charge_item only for
handle_charge_item_cancel but then dereferences dispense.charge_item
unconditionally (setting status and updated_by), which will crash if it's None;
update the logic in the relevant viewset method so that the lines referencing
dispense.charge_item.status and dispense.charge_item.updated_by are only
executed when dispense.charge_item is truthy (e.g., move those assignments into
the existing if block that calls handle_charge_item_cancel or add an explicit
null-check), ensuring handle_charge_item_cancel, setting
ChargeItemStatusOptions.aborted.value, and updating updated_by happen together
and are skipped when dispense.charge_item is None.
🪄 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: 70285006-aa84-4d1f-a26c-4644ae56c7c9
📒 Files selected for processing (2)
care/emr/api/viewsets/inventory/dispense_order.pycare/emr/tests/test_dispense_order_api.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3656 +/- ##
===========================================
+ Coverage 75.46% 75.54% +0.08%
===========================================
Files 479 479
Lines 22984 22984
Branches 2375 2375
===========================================
+ Hits 17344 17363 +19
+ Misses 5068 5050 -18
+ Partials 572 571 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Proposed Changes
Associated Issue
Merge Checklist
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
Bug Fixes
Tests