Fix wrong duplicate report total for foreign-currency transactions in a non-USD workspace#97041
Fix wrong duplicate report total for foreign-currency transactions in a non-USD workspace#97041MelvinBot wants to merge 1 commit into
Conversation
…nsactions When the workspace default currency is non-USD, duplicating a report created the duplicate in the policy currency while its copied transactions kept their own (e.g. USD) currency. The per-transaction total accumulation in getMoneyRequestInformation only runs when the transaction currency matches the report currency, so mismatched transactions were dropped and the duplicate's optimistic total (and reimbursable/non-reimbursable buckets read by the preview) stayed at 0, showing the wrong amount. Seed the optimistic report totals from the eligible transactions expressed in the report currency and apply them outside the currency-equality guard, for same-workspace duplicates whose source report currency matches the new report currency. Co-authored-by: Chavda Sachin <ChavdaSachin@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. |
|
Hey The only red check is PR Author Checklist / checklist, and it's failing for the expected reason on a MelvinBot-raised draft: Those are human-only sections that I'm not allowed to fill out or tick on your behalf, so I can't clear this check by pushing a commit. As the human co-author, you'll need to:
Every functional check is green:
So no code fix is needed here — the checklist just needs you to complete the human sections before this PR can go green. |
Explanation of Change
When the workspace default currency is non-USD, duplicating a report ("more" → "Duplicate report") produced a duplicate whose total was wrong (often
0) in both the report preview and the details page.Root cause:
duplicateReportpre-creates the new report in the policy's output currency, then copies each source transaction into it via the money-request flow. The optimistic total ingetMoneyRequestInformationis only accumulated inside theiouReport?.currency === currencyguard, which has no conversion branch. When a copied transaction's currency differs from the (non-USD) report currency — e.g. the CSV-imported USD transactions from the repro — it is silently dropped from the running total, so the duplicate'stotal(and thereimbursableTotal/nonReimbursableTotalbuckets the preview reads viagetMoneyRequestSpendBreakdown) stay at0.Fix:
duplicateReport, seed an optimistic snapshot of the report totals (total,reimbursableTotal,nonReimbursableTotal, and the matchingunheld*buckets) computed from the eligible transactions expressed in the report currency — using each transaction's own amount when its currency already matches the report, otherwise its storedconvertedAmount. Signs follow the expense-report convention (stored negative). This is gated to same-workspace duplicates whose source report currency matches the new report currency, which guaranteesconvertedAmountis valid; cross-currency duplicates are left for the server response to reconcile.getMoneyRequestInformation(MoneyRequestBuilder.ts), apply this optionalreportTotalsOverridesnapshot directly, outside the currency-equality guard, so mismatched-currency copies are no longer skipped. Only defined fields are applied, so a valid zero total is honored. The snapshot is threaded throughrequestMoney; all other flows are unaffected (they never pass it).These are optimistic values only — the server response remains the source of truth.
Fixed Issues
$ #94009
PROPOSAL: #94009 (comment)
Tests
// TODO: The human co-author must fill out the manual tests they ran before marking this PR as "ready for review".
Suggested manual test for the reviewer/co-author:
0/incorrect).Offline tests
QA Steps
// TODO: The human co-author must fill out the QA steps before marking this PR as "ready for review". These must be filled out, or the issue title must include "[No QA]."
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
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari