Skip to content
Merged
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
20 changes: 19 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber';
import {getPerDiemCustomUnit, getPolicy, getSubmitToAccountID, hasDependentTags, isControlPolicy, isPaidGroupPolicy, isPolicyAdmin, isSubmitAndClose} from '@libs/PolicyUtils';
import {
getAllReportActions,
getIOUReportIDFromReportActionPreview,
getLastVisibleAction,
getLastVisibleMessage,
getOriginalMessage,
Expand Down Expand Up @@ -7851,6 +7852,23 @@ function getReportFromHoldRequestsOnyxData(
};
}

function hasOutstandingChildRequest(chatReport: OnyxTypes.Report, excludedIOUReport: OnyxEntry<OnyxTypes.Report>, policyId?: string) {
const policy = getPolicy(policyId);
if (!policy?.achAccount?.bankAccountID) {
return false;
}
const reportActions = getAllReportActions(chatReport.reportID);
return !!Object.values(reportActions).find((action) => {
const iouReportID = getIOUReportIDFromReportActionPreview(action);
if (iouReportID === excludedIOUReport?.reportID) {
return false;
}
const iouReport = getReportOrDraftReport(iouReportID);
const transactions = getReportTransactions(iouReportID);
return canIOUBePaid(iouReport, chatReport, policy, transactions) || canIOUBePaid(iouReport, chatReport, policy, transactions, true);
});
}

function getPayMoneyRequestParams(
initialChatReport: OnyxTypes.Report,
iouReport: OnyxEntry<OnyxTypes.Report>,
Expand Down Expand Up @@ -7937,7 +7955,7 @@ function getPayMoneyRequestParams(
const optimisticChatReport = {
...chatReport,
lastReadTime: DateUtils.getDBTime(),
hasOutstandingChildRequest: false,
hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport, iouReport?.policyID),
iouReportID: null,
lastMessageText: getReportActionText(optimisticIOUReportAction),
lastMessageHtml: getReportActionHtml(optimisticIOUReportAction),
Expand Down