diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index b02b70cdb85e..71090e85cf7e 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -830,7 +830,7 @@ function getMerchant(transaction: OnyxInputOrEntry, policyParam: On const mileageRate = DistanceRequestUtils.getRate({transaction, policy}); const {unit, rate} = mileageRate; const distanceInMeters = getDistanceInMeters(transaction, unit); - if (!isUnreportedAndHasInvalidDistanceRateTransaction(transaction, policy)) { + if (policy && !isUnreportedAndHasInvalidDistanceRateTransaction(transaction, policy)) { // eslint-disable-next-line @typescript-eslint/no-deprecated return DistanceRequestUtils.getDistanceMerchant(true, distanceInMeters, unit, rate, transaction.currency, translateLocal, (digit) => toLocaleDigit(IntlStore.getCurrentLocale(), digit), diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c3fa75846ef5..f6a137bf6435 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -12766,11 +12766,20 @@ function rejectMoneyRequest(transactionID: string, reportID: string, comment: st } } else { // For reports with single expense: Delete the report - optimisticData.push({ - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: null, - }); + optimisticData.push( + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: null, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, + value: { + reportID: CONST.REPORT.UNREPORTED_REPORT_ID, + }, + }, + ); // And delete the corresponding REPORTPREVIEW action const parentReportID = report?.parentReportID; @@ -12809,11 +12818,20 @@ function rejectMoneyRequest(transactionID: string, reportID: string, comment: st }); // Add failure data to restore the report - failureData.push({ - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: report, - }); + failureData.push( + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: report, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, + value: { + reportID, + }, + }, + ); if (isUserOnSearchPage) { // Navigate to the existing Reports > Expense view. diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index 29cc81b03f32..f0502da9e67e 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -537,7 +537,8 @@ describe('TransactionUtils', () => { const transaction = generateTransaction({ iouRequestType: CONST.IOU.REQUEST_TYPE.DISTANCE, }); - const merchant = TransactionUtils.getMerchant(transaction); + const policy = {role: CONST.POLICY.ROLE.ADMIN} as Policy; + const merchant = TransactionUtils.getMerchant(transaction, policy); expect(merchant).toBe('Pending...'); });