Skip to content

Commit

Permalink
Merge pull request Expensify#36997 from rojiphil/35814-instant-submit…
Browse files Browse the repository at this point in the history
…-allow-request-money

allow money requests on instantly submitted reports
  • Loading branch information
Beamanator authored Feb 27, 2024
2 parents cfa0ae3 + fc4297d commit 174a032
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
15 changes: 12 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,14 @@ function isProcessingReport(report: OnyxEntry<Report> | 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<Report> | 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
Expand Down Expand Up @@ -1264,8 +1272,8 @@ function canDeleteReportAction(reportAction: OnyxEntry<ReportAction>, 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;
}
Expand Down Expand Up @@ -4238,7 +4246,7 @@ function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, 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);
Expand Down Expand Up @@ -5040,6 +5048,7 @@ export {
isPublicAnnounceRoom,
isConciergeChatReport,
isProcessingReport,
isExpenseReportWithInstantSubmittedState,
isCurrentUserTheOnlyParticipant,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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 {
Expand Down

0 comments on commit 174a032

Please sign in to comment.