Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conditional statement for hasOutstandingChildRequest when calculating the optimistic data for IOU requests #38431

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5314,6 +5314,18 @@ function shouldCreateNewMoneyRequestReport(existingIOUReport: OnyxEntry<Report>
return !existingIOUReport || hasIOUWaitingOnCurrentUserBankAccount(chatReport) || !canAddOrDeleteTransactions(existingIOUReport);
}

function needsToBeManuallySubmitted(iouReport: Report) {
if (isPolicyExpenseChat(iouReport)) {
const policy = getPolicy(iouReport.policyID);
const isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);

// If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN
return isFromPaidPolicy && !policy.harvesting?.enabled;
}

return true;
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -5524,6 +5536,7 @@ export {
isJoinRequestInAdminRoom,
canAddOrDeleteTransactions,
shouldCreateNewMoneyRequestReport,
needsToBeManuallySubmitted,
};

export type {
Expand Down
25 changes: 7 additions & 18 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,25 +402,11 @@ function getReceiptError(receipt?: Receipt, filename?: string, isScanRequest = t
: ErrorUtils.getMicroSecondOnyxErrorObject({error: CONST.IOU.RECEIPT_ERROR, source: receipt.source?.toString() ?? '', filename: filename ?? ''});
}

function needsToBeManuallySubmitted(iouReport: OnyxTypes.Report) {
const isPolicyExpenseChat = ReportUtils.isExpenseReport(iouReport);

if (isPolicyExpenseChat) {
const policy = ReportUtils.getPolicy(iouReport.policyID);
const isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy);

// If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN
return isFromPaidPolicy && !policy.harvesting?.enabled;
}

return true;
}

/**
* Return the object to update hasOutstandingChildRequest
*/
function getOutstandingChildRequest(policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject, iouReport: OnyxTypes.Report): OutstandingChildRequest {
if (!needsToBeManuallySubmitted(iouReport)) {
if (!ReportUtils.needsToBeManuallySubmitted(iouReport)) {
return {
hasOutstandingChildRequest: false,
};
Expand Down Expand Up @@ -1248,6 +1234,8 @@ function getUpdateMoneyRequestParams(
}
updatedMoneyRequestReport.cachedTotal = CurrencyUtils.convertToDisplayString(updatedMoneyRequestReport.total, transactionDetails?.currency);

const canChatRequireAttention = (!!iouReport && ReportUtils.needsToBeManuallySubmitted(iouReport)) || updatedMoneyRequestReport.managerID === userAccountID;

optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -1258,8 +1246,7 @@ function getUpdateMoneyRequestParams(
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`,
value: {
hasOutstandingChildRequest:
iouReport && needsToBeManuallySubmitted(iouReport) && updatedMoneyRequestReport.managerID === userAccountID && updatedMoneyRequestReport.total !== 0,
hasOutstandingChildRequest: canChatRequireAttention && updatedMoneyRequestReport.total !== 0,
},
},
);
Expand Down Expand Up @@ -3008,6 +2995,8 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor
);
}

const canChatRequireAttention = (!!iouReport && ReportUtils.needsToBeManuallySubmitted(iouReport)) || updatedIOUReport?.managerID === userAccountID;

optimisticData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -3030,7 +3019,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
value: {
hasOutstandingChildRequest: iouReport && needsToBeManuallySubmitted(iouReport) && updatedIOUReport?.managerID === userAccountID && updatedIOUReport.total !== 0,
hasOutstandingChildRequest: canChatRequireAttention && updatedIOUReport?.total !== 0,
},
},
);
Expand Down
Loading