From feaa3f7bd9a0ac6d10160e5d08630b1e555aae24 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Wed, 21 Feb 2024 10:34:39 +0530 Subject: [PATCH 1/4] allow money requests on instantly submitted reports --- src/components/MoneyRequestHeader.tsx | 5 +++-- src/libs/ReportUtils.ts | 15 ++++++++++++--- src/libs/actions/IOU.ts | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 1a5a2621e43e..b9513f0d695d 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -84,8 +84,9 @@ 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.isInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); } const changeMoneyRequestStatus = () => { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d0c3bf3e8c03..3455e4bd9b5f 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 is of `instant` submit type and if the report is still being processed (i.e. submitted) + */ +function isInstantSubmittedState(report: OnyxEntry | EmptyObject): boolean { + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null; + return 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) || isInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy); } return true; } @@ -4245,7 +4253,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) || isInstantSubmittedState(report); } return (isOwnExpenseReport || isIOUReport(report)) && !isReportApproved(report) && !isSettled(report?.reportID); @@ -4985,6 +4993,7 @@ export { isPublicAnnounceRoom, isConciergeChatReport, isProcessingReport, + isInstantSubmittedState, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index cc85fb92dd66..6ec97bc700f2 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -759,8 +759,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.isInstantSubmittedState(iouReport)) { iouReport = null; } } From c202d3c8ed5a7a5c82a7df4e6a2e82423aa80e5c Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sat, 24 Feb 2024 08:57:13 +0530 Subject: [PATCH 2/4] Update src/libs/ReportUtils.ts Co-authored-by: Alex Beaman --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3455e4bd9b5f..524ed0f3f65e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -956,7 +956,7 @@ function isProcessingReport(report: OnyxEntry | EmptyObject): boolean { } /** - * Returns true if the policy is of `instant` submit type and if the report is still being processed (i.e. submitted) + * Returns true if the policy has `instant` reporting frequency and if the report is still being processed (i.e. submitted state) */ function isInstantSubmittedState(report: OnyxEntry | EmptyObject): boolean { const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null; From 9a71d715cd4d477056a428e3e5b011295c6d1e14 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sat, 24 Feb 2024 10:50:28 +0530 Subject: [PATCH 3/4] spelling correction - subtract --- src/libs/actions/IOU.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 58cb49301ddf..2ccac6dd40c5 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -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 { From fc4297dfc9c451cfdf84d8dcdb6c0d59041a32f3 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 26 Feb 2024 22:23:58 +0530 Subject: [PATCH 4/4] better function name and check for isExpenseReport too --- src/components/MoneyRequestHeader.tsx | 3 ++- src/libs/ReportUtils.ts | 10 +++++----- src/libs/actions/IOU.ts | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index b9513f0d695d..35d26a35b331 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -86,7 +86,8 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction, if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { // 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.isInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); + 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 89f02b8322b0..2b60c339cdaf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -958,9 +958,9 @@ function isProcessingReport(report: OnyxEntry | EmptyObject): boolean { /** * Returns true if the policy has `instant` reporting frequency and if the report is still being processed (i.e. submitted state) */ -function isInstantSubmittedState(report: OnyxEntry | EmptyObject): boolean { +function isExpenseReportWithInstantSubmittedState(report: OnyxEntry | EmptyObject): boolean { const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null; - return isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy); + return isExpenseReport(report) && isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy); } /** @@ -1273,7 +1273,7 @@ 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 a draft or is instantly submitted or the user is the policy admin - return isDraftExpenseReport(report) || isInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy); + return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy); } return true; } @@ -4264,7 +4264,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o if (isMoneyRequestReport(report)) { const isOwnExpenseReport = isExpenseReport(report) && isOwnPolicyExpenseChat; if (isOwnExpenseReport && PolicyUtils.isPaidGroupPolicy(policy)) { - return isDraftExpenseReport(report) || isInstantSubmittedState(report); + return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report); } return (isOwnExpenseReport || isIOUReport(report)) && !isReportApproved(report) && !isSettled(report?.reportID); @@ -5066,7 +5066,7 @@ export { isPublicAnnounceRoom, isConciergeChatReport, isProcessingReport, - isInstantSubmittedState, + isExpenseReportWithInstantSubmittedState, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyAccountIDs, hasExpensifyGuidesEmails, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 2ccac6dd40c5..d84d9584ef2b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -805,7 +805,7 @@ function getMoneyRequestInformation( needsToBeManuallySubmitted = isFromPaidPolicy && !policy?.harvesting?.enabled; // 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.isInstantSubmittedState(iouReport)) { + if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport) && !ReportUtils.isExpenseReportWithInstantSubmittedState(iouReport)) { iouReport = null; } }