diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index f53e3130f660..fe8cc3506b3f 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -84,8 +84,10 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction, let canDeleteRequest = canModifyRequest; if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { - // If it's a paid policy expense report, only allow deleting the request if it's not submitted or the user is the policy admin - canDeleteRequest = canDeleteRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); + // If it's a paid policy expense report, only allow deleting the request if it's in draft state or instantly submitted state or the user is the policy admin + canDeleteRequest = + canDeleteRequest && + (ReportUtils.isDraftExpenseReport(moneyRequestReport) || ReportUtils.isExpenseReportWithInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); } const changeMoneyRequestStatus = () => { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 747ba27780a3..95a4bc4a8e1f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -955,6 +955,14 @@ function isProcessingReport(report: OnyxEntry | EmptyObject): boolean { return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED; } +/** + * Returns true if the policy has `instant` reporting frequency and if the report is still being processed (i.e. submitted state) + */ +function isExpenseReportWithInstantSubmittedState(report: OnyxEntry | EmptyObject): boolean { + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null; + return isExpenseReport(report) && isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy); +} + /** * Check if the report is a single chat report that isn't a thread * and personal detail of participant is optimistic data @@ -1264,8 +1272,8 @@ function canDeleteReportAction(reportAction: OnyxEntry, reportID: if (isActionOwner) { if (!isEmptyObject(report) && isPaidGroupPolicyExpenseReport(report)) { - // If it's a paid policy expense report, only allow deleting the request if it's not submitted or the user is the policy admin - return isDraftExpenseReport(report) || PolicyUtils.isPolicyAdmin(policy); + // If it's a paid policy expense report, only allow deleting the request if it's a draft or is instantly submitted or the user is the policy admin + return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy); } return true; } @@ -4238,7 +4246,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o if (isMoneyRequestReport(report)) { const isOwnExpenseReport = isExpenseReport(report) && isOwnPolicyExpenseChat; if (isOwnExpenseReport && PolicyUtils.isPaidGroupPolicy(policy)) { - return isDraftExpenseReport(report); + return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report); } return (isOwnExpenseReport || isIOUReport(report)) && !isReportApproved(report) && !isSettled(report?.reportID); @@ -5040,6 +5048,7 @@ export { isPublicAnnounceRoom, isConciergeChatReport, isProcessingReport, + isExpenseReportWithInstantSubmittedState, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index ca43d92bde83..e2ad00e1555d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -804,8 +804,8 @@ function getMoneyRequestInformation( // If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN needsToBeManuallySubmitted = isFromPaidPolicy && !policy?.harvesting?.enabled; - // If the linked expense report on paid policy is not draft, we need to create a new draft expense report - if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport)) { + // If the linked expense report on paid policy is not draft and not instantly submitted, we need to create a new draft expense report + if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport) && !ReportUtils.isExpenseReportWithInstantSubmittedState(iouReport)) { iouReport = null; } } @@ -814,7 +814,7 @@ function getMoneyRequestInformation( if (isPolicyExpenseChat) { iouReport = {...iouReport}; if (iouReport?.currency === currency && typeof iouReport.total === 'number') { - // Because of the Expense reports are stored as negative values, we substract the total from the amount + // Because of the Expense reports are stored as negative values, we subtract the total from the amount iouReport.total -= amount; } } else {