From 2de3297810a8a7862a01ad2535f01aa67744813c Mon Sep 17 00:00:00 2001 From: TaduJR Date: Wed, 14 Jan 2026 13:01:48 +0300 Subject: [PATCH 1/5] fix: Report - Total amount shown as '0,00' when splitting expense offline after currency change --- src/libs/actions/IOU/index.ts | 11 ++- tests/actions/IOUTest.ts | 150 ++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index c07865a07db4..5eef3423a0a3 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -3202,8 +3202,17 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma } if (isSplitExpense && existingTransaction) { - const {convertedAmount: omittedConvertedAmount, ...existingTransactionWithoutConvertedAmount} = existingTransaction; + const {convertedAmount: originalConvertedAmount, ...existingTransactionWithoutConvertedAmount} = existingTransaction; optimisticTransaction = fastMerge(existingTransactionWithoutConvertedAmount, optimisticTransaction, false); + + // Calculate proportional convertedAmount for the split based on the original conversion rate + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- modifiedAmount can be empty string + const originalAmount = existingTransaction.modifiedAmount || existingTransaction.amount; + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- modifiedAmount can be empty string + const splitAmount = optimisticTransaction.modifiedAmount || optimisticTransaction.amount; + if (originalConvertedAmount && originalAmount && splitAmount) { + optimisticTransaction.convertedAmount = Math.round((originalConvertedAmount * splitAmount) / originalAmount); + } } // STEP 4: Build optimistic reportActions. We need: diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 1d829ca82b25..25174b765af8 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3447,6 +3447,156 @@ describe('actions/IOU', () => { // Then the description should be the same since it was not changed expect(splitTransaction?.comment?.comment).toBe('

test

'); }); + + it('should calculate proportional convertedAmount for split transactions with foreign currency', async () => { + jest.setTimeout(10 * 1000); + + // Given: An expense report with AED currency and a USD transaction with convertedAmount + const originalAmount = -1000; + const originalConvertedAmount = -3673; + const reportID = rand64(); + const originalTransactionID = rand64(); + + const expenseReport: Report = { + reportID, + type: CONST.REPORT.TYPE.EXPENSE, + currency: 'AED', + ownerAccountID: RORY_ACCOUNT_ID, + total: originalAmount, + }; + + const originalTransaction: Transaction = { + transactionID: originalTransactionID, + amount: originalAmount, + modifiedAmount: '', // Empty string - the edge case that was causing the bug + currency: 'USD', + modifiedCurrency: '', + convertedAmount: originalConvertedAmount, + created: DateUtils.getDBTime(), + merchant: 'Test Merchant', + reportID, + comment: {}, + }; + + const transactionThread: Report = { + reportID: rand64(), + type: CONST.REPORT.TYPE.CHAT, + parentReportID: reportID, + parentReportActionID: rand64(), + }; + + const iouAction: ReportAction = { + ...buildOptimisticIOUReportAction({ + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + amount: Math.abs(originalAmount), + currency: 'USD', + comment: '', + participants: [], + transactionID: originalTransactionID, + iouReportID: reportID, + }), + childReportID: transactionThread.reportID, + }; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.reportID}`, transactionThread); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, { + [iouAction.reportActionID]: iouAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`, originalTransaction); + + const splitExpenses: SplitExpense[] = [ + { + transactionID: rand64(), + amount: -500, + created: DateUtils.getDBTime(), + merchant: 'Test Merchant', + }, + { + transactionID: rand64(), + amount: -500, + created: DateUtils.getDBTime(), + merchant: 'Test Merchant', + }, + ]; + + let allTransactions: OnyxCollection; + let allReports: OnyxCollection; + let allReportNameValuePairs: OnyxCollection; + await getOnyxData({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (value) => { + allTransactions = value; + }, + }); + await getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (value) => { + allReports = value; + }, + }); + await getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, + waitForCollectionCallback: true, + callback: (value) => { + allReportNameValuePairs = value; + }, + }); + + // When splitting the expense + updateSplitTransactionsFromSplitExpensesFlow({ + allTransactionsList: allTransactions, + allReportsList: allReports, + allReportNameValuePairsList: allReportNameValuePairs, + transactionData: { + reportID, + originalTransactionID, + splitExpenses, + splitExpensesTotal: -1000, + }, + searchContext: { + currentSearchHash: -1, + }, + policyCategories: undefined, + policy: undefined, + policyRecentlyUsedCategories: [], + iouReport: expenseReport, + firstIOU: iouAction, + isASAPSubmitBetaEnabled: false, + currentUserPersonalDetails, + transactionViolations: {}, + policyRecentlyUsedCurrencies: [], + quickAction: undefined, + }); + + await waitForBatchedUpdates(); + + // Then each split transaction should have proportional convertedAmount + // Formula: Math.round((originalConvertedAmount * splitAmount) / originalAmount) + const expectedProportionalConvertedAmount = -1836; + + const splitTransactions = await new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (transactions) => { + Onyx.disconnect(connection); + const splits = Object.values(transactions ?? {}).filter( + (t) => t?.transactionID !== originalTransactionID && t?.comment?.originalTransactionID === originalTransactionID, + ); + resolve(splits as Transaction[]); + }, + }); + }); + + expect(splitTransactions.length).toBe(2); + + for (const splitTx of splitTransactions) { + expect(splitTx.convertedAmount).toBe(expectedProportionalConvertedAmount); + } + }); }); describe('startSplitBill', () => { From afb5de0b0b72dd45b84a12bee036e5c9a0c4497e Mon Sep 17 00:00:00 2001 From: TaduJR Date: Wed, 14 Jan 2026 13:29:20 +0300 Subject: [PATCH 2/5] fix: use type assertion for Transaction with empty string modifiedAmount in test --- tests/actions/IOUTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 25174b765af8..b75da6af850c 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3465,7 +3465,7 @@ describe('actions/IOU', () => { total: originalAmount, }; - const originalTransaction: Transaction = { + const originalTransaction = { transactionID: originalTransactionID, amount: originalAmount, modifiedAmount: '', // Empty string - the edge case that was causing the bug @@ -3476,7 +3476,7 @@ describe('actions/IOU', () => { merchant: 'Test Merchant', reportID, comment: {}, - }; + } as Transaction; const transactionThread: Report = { reportID: rand64(), From 53f423fa02299e93ca967ce7270e64b4422bf7dc Mon Sep 17 00:00:00 2001 From: TaduJR Date: Wed, 14 Jan 2026 13:42:50 +0300 Subject: [PATCH 3/5] fix: cast test Transaction through unknown for empty string modifiedAmount --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index b75da6af850c..52a87015e3ae 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3476,7 +3476,7 @@ describe('actions/IOU', () => { merchant: 'Test Merchant', reportID, comment: {}, - } as Transaction; + } as unknown as Transaction; const transactionThread: Report = { reportID: rand64(), From 3f6bbd3a8864a0c9ee962fe916d62fbb058c8b4f Mon Sep 17 00:00:00 2001 From: TaduJR Date: Tue, 20 Jan 2026 16:43:06 +0300 Subject: [PATCH 4/5] refactor: rename splitTx to splitTransaction per review feedback --- tests/actions/IOUTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index e6f9af5ba7ad..b6220987b38f 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3766,8 +3766,8 @@ describe('actions/IOU', () => { expect(splitTransactions.length).toBe(2); - for (const splitTx of splitTransactions) { - expect(splitTx.convertedAmount).toBe(expectedProportionalConvertedAmount); + for (const splitTransaction of splitTransactions) { + expect(splitTransaction.convertedAmount).toBe(expectedProportionalConvertedAmount); } }); }); From c9e988d5084dfb1ab795c0786a4cbcdf01e73a52 Mon Sep 17 00:00:00 2001 From: TaduJR Date: Wed, 21 Jan 2026 01:51:33 +0300 Subject: [PATCH 5/5] fix: handle string type for modifiedAmount and add missing iouReportNextStep param --- src/libs/actions/IOU/index.ts | 4 ++-- tests/actions/IOUTest.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 32df26f6fc29..0d56bf558e08 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -3246,9 +3246,9 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma // Calculate proportional convertedAmount for the split based on the original conversion rate // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- modifiedAmount can be empty string - const originalAmount = existingTransaction.modifiedAmount || existingTransaction.amount; + const originalAmount = Number(existingTransaction.modifiedAmount) || existingTransaction.amount; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- modifiedAmount can be empty string - const splitAmount = optimisticTransaction.modifiedAmount || optimisticTransaction.amount; + const splitAmount = Number(optimisticTransaction.modifiedAmount) || optimisticTransaction.amount; if (originalConvertedAmount && originalAmount && splitAmount) { optimisticTransaction.convertedAmount = Math.round((originalConvertedAmount * splitAmount) / originalAmount); } diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index b6220987b38f..c4186682b97c 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -3742,6 +3742,7 @@ describe('actions/IOU', () => { transactionViolations: {}, policyRecentlyUsedCurrencies: [], quickAction: undefined, + iouReportNextStep: undefined, }); await waitForBatchedUpdates();