diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ad2b8a1243d1..07ed7eebf397 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2744,7 +2744,7 @@ function canDeleteMoneyRequestReport(report: Report, reportTransactions: Transac } if (isInvoiceReport(report)) { - return report?.ownerAccountID === currentUserAccountID && isReportOpenOrProcessing && policy?.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL; + return report?.ownerAccountID === currentUserAccountID && isReportOpenOrProcessing; } // Users cannot delete a report in the unreported or IOU cases, but they can delete individual transactions. diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index bd6e1153cca6..bb3fa3883875 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -26,6 +26,7 @@ import { buildTransactionThread, canAddTransaction, canCreateRequest, + canDeleteMoneyRequestReport, canDeleteReportAction, canDeleteTransaction, canEditMoneyRequest, @@ -3410,6 +3411,24 @@ describe('ReportUtils', () => { }); }); + describe('canDeleteMoneyRequestReport', () => { + it('should allow deletion if the report is open invoice report', async () => { + const invoiceReport = {...createInvoiceReport(343), ownerAccountID: currentUserAccountID, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS_NUM.OPEN}; + // Wait for Onyx to load session data before calling canDeleteMoneyRequestReport, + // since it relies on the session subscription for currentUserAccountID. + await new Promise((resolve) => { + const connection = Onyx.connectWithoutView({ + key: `${ONYXKEYS.SESSION}`, + callback: () => { + Onyx.disconnect(connection); + resolve(); + }, + }); + }); + expect(canDeleteMoneyRequestReport(invoiceReport, [], [])).toBe(true); + }); + }); + describe('canEditMoneyRequest', () => { it('it should return false for archived invoice', async () => { const invoiceReport: Report = {