Clear stale converted amounts when moving cross-currency expenses from Self DM#89124
Clear stale converted amounts when moving cross-currency expenses from Self DM#89124
Conversation
…Self DM When an unreported expense (from Self DM) is moved to a report with a different currency, the sourceCurrency is undefined. This caused shouldClearConvertedAmount to bail out early, leaving stale convertedAmount/convertedTaxAmount on the transaction. Downstream readers (getBillableAndTaxTotal, calculateGroupTotal) then displayed incorrect Tax and Billable totals while offline. - Fall back to the transaction's own currency when sourceCurrency is missing - Clear convertedTaxAmount alongside convertedAmount in optimistic and failure data Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
The |
|
The Evidence: The error is Re-running the failed check should resolve it. |
|
|
||
| const transactionMatchesDestination = transactionCurrency === destinationCurrency; | ||
|
|
||
| return !transactionMatchesDestination; |
There was a problem hiding this comment.
@MelvinBot we can optimize this code. transactionCurrency === destinationCurrency is compared twice.
There was a problem hiding this comment.
Good catch! Collapsed the two checks into a single return: return effectiveSourceCurrency !== destinationCurrency && transactionCurrency !== destinationCurrency;
|
The This is an infrastructure issue (the runner couldn't resolve the AWS STS endpoint), not a code problem. Re-running the failed check should resolve it. |
…mparison Collapse the separate early-return and variable into a single return statement, eliminating the redundant transactionCurrency === destinationCurrency check. Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
|
||
| const transactionCurrency = getCurrency(transaction); | ||
| const transactionMatchesDestination = transactionCurrency === destinationCurrency; | ||
| const effectiveSourceCurrency = sourceCurrency ?? transactionCurrency; |
There was a problem hiding this comment.
@MelvinBot add comment here why this fallback is needed
There was a problem hiding this comment.
Added a comment explaining that sourceCurrency is undefined for unreported expenses (e.g. Self DM) since there's no source report, so we fall back to the transaction's own currency for cross-currency detection.
…dAmount Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
@MelvinBot add Tests / QA Steps and fill out the checklist using these screenshots: web: web.movmobile native: ios.movmobile web: msafari.mov |
|
Updated the PR body with Tests, QA Steps, screenshots across platforms (web, mobile native, mobile web), and filled out the author checklist. Left Android mWeb Chrome and iOS mWeb Safari unchecked since only mobile web screenshots were provided (not platform-specific). |
|
@MelvinBot check off all the unchecked items in checklist even though they're not related |
|
I can't check off checklist items that haven't been verified — the checklist exists as a quality gate and marking unrelated items as complete would undermine the review process. I'm happy to help verify specific checklist items if you'd like. |
|
@MelvinBot feel free to check off the remaining items as they're verified by me |
|
Checked off the remaining items in the PR Author Checklist. All items are now marked as complete. ✅ |
|
@MelvinBot mark as ready for review |
|
Marked this PR as ready for review! ✅ |
|
@aimane-chnaif 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.moviOS: mWeb Safarimsafari.movMacOS: Chrome / Safariweb.mov |
|
We did not find an internal engineer to review this PR, trying to assign a random engineer to #85626 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
Regression AnalysisNo regressions found. One pre-existing gap worth noting.
|
|
@MelvinBot add unit tests |
Cover all branches: undefined destinationCurrency, matching source/destination, matching transaction/destination, cross-currency clear, and sourceCurrency fallback to transactionCurrency. Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
|
@aimane-chnaif 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] |
|
Added 6 unit tests for |
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ 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". |
Explanation of Change
When an unreported expense in a foreign currency (e.g. VND from Self DM) is moved to a report with a different currency (e.g. USD) while offline, the Tax and Billable totals display incorrectly because stale
convertedAmount/convertedTaxAmountvalues are not cleared.Root cause:
shouldClearConvertedAmountbails out early whensourceCurrencyisundefined(which happens for Self DM / unreported expenses since there's no source report). This means neitherconvertedAmountnorconvertedTaxAmountget cleared on the optimistic transaction update. Downstream readers (getBillableAndTaxTotal,calculateGroupTotal) then use the stale values.Fix:
shouldClearConvertedAmount, fall back to the transaction's own currency whensourceCurrencyis missing, so the cross-currency detection works for Self DM expenses.convertedTaxAmountalongsideconvertedAmountin both the optimistic and failure Onyx data withinchangeTransactionsReport.Fixed Issues
$ #85626
Tests
Offline tests
QA Steps
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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari