diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bf687c973abb..e44777a5096d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1284,6 +1284,16 @@ function isProcessingReport(report: OnyxEntry): boolean { return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED; } +function isAwaitingFirstLevelApproval(report: OnyxEntry): boolean { + if (!report) { + return false; + } + + const submitsToAccountID = PolicyUtils.getSubmitToAccountID(getPolicy(report.policyID), report.ownerAccountID ?? -1); + + return isProcessingReport(report) && submitsToAccountID === report.managerID; +} + /** * Check if the report is a single chat report that isn't a thread * and personal detail of participant is optimistic data @@ -1739,6 +1749,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } + if (PolicyUtils.isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) { + return isAwaitingFirstLevelApproval(moneyRequestReport); + } + if (isReportApproved(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) { return false; } @@ -8492,6 +8506,7 @@ export { isPolicyExpenseChat, isPolicyExpenseChatAdmin, isProcessingReport, + isAwaitingFirstLevelApproval, isPublicAnnounceRoom, isPublicRoom, isReportApproved, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e4eee7241d80..81101b74f4d7 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -691,6 +691,12 @@ describe('ReportUtils', () => { owner: '', outputCurrency: '', isPolicyExpenseChatEnabled: false, + employeeList: { + [currentUserEmail]: { + email: currentUserEmail, + submitsTo: currentUserEmail, + }, + }, }; Promise.all([ Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${paidPolicy.id}`, paidPolicy), @@ -698,6 +704,8 @@ describe('ReportUtils', () => { reportID: '101', chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, isOwnPolicyExpenseChat: true, + policyID: paidPolicy.id, + ownerAccountID: currentUserAccountID, }), ]).then(() => { const report = { @@ -708,6 +716,7 @@ describe('ReportUtils', () => { parentReportID: '101', policyID: paidPolicy.id, managerID: currentUserAccountID, + ownerAccountID: currentUserAccountID, }; const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, paidPolicy, [currentUserAccountID, participantsAccountIDs.at(0) ?? -1]); expect(moneyRequestOptions.length).toBe(2);