Repository navigation
Fix stale Pay total after offline partial approval of held expenses - #89478
mjasikowski merged 8 commits into
Conversation
…s to a new hold report When a user partially approves or pays an expense report offline, the held transactions are reassigned to a new hold report inside getReportFromHoldRequestsOnyxData, but the original report's total and nonReimbursableTotal fields were never updated. As a result, after the optimistic merge the original report still carried its pre-move total while hasHeldExpenses returned false, causing getTotalAmountForIOUReportPreviewButton to fall through to reimbursableSpend derived from the stale total and display the wrong Pay amount. This change updates the original iouReport's total and nonReimbursableTotal to the previously-stored unheld amounts whenever the utility actually moved any held transactions, and adds a matching failure rollback. Because both the approve and pay partial flows share this utility, both inherit the fix. unheldTotal is intentionally left unchanged — after the move, every remaining transaction is unheld, so the existing unheldTotal value already equals the new total.
…l-approve-offline-pay-total # Conflicts: # src/libs/actions/IOU/index.ts
…l-approve-offline-pay-total
…l-approve-offline-pay-total
|
@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
|
||
| const isApprovalEnabled = policy ? policy.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false; | ||
|
|
||
| // After the held transactions are reassigned to the new hold report, the original iouReport |
There was a problem hiding this comment.
@wildan-m Can we shorten this comment to make it more impactful and easy to digest?
There was a problem hiding this comment.
Done in 78ff4d0 — trimmed from 6 lines to 3 while keeping the why (offline consumers + why unheldTotal is left untouched).
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid-stale-total.mp4.mp4Android: mWeb Chromemweb-chrome-stale-total.mp4iOS: HybridAppios-stale-play.mp4iOS: mWeb Safarimweb-safari-stale-pay.movMacOS: Chrome / Safariweb-partial-total.mov |
|
Something's wrong with my flow when I approve the expense offline, it doesn't show the pay button. Still figuring out. ios-partial-total.mov |
|
@trjExpensify @mjasikowski Can one of you help trigger adhoc build this PR? |
|
🚧 @mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
🚧 @mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
…l-approve-offline-pay-total
|
@mananjadhav, I've merged latest |
|
I tested on a new account with the adhoc build and it seems to be working fine. |
mananjadhav
left a comment
There was a problem hiding this comment.
Thanks for the patience here. I was able to test this properly. Seems like an issue with my test account. Checklist here.
|
@mjasikowski looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
Not an emergency, was a second too quick for a test (which passed) |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @mjasikowski has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mjasikowski in version: 9.3.74-7 🚀
Bundle Size Analysis (Sentry): |
|
After reviewing the PR changes and the existing help site documentation, no help site changes are required. This PR fixes an internal bug where the Pay button displayed a stale total after offline partial approval of held expenses. The changes are entirely in the optimistic data layer ( The existing help site article
Since this is a bug fix that corrects the displayed amount to match what was already documented, no documentation updates are needed. |
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.3.74-7 🚀
|
Explanation of Change
When a workspace admin goes offline and approves the unheld portion of a money request report that mixes held and unheld expenses, the Pay button on the Money Request Report header keeps showing the original full-report total — letting the user pay the wrong (inflated) amount.
The Pay button label is computed in
getTotalAmountForIOUReportPreviewButton(src/libs/MoneyRequestReportUtils.ts). When the report no longer has held expenses, the function falls through toreimbursableSpendfromgetMoneyRequestSpendBreakdown, which is derived fromreport.totalandreport.nonReimbursableTotal.During partial approval,
approveMoneyRequestcallsgetReportFromHoldRequestsOnyxData(src/libs/actions/IOU/index.ts) to optimistically:reportIDto the new hold report.After those three optimistic updates, the original
iouReportonly contains the previously-unheld transactions, but itstotalandnonReimbursableTotalare never touched. Meanwhile,hasHeldExpenses(report)now returnsfalse(the held transactions have a differentreportID), sogetTotalAmountForIOUReportPreviewButtonskips thenonHeldAmountbranch and reads the still-stalereport.total.The fix extends
getReportFromHoldRequestsOnyxDataso its optimistic update keeps the original report self-consistent:optimisticDatathat setstotal←iouReport.unheldTotalandnonReimbursableTotal←iouReport.unheldNonReimbursableTotalon the original report. Guarded byholdTransactions.length > 0 && iouReport?.unheldTotal !== undefinedso degenerate calls behave exactly as before.unheldTotalis intentionally left unchanged — every transaction remaining on the original report is unheld, so it already equals the newtotal.failureDatathat restores the pre-updatetotalandnonReimbursableTotalif the API call fails. The keys do not overlap with the existing failure rollbacks inapproveMoneyRequest, so Onyx merges them cleanly.Because both
approveMoneyRequestandpayMoneyRequest(the partial-pay flow) go through the same utility, centralizing the fix here covers both flows automatically and protects any future caller that adds another "move held out" path.Fixed Issues
$ #83295
PROPOSAL: #83295 (comment)
Tests
Test data setup. The bug only reproduces against an
iouReportthat holds both held and unheld expenses while offline — the offline boundary keeps the optimistic data on the client where the stale total is observable. The fix touches optimistic data only; once the API reconciles, the server total is authoritative.Offline tests
Same as Tests, steps 5-10 above. The whole repro and fix surface lives in offline / optimistic-update territory, so the offline behavior is the change being verified.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Kapture.2026-05-05.at.23.32.29.mp4
Android: mWeb Chrome
Kapture.2026-05-05.at.22.53.55.mp4
iOS: Native
Kapture.2026-05-05.at.16.54.03.mp4
iOS: mWeb Safari
Kapture.2026-05-05.at.22.45.13.mp4
MacOS: Chrome / Safari
Kapture.2026-05-05.at.15.10.00.mp4