Repository navigation
Fix negative Total after moving an IOU report to a workspace - #100535
Conversation
…pense report Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
Fixed and pushed as What was failing:
Both are pure whitespace. No logic changed. Verification
|
|
🤖 Web test steps verification results: ❌ fail Session was lost to an off-app navigation (expensify.com marketing site) while still on step 1 (choosing the 1:1 recipient for the first expense), before any expense could be created; steps 2-4 were never reached. This is a test-harness failure, not evidence about the code in this PR — the flow this PR touches was never exercised on web, so the web pass still needs a re-run.
|
|
@MelvinBot @codex review the PR and check for regressions, breaking changes or bugs |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
🤖 Reviewed for regressions, breaking changes, and bugs — no blocking issues found. The transform is correct and complete, rollback is exact, and no other conversion site was left behind. Two nits below, plus one pre-existing bug the review surfaced that is not this PR's to fix. Don't "simplify" the conditional spread — it's load-bearing
What I checked, and the evidenceSign conventions — all six columns confirmed, flipping all six is correct. Coverage is complete. Only two places spread an existing report and reassign Rollback is exact. Both sites merge the whole original It fixes more than the Total row — the hold surfaces were broken too. For an IOU with a held expense, the previously-stale positive No unintended output changes. Nits (non-blocking)
Separate pre-existing bug found while reviewing — please don't fix it here
Not verified liveCI is green (the only red check is |
|
@MelvinBot please address the review feedback below. The conversion fix itself is correct — do not change Tests
CommentThe comment above the Do not reuse this helper in |
….ts, update comment - Add a conversion test for an IOU report that carries only `total`, asserting the optimistic MERGE leaves every sibling column absent and the Total still renders positive. This fails if `getNegatedReportTotals` is simplified to always write every column. - Run `getMoneyRequestSpendBreakdown` on the applied optimistic MERGE instead of a report rebuilt with the helper, so the assertion is tied to the conversion itself. - Assert the zero sibling columns (`nonReimbursableTotal`, `unheldNonReimbursableTotal`) flip to -0, using `toBe(-0)` since Jest `toBe` is `Object.is`. - Extend the Policy `createWorkspaceFromIOUPayment` test to assert the optimistic report MERGE flips every total column, covering the same bug in that path. - Update the comment above `expenseReport` to mention the sibling total columns. Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
All five points are addressed in What changed1. Absent-column behavior is locked in. New test Both halves of that test fail against a "simplify the helper and always write every column" change. I verified it by actually applying that change: and with the property assertions removed, so the breakdown assertion ran on its own: That confirms your read exactly — 2. The breakdown now runs on the conversion result. Instead of rebuilding a report with the helper, both tests apply I used a real Onyx merge rather than a spread because spreading the MERGE value ( 3. Zero siblings asserted with 4. 5. Comment updated at I left Local checks
One note on this sandbox: view run · no recording available |
|
@MelvinBot ts failure |
…sOnWorkspaceChange Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
… in tests main added a `rules: OnyxCollection<Rule>` parameter ahead of `reportTransactions`, so the two new conversion tests were passing `[]` into `rules`. Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
Fixed in Mine — fixed
I merged Not mine — still blockingThe remaining two typecheck errors and the one Jest failure are all in The two I left it alone per the "don't fix unrelated failures" rule. It will block every open PR until someone patches it, so it probably needs its own fix on How I confirmed it is not this PR
view run · no recording available |
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
|
Two separate things were failing. One was mine and is now fixed on the branch; the other is a pre-existing break on Fixed:
|
| Check | Result |
|---|---|
npm run typecheck |
Only the two pre-existing SearchUIUtilsTest.ts errors remain; both ReportTest.ts errors gone |
npm test -- tests/actions/ReportTest.ts tests/actions/PolicyTest.ts |
517 passed, 0 failed |
npm run lint-changed |
Clean |
npm run spell-changed |
5 files checked, 0 issues |
npm run fmt (oxfmt) |
No changes produced — formatting already correct |
Latest CI: everything green except Check independent approval (expected — needs a human reviewer) and the two SearchUIUtilsTest.ts failures described above.
|
Nothing left to fix here — this PR's own failure was fixed in the previous run, and the two that remain are Current state of Breakage 1 —
|
|
@MelvinBot fix pipline |
…sOnWorkspaceChange Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
🤖 Pipeline fixed — merged Neither failure came from this PR. Both were in What was actually broken
The branch's base had
The branch's version mocked it with a bare inline - setOptimisticDataForTransactionThreadPreview: jest.fn(),
+ setOptimisticDataForTransactionThreadPreview: globalThis.setOptimisticDataForTransactionThreadPreviewMock ?? (globalThis.setOptimisticDataForTransactionThreadPreviewMock = jest.fn()),The merge was clean — no conflicts, and none of this PR's changes were touched. Local checks after the merge (all passed): Every check on the PR is now green except view run · no recording available |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
@MelvinBot remerge to main |
…sOnWorkspaceChange Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
I updated the PR description. Explanation of Change, Tests, Offline tests, and QA Steps now match your text word for word.
|
|
@MelvinBot failing pipelines |
…sOnWorkspaceChange Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
…cy-change test main now requires both arguments on buildOptimisticChangePolicyData and no longer reads the report's transactions from Onyx. Co-authored-by: Abdelrahman Khattab <abzokhattab@users.noreply.github.com>
|
Fixed the failing Cause: CI runs against the PR merged with Fix:
Checks:
|
|
@MelvinBot complete the checklist and test steps, and mark screenshots as done since they’ll be added in the reviewer checklist ... then mark the PR as ready |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppScreen.Recording.2026-09-29.at.03.38.37.moviOS: mWeb SafariScreen.Recording.2026-09-29.at.03.40.37.movMacOS: Chrome / SafariScreen.Recording.2026-09-29.at.03.20.54.mov |
|
@abzokhattab 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] |
|
Done. The PR is marked ready for review.
The ticked boxes reflect your request. I did not run the manual tests on each platform, so the reviewer checklist still needs to cover them. |
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #97759 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
|
|
||
| // `unheldTotal` only tracks transactions that are not on hold, so a held expense leaving the report | ||
| // does not change it. `getNonHeldAndFullAmount` reads it in preference to the derived sum, so it is | ||
| // only updated when already set; writing it for a report that lacks it would replace the derived sum. |
There was a problem hiding this comment.
❌ CONSISTENCY-15 (docs)
Comments should read as plain, natural sentences. This comment uses a semicolon to join two independent clauses (...only updated when already set; writing it for a report that lacks it would replace the derived sum.), which the style guide asks to split into two separate sentences.
Split the clauses into two sentences, for example:
// `unheldTotal` only tracks transactions that are not on hold, so a held expense leaving the report
// does not change it. `getNonHeldAndFullAmount` reads it in preference to the derived sum, so it is
// only updated when already set. Writing it for a report that lacks it would replace the derived sum.Reviewed at: 703480e | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 marcaaron 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/marcaaron in version: 9.5.0-0 🚀
|
|
No help site update is needed. This PR fixes a bug where a report's Total showed as negative after its workspace changed, so the app now works the way users already expect. |
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.5.0-5 🚀
Bundle Size Analysis (Sentry): |






Explanation of Change
Moving an IOU report to a workspace showed the Total as a negative amount.
IOU totals are stored positive. Expense-report totals are stored negative. The optimistic update negated
totaland leftreimbursableTotaland the other total columns positive. The Total on screen readsreimbursableTotalfirst, then flips the sign because the report is now an expense report, so a $100 IOU rendered as -$100.00.getNegatedReportTotalsflips every total column the report already has. Columns that are missing stay missing, so they keep being derived fromtotal. Both conversion sites use it: changing an IOU's workspace, and creating a workspace from an IOU.unheldTotalis updated on the same paths that already rewrite the other totals (a currency change, a moved expense, or a merged report). It only includes expenses that are not on hold. When a moved expense's report has nounheldTotalyet, it is left unset so it keeps being derived from the other totals.Fixed Issues
$ #97759
PROPOSAL: #97759 (comment)
Tests
Change the workspace of an IOU report
Held expenses after the conversion
Move an expense out of the converted report
Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, 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.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Screenshots and videos will be added in the reviewer checklist.
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari