Skip to content

fix: Clear convertedAmount when amount or currency is manually modified#83624

Open
DebuggingMax wants to merge 1 commit intoExpensify:mainfrom
DebuggingMax:fix-currency-conversion-export
Open

fix: Clear convertedAmount when amount or currency is manually modified#83624
DebuggingMax wants to merge 1 commit intoExpensify:mainfrom
DebuggingMax:fix-currency-conversion-export

Conversation

@DebuggingMax
Copy link

@DebuggingMax DebuggingMax commented Feb 26, 2026

Details

When a user manually edits an expense's amount or currency, the convertedAmount field was not being cleared. This caused incorrect currency conversion to be applied during report export.

Root Cause: The getUpdatedTransaction function in TransactionUtils sets modifiedAmount and modifiedCurrency when users edit expenses, but it did not clear convertedAmount. During export, the stale convertedAmount (calculated from the original currency/amount) would be used, leading to double conversion.

Example from the issue:

  • User has a $45 USD Expensify subscription
  • Credit card charged C$62.85 CAD
  • User manually enters C$62.85 as the expense amount
  • Before fix: Export shows C$85.63 (C$62.85 was treated as USD and re-converted to CAD)
  • After fix: Export correctly shows C$62.85

Fixed Issues

$ #83451
$ #83451

Tests

Added unit tests in TransactionUtilsTest.ts to verify:

  1. convertedAmount is cleared when currency is changed
  2. convertedAmount is cleared when amount is manually modified

Offline tests

N/A - This change affects local state management that is then sent to the server.

QA Steps

  1. Create an expense with a receipt that shows a different currency than manually entered
  2. Manually edit the amount and/or currency to match your credit card charge
  3. Export the report to CSV
  4. Before: Exported amount was incorrectly re-converted
  5. After: Exported amount matches the manually entered value

PR Author Checklist

  • I linked the GitHub issue this PR fixes in the Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
  • I added tests to verify changes
  • I followed the code conventions described in the Style Guide
  • I followed the guidelines for writing Good Component Structure in the Best Practices
  • I validated my changes against standard platform devices using the checklist below

Screenshots/Videos

Web

N/A - Logic change only, no UI changes

Mobile Web - Chrome

N/A - Logic change only, no UI changes

Mobile Web - Safari

N/A - Logic change only, no UI changes

Desktop

N/A - Logic change only, no UI changes

iOS

N/A - Logic change only, no UI changes

Android

N/A - Logic change only, no UI changes

When a user manually edits an expense's amount or currency, the convertedAmount
field was not being cleared. This caused incorrect currency conversion to be
applied during report export - the system would re-convert already manually
entered amounts.

For example, if a user manually entered C$62.85 (matching their credit card
charge), the export would incorrectly convert this again, resulting in C$85.63.

This fix clears convertedAmount when modifiedAmount or modifiedCurrency is set,
ensuring the server recalculates conversion if needed rather than using stale
data.

Fixes Expensify#83451
@DebuggingMax DebuggingMax requested review from a team as code owners February 26, 2026 21:01
@melvin-bot melvin-bot bot requested review from mananjadhav and removed request for a team February 26, 2026 21:01
@melvin-bot
Copy link

melvin-bot bot commented Feb 26, 2026

@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]

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77aa2bb68b

ℹ️ 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".

shouldStopSmartscan = true;
// Clear convertedAmount when amount is manually modified to prevent stale conversion data
// from being used during export (the server will recalculate if needed)
updatedTransaction.convertedAmount = undefined;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use null so convertedAmount is actually removed

getUpdatedTransaction() sets convertedAmount to undefined, but this object is later written with Onyx.METHOD.MERGE (src/libs/actions/IOU/index.ts, around the optimistic transaction merge), and this codebase explicitly treats undefined as a no-op for Onyx.merge (see comments in src/pages/workspace/companyCards/addNew/StatementCloseDateStep.tsx:33 and src/libs/actions/TravelInvoicing.ts:74). In the amount/currency edit flow, that means the stale convertedAmount value is preserved instead of cleared, so the export double-conversion issue this commit targets can still occur.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant