Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ function MoneyReportHeader({
}

const currentTransaction = transactions.at(0);
initSplitExpense(currentTransaction, moneyRequestReport?.reportID ?? String(CONST.DEFAULT_NUMBER_ID));
initSplitExpense(currentTransaction);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE]: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
icon: Expensicons.ArrowSplit,
value: CONST.REPORT.SECONDARY_ACTIONS.SPLIT,
onSelected: () => {
initSplitExpense(transaction, reportID ?? String(CONST.DEFAULT_NUMBER_ID));
initSplitExpense(transaction);
},
},
[CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.VIEW_DETAILS]: {
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11661,11 +11661,13 @@ function getSearchOnyxUpdate({
/**
* Create a draft transaction to set up split expense details for the split expense flow
*/
function initSplitExpense(transaction: OnyxEntry<OnyxTypes.Transaction>, reportID: string, isOpenCreatedSplit?: boolean) {
function initSplitExpense(transaction: OnyxEntry<OnyxTypes.Transaction>, isOpenCreatedSplit?: boolean) {
if (!transaction) {
return;
}

const reportID = transaction?.reportID ?? String(CONST.DEFAULT_NUMBER_ID);

if (isOpenCreatedSplit) {
const originalTransactionID = transaction.comment?.originalTransactionID;
const originalTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`];
Expand Down
9 changes: 3 additions & 6 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6072,9 +6072,7 @@ describe('actions/IOU', () => {
reportID: '456',
};

const reportID = '456';

initSplitExpense(transaction, reportID);
initSplitExpense(transaction);
await waitForBatchedUpdates();

const draftTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transaction.transactionID}`);
Expand All @@ -6086,7 +6084,7 @@ describe('actions/IOU', () => {
expect(draftTransaction?.amount).toBe(100);
expect(draftTransaction?.currency).toBe('USD');
expect(draftTransaction?.merchant).toBe('Test Merchant');
expect(draftTransaction?.reportID).toBe(reportID);
expect(draftTransaction?.reportID).toBe(transaction.reportID);

expect(splitExpenses?.[0].amount).toBe(50);
expect(splitExpenses?.[0].description).toBe('Test comment');
Expand All @@ -6100,9 +6098,8 @@ describe('actions/IOU', () => {
});
it('should not initialize split expense for null transaction', async () => {
const transaction: Transaction | undefined = undefined;
const reportID = '456';

initSplitExpense(transaction, reportID);
initSplitExpense(transaction);
await waitForBatchedUpdates();

expect(transaction).toBeFalsy();
Expand Down