Resolve Invoice Number Approved count Mismatches Actual Approved Visits#1155
Resolve Invoice Number Approved count Mismatches Actual Approved Visits#1155zandre-eng wants to merge 2 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThis change updates the invoice item generation logic to aggregate approved work items using a Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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 docstrings
🧪 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
Product Description
The "Number approved" column in the Line Items table on the Review Service Delivery Invoice page now matches the Total Amount calculation. Previously, when a single
CompletedWorkrepresented multiple approved visits for the same entity, the count under-reported the actual number of approved visits, causingNumber approved × Payment Unit Amountnot to equalTotal Amount. Network and Program Managers will now see arithmetically consistent line items.Technical Summary
Link to ticket here
This is a release path 1 feature — Improvements to existing features & quick wins
get_invoice_items()aggregated line items per(payment_unit, month_approved)and computedtotal_amount_local = Sum("saved_payment_accrued")butrecord_count = Count("id"). Sincesaved_payment_accrued = saved_approved_count × payment_unit.amountperCompletedWork, the totals were correct but the count counted rows instead of visits. ACompletedWorkis keyed by(opportunity_access, entity_id, payment_unit)and can carrysaved_approved_count > 1, so the two aggregates diverged whenever any record had more than one approved visit.record_countfromCount("id")toSum("saved_approved_count")incompleted_work.get_invoice_items. This makes the count algebraically consistent with the total:payment_unit.amount × Sum(saved_approved_count) == Sum(saved_payment_accrued).saved_approved_countandsaved_payment_accruedare written together inCompletedWorkUpdater._update_payment, so existing rows already have the right values.Safety Assurance
Safety story
Read-only query change on the invoice review page. No schema changes, no data writes, no migrations. The new aggregate uses an already-populated cached column (
saved_approved_count) that is written alongsidesaved_payment_accruedin the sameCompletedWorkUpdater._update_paymentcall, so the two are guaranteed to be in sync for any record that has gone through the recompute path. If a stale row existed withsaved_payment_accrued > 0butsaved_approved_count = 0, the displayed count would be lower than before — but that condition implies an inconsistent record that would already mis-display elsewhere; spot-checking production data is straightforward (WHERE saved_payment_accrued > 0 AND saved_approved_count = 0).The change is fully reversible — a one-line revert restores the prior behaviour.
Automated test coverage
TestUninvoicedVisitItems.test_number_approved_uses_saved_approved_count— regression test for the bug. TwoCompletedWorkrows in the same payment unit withsaved_approved_countof 2 and 1 must producenumber_approved = 3andtotal_amount_local = 3 × payment_unit.amount. This test fails on the prior implementation (assert 2 == 3) and passes after the fix.TestUninvoicedVisitItemstests (test_items_without_prior_invoice,test_items_with_prior_invoice, and_create_completed_work) to setsaved_approved_countalongsidesaved_payment_accrued, mirroring how the two fields are written together in production.QA Plan
QA will not be performed for this change. Below is the testing plan for reference:
CompletedWorkwithsaved_approved_count > 1, open the Review Service Delivery Invoice page.Total Amount / Payment Unit Amountexactly.saved_approved_count == 1for every record (the common case) are unchanged.Labels & Review