Skip to content

Commit 4acb25b

Browse files
authored
Merge pull request Expensify#89124 from Expensify/claude-fixCrossCurrencyOfflineTotals
Clear stale converted amounts when moving cross-currency expenses from Self DM
2 parents 0ee8d7b + c191bcc commit 4acb25b

3 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,16 @@ function getCurrency(transaction: OnyxInputOrEntry<Transaction>): string {
10421042
* Transactions that match the destination currency can keep their convertedAmount since no conversion is needed.
10431043
*/
10441044
function shouldClearConvertedAmount(transaction: OnyxInputOrEntry<Transaction>, sourceCurrency: string | undefined, destinationCurrency: string | undefined): boolean {
1045-
if (!sourceCurrency || !destinationCurrency || sourceCurrency === destinationCurrency) {
1045+
if (!destinationCurrency) {
10461046
return false;
10471047
}
10481048

10491049
const transactionCurrency = getCurrency(transaction);
1050-
const transactionMatchesDestination = transactionCurrency === destinationCurrency;
1050+
// sourceCurrency is undefined for unreported expenses (e.g. Self DM) since there's no source report.
1051+
// Fall back to the transaction's own currency so cross-currency detection still works.
1052+
const effectiveSourceCurrency = sourceCurrency ?? transactionCurrency;
10511053

1052-
return !transactionMatchesDestination;
1054+
return effectiveSourceCurrency !== destinationCurrency && transactionCurrency !== destinationCurrency;
10531055
}
10541056

10551057
/**

src/libs/actions/Transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ function changeTransactionsReport({
10891089
originalCurrency: shouldCopyOriginalCurrency ? transaction.originalCurrency : null,
10901090
...(shouldClearAmount && {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}),
10911091
...(shouldClearAmount && {convertedAmount: null}),
1092+
...(shouldClearAmount && {convertedTaxAmount: null}),
10921093
...(oldIOUAction ? {linkedTrackedExpenseReportAction: newIOUAction} : {}),
10931094
},
10941095
});
@@ -1112,6 +1113,7 @@ function changeTransactionsReport({
11121113
originalCurrency: transaction.originalCurrency,
11131114
...(shouldClearAmount && {pendingAction: transaction.pendingAction ?? null}),
11141115
...(shouldClearAmount && {convertedAmount: transaction.convertedAmount}),
1116+
...(shouldClearAmount && {convertedTaxAmount: transaction.convertedTaxAmount}),
11151117
},
11161118
});
11171119

tests/unit/TransactionUtilsTest.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,4 +2930,36 @@ describe('TransactionUtils', () => {
29302930
expect(TransactionUtils.getExchangeRate(transaction)).toBe('1.25 USD/EUR');
29312931
});
29322932
});
2933+
2934+
describe('shouldClearConvertedAmount', () => {
2935+
it('returns false when destinationCurrency is undefined', () => {
2936+
const transaction = generateTransaction({currency: 'USD'});
2937+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'EUR', undefined)).toBe(false);
2938+
});
2939+
2940+
it('returns false when sourceCurrency equals destinationCurrency', () => {
2941+
const transaction = generateTransaction({currency: 'USD'});
2942+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'EUR', 'EUR')).toBe(false);
2943+
});
2944+
2945+
it('returns false when transactionCurrency equals destinationCurrency', () => {
2946+
const transaction = generateTransaction({currency: 'EUR'});
2947+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'USD', 'EUR')).toBe(false);
2948+
});
2949+
2950+
it('returns true when both sourceCurrency and transactionCurrency differ from destinationCurrency', () => {
2951+
const transaction = generateTransaction({currency: 'GBP'});
2952+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, 'USD', 'EUR')).toBe(true);
2953+
});
2954+
2955+
it('falls back to transactionCurrency when sourceCurrency is undefined and currencies differ', () => {
2956+
const transaction = generateTransaction({currency: 'GBP'});
2957+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, undefined, 'EUR')).toBe(true);
2958+
});
2959+
2960+
it('returns false when sourceCurrency is undefined and transactionCurrency matches destinationCurrency', () => {
2961+
const transaction = generateTransaction({currency: 'EUR'});
2962+
expect(TransactionUtils.shouldClearConvertedAmount(transaction, undefined, 'EUR')).toBe(false);
2963+
});
2964+
});
29332965
});

0 commit comments

Comments
 (0)