diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 17567d87c074..9b4ab95b158d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4300,7 +4300,10 @@ function canEditFieldOfMoneyRequest( } if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) { - if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID)) { + // Unreported transaction from OldDot can have the reportID as an empty string + const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; + + if (!isReportOutstanding(moneyRequestReport, moneyRequestReport.policyID) && !isUnreportedExpense) { return false; } @@ -4310,9 +4313,6 @@ function canEditFieldOfMoneyRequest( } const isOwner = moneyRequestReport?.ownerAccountID === currentUserAccountID; - // Unreported transaction from OldDot can have the reportID as an empty string - const isUnreportedExpense = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; - if (isInvoiceReport(moneyRequestReport) && !isUnreportedExpense) { return ( getOutstandingReportsForUser( diff --git a/tests/unit/canEditFieldOfMoneyRequestTest.ts b/tests/unit/canEditFieldOfMoneyRequestTest.ts index 6929f224074c..dd684124ff5c 100644 --- a/tests/unit/canEditFieldOfMoneyRequestTest.ts +++ b/tests/unit/canEditFieldOfMoneyRequestTest.ts @@ -260,6 +260,21 @@ describe('canEditFieldOfMoneyRequest', () => { // Then they should not be able to move the expense since there's only one outstanding report expect(canEditReportField).toBe(false); }); + + it('should return false when the expense report is not outstanding report', async () => { + // Given that there are multiple outstanding expense reports in the same policy + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`, {...expenseReport, stateNum: CONST.REPORT.STATE_NUM.APPROVED, statusNum: CONST.REPORT.STATUS_NUM.APPROVED}); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_1_ID}`, outstandingExpenseReport1); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${EXPENSE_OUTSTANDING_REPORT_2_ID}`, outstandingExpenseReport2); + await waitForBatchedUpdates(); + const outstandingReportsByPolicyID = await OnyxUtils.get(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID); + + // When the submitter tries to move an expense between reports + const canEditReportField = canEditFieldOfMoneyRequest(reportAction, CONST.EDIT_REQUEST_FIELD.REPORT, undefined, undefined, outstandingReportsByPolicyID); + + // Then they should be able to move the expense since there are multiple outstanding expense reports + expect(canEditReportField).toBe(false); + }); }); }); });