Skip to content

Commit 174a032

Browse files
authored
Merge pull request #36997 from rojiphil/35814-instant-submit-allow-request-money
allow money requests on instantly submitted reports
2 parents cfa0ae3 + fc4297d commit 174a032

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/components/MoneyRequestHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction,
8484
let canDeleteRequest = canModifyRequest;
8585

8686
if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) {
87-
// 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
88-
canDeleteRequest = canDeleteRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy));
87+
// 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
88+
canDeleteRequest =
89+
canDeleteRequest &&
90+
(ReportUtils.isDraftExpenseReport(moneyRequestReport) || ReportUtils.isExpenseReportWithInstantSubmittedState(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy));
8991
}
9092

9193
const changeMoneyRequestStatus = () => {

src/libs/ReportUtils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,14 @@ function isProcessingReport(report: OnyxEntry<Report> | EmptyObject): boolean {
955955
return report?.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report?.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
956956
}
957957

958+
/**
959+
* Returns true if the policy has `instant` reporting frequency and if the report is still being processed (i.e. submitted state)
960+
*/
961+
function isExpenseReportWithInstantSubmittedState(report: OnyxEntry<Report> | EmptyObject): boolean {
962+
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null;
963+
return isExpenseReport(report) && isProcessingReport(report) && PolicyUtils.isInstantSubmitEnabled(policy);
964+
}
965+
958966
/**
959967
* Check if the report is a single chat report that isn't a thread
960968
* and personal detail of participant is optimistic data
@@ -1264,8 +1272,8 @@ function canDeleteReportAction(reportAction: OnyxEntry<ReportAction>, reportID:
12641272

12651273
if (isActionOwner) {
12661274
if (!isEmptyObject(report) && isPaidGroupPolicyExpenseReport(report)) {
1267-
// 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
1268-
return isDraftExpenseReport(report) || PolicyUtils.isPolicyAdmin(policy);
1275+
// 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
1276+
return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report) || PolicyUtils.isPolicyAdmin(policy);
12691277
}
12701278
return true;
12711279
}
@@ -4238,7 +4246,7 @@ function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, o
42384246
if (isMoneyRequestReport(report)) {
42394247
const isOwnExpenseReport = isExpenseReport(report) && isOwnPolicyExpenseChat;
42404248
if (isOwnExpenseReport && PolicyUtils.isPaidGroupPolicy(policy)) {
4241-
return isDraftExpenseReport(report);
4249+
return isDraftExpenseReport(report) || isExpenseReportWithInstantSubmittedState(report);
42424250
}
42434251

42444252
return (isOwnExpenseReport || isIOUReport(report)) && !isReportApproved(report) && !isSettled(report?.reportID);
@@ -5040,6 +5048,7 @@ export {
50405048
isPublicAnnounceRoom,
50415049
isConciergeChatReport,
50425050
isProcessingReport,
5051+
isExpenseReportWithInstantSubmittedState,
50435052
isCurrentUserTheOnlyParticipant,
50445053
hasAutomatedExpensifyAccountIDs,
50455054
hasExpensifyGuidesEmails,

src/libs/actions/IOU.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,8 @@ function getMoneyRequestInformation(
804804
// If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN
805805
needsToBeManuallySubmitted = isFromPaidPolicy && !policy?.harvesting?.enabled;
806806

807-
// If the linked expense report on paid policy is not draft, we need to create a new draft expense report
808-
if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport)) {
807+
// If the linked expense report on paid policy is not draft and not instantly submitted, we need to create a new draft expense report
808+
if (iouReport && isFromPaidPolicy && !ReportUtils.isDraftExpenseReport(iouReport) && !ReportUtils.isExpenseReportWithInstantSubmittedState(iouReport)) {
809809
iouReport = null;
810810
}
811811
}
@@ -814,7 +814,7 @@ function getMoneyRequestInformation(
814814
if (isPolicyExpenseChat) {
815815
iouReport = {...iouReport};
816816
if (iouReport?.currency === currency && typeof iouReport.total === 'number') {
817-
// Because of the Expense reports are stored as negative values, we substract the total from the amount
817+
// Because of the Expense reports are stored as negative values, we subtract the total from the amount
818818
iouReport.total -= amount;
819819
}
820820
} else {

0 commit comments

Comments
 (0)