Repository navigation
Keep held expenses out of unheld totals when splitting offline - #105524
Conversation
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
|
@MelvinBot Same as the unheld totals: this is the last line that still reads |
|
🤖 Web test steps verification results: ✅ pass After splitting an unheld expense offline on a report that also has a held expense, the report total stayed at $30.00 (not doubled), and "Approve only" showed $10.00 (unheld only), both offline and after going back online. The PR's Tests section is still empty, so these steps come from the linked issue's repro plus the held-expense case this PR fixes. view run · no recording available |
Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
|
Done in fd30d9b. When the report total is overridden, the new formula gives the same result as the old Checks
|
|
@codex review |
|
@MelvinBot review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review at
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd30d9bd78
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| iouReport.unheldTotal += reportTotalChange; | ||
| if (reimbursable && newUnheldReimbursableTotal === undefined && isCurrencyMatching) { | ||
| iouReport.unheldReimbursableTotal = newReportTotal ? newReportTotal - (iouReport.unheldNonReimbursableTotal ?? 0) : previousUnheldReimbursableTotal - reportAmount; | ||
| iouReport.unheldReimbursableTotal = previousUnheldReimbursableTotal + reportTotalChange; |
There was a problem hiding this comment.
Keep held split deltas out of unheld totals
When the source expense itself is held and the user saves ordinary cash splits whose sum is below the original amount (which computeSplitSaveErrorMessage() permits), SplitTransactionUpdate.copyCommentsAndHoldState() carries that hold to every child while passing the changed report total here. Adding the resulting reportTotalChange to unheldTotal and unheldReimbursableTotal therefore changes the approvable amount even though the entire delta belongs to held expenses; for example, reducing a held $100 expense to $60 makes an initially zero unheld total become +$40. Skip this delta for held source transactions or pass a separately computed unheld-total change.
AGENTS.md reference: AGENTS.md:L96-L100
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@MelvinBot address #105524 (comment)
Splitting a held expense into a lower total shows a negative "Approve only" amount offline
A cash split can total less than the original (only an info warning). The hold is copied to every split (SplitTransactionUpdate.ts#L1414), so the whole change in the report total belongs to held spend. The builder still adds it to the unheld totals (MoneyRequestBuilder.ts#L1532-L1534).
Preconditions: workspace with approvals enabled, you are the report's approver, desktop web.
- Submit two expenses to the same report: $100 and $20
- Open the $100 expense > Hold > enter a reason
- Go offline
- Open the $100 expense > More > Split. Set the first split to $30, then the second to $30, and Save
- Open the report and click the Approve dropdown
Expected: "Approve only $20.00" and "Approve $80.00"
Actual: "Approve only -$20.00" and "Approve $80.00"
There was a problem hiding this comment.
Fixed in c90e0ef. When you split a held expense, its unheld totals now stay the same. In your example, "Approve only" stays at $20.00 instead of -$20.00.
- Why: each new split inherits the source expense's hold, so the whole change in the report total is held spend.
- Change: the split now passes
isReportTotalChangeOnHold: isCreationOfSplits && isTransactionOnHoldto the builder. With that flag set, the builder leavesunheldTotalandunheldReimbursableTotalalone.totalandreimbursableTotalstill move by the full change. - Test: I added a unit test for your case. It holds a $100 expense, adds a $20 unheld expense, and splits the $100 into $30 + $30 while offline. It expects a total of $80 and an unheld total of $20. It fails without the fix and passes with it.
- Checks: all 176 tests in
SplitTest.ts, lint, and typecheck pass.
I didn't confirm this in the web app. The test browser went blank before the first step, so none of your repro steps ran.
view run · no recording available
|
🤖 Web test steps verification results: ❌ fail One regression found: when you split a held expense offline into parts that add up to less than the original, "Approve only" shows a negative amount (-$40.00 instead of $50.00) until the app reconnects. Plain splits, splits of held expenses that keep the same sum, and non-reimbursable splits all keep the correct totals offline and online.
view run · no recording available |
When a held expense is split, every split inherits the hold, so the whole change in the report total is held spend. Skip the unheld totals in that case so 'Approve only' does not go negative when the splits total less than the original. Co-authored-by: mkhutornyi <mkhutornyi@users.noreply.github.com>
|
@MelvinBot review |
|
@codex review |
Review at
|
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@MelvinBot add QA steps below and mark this PR ready for review Case 1: "Approve only" includes held expenses after an offline split
Case 2: splitting a held expense into a lower total
Case 3: report with a $0.00 total
|
|
I added your three QA cases to the QA Steps section and marked this PR as ready for review. The Tests section still has the TODO placeholder. You may want to fill it in, or replace it with "Same as QA Steps", before the reviewer checklist runs. |
|
@mkhutornyi 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] |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safaricase1.movcase2.movcase3.mov |
|
While testing, I found bug happening on Bug: Editing splits offline to a lower total only applies the last split's change to the report total
Expected: total $80.00, "Approve $80.00" bug.mov |
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #104050 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
|
🤖 Web test steps verification results: ✅ pass I found no regressions in six new flows, each checked offline and online: a $0 report, a new expense added offline, splits into a lower total, a held non-reimbursable split, undoing a split, and a personal IOU. Earlier runs already covered the other split cases. In one case, the report view showed a wrong total ($70.00 instead of $50.00) for a moment and then corrected itself. I didn't confirm whether this PR causes it (see step 5).
view run · no recording available |
|
🚧 marcochavezf has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/marcochavezf in version: 9.5.31-0 🚀
|
|
No help site update needed — this PR fixes incorrect amounts after offline expense splits, restoring expected behavior without changing the documented workflow. |
|
🚀 Deployed to staging by https://github.com/marcochavezf in version: 9.5.31-0 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.5.31-4 🚀
Bundle Size Analysis (Sentry): |





























































Explanation of Change
When an expense is split,
SplitTransactionUpdatepasses the post-split report total to the money request builder asnewReportTotal. The builder copied that full total intounheldTotalandunheldReimbursableTotal. The full total also counts held expenses, so after an offline split every held expense was counted as unheld, and the Approve dropdown showed the whole report total for "Approve only".This PR changes the builder so that, when
newReportTotalis passed,unheldTotalandunheldReimbursableTotalmove by the change intotal(newReportTotal - previous total) instead of being overwritten with it. Held amounts stay out of the unheld totals. Without an override, the change is still-reportAmount, so the existing per-transaction behavior is unchanged.A unit test covers a report with one held expense and one unheld expense that is split while offline. It fails on
main(unheldTotalbecomes the full total) and passes with this change.Fixed Issues
$ #104050
PROPOSAL: #104050 (comment)
Tests
// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.
Offline tests
QA Steps
Case 1: "Approve only" includes held expenses after an offline split
Case 2: splitting a held expense into a lower total
Case 3: report with a $0.00 total
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)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.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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari