From ffc8ca69a9a91b3a942e2e3932b4b2b11ba10082 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 26 Nov 2024 22:28:12 +0700 Subject: [PATCH 1/6] Green dot disappears from LHN when paying one out of many unpaid reports --- src/libs/actions/IOU.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 3fb01f916acda..26f7e3c1fda8e 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6503,6 +6503,17 @@ function getReportFromHoldRequestsOnyxData( }; } +function hasOutstandingChildRequest(reportID: string, excludedIOUReportID: string){ + const reportActions = ReportActionsUtils.getAllReportActions(reportID); + return !!Object.values(reportActions).find(action => { + const iouReportID = ReportActionsUtils.getIOUReportIDFromReportActionPreview(action); + if(iouReportID === excludedIOUReportID){ + return false; + } + return ReportUtils.getReport(iouReportID)?.hasOutstandingChildRequest; + }) +} + function getPayMoneyRequestParams( initialChatReport: OnyxTypes.Report, iouReport: OnyxEntry, @@ -6590,7 +6601,7 @@ function getPayMoneyRequestParams( ...chatReport, lastReadTime: DateUtils.getDBTime(), lastVisibleActionCreated: optimisticIOUReportAction.created, - hasOutstandingChildRequest: false, + hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID ?? ''), iouReportID: null, lastMessageText: ReportActionsUtils.getReportActionText(optimisticIOUReportAction), lastMessageHtml: ReportActionsUtils.getReportActionHtml(optimisticIOUReportAction), From 3d6fe26db1153e8654b9494323a49f1ab220c880 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 20 Feb 2025 11:55:41 +0700 Subject: [PATCH 2/6] lint fix --- src/libs/actions/IOU.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 5d3eac989afa1..2ac77107091a2 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -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, @@ -7745,15 +7746,15 @@ function getReportFromHoldRequestsOnyxData( }; } -function hasOutstandingChildRequest(reportID: string, excludedIOUReportID: string){ - const reportActions = ReportActionsUtils.getAllReportActions(reportID); - return !!Object.values(reportActions).find(action => { - const iouReportID = ReportActionsUtils.getIOUReportIDFromReportActionPreview(action); - if(iouReportID === excludedIOUReportID){ +function hasOutstandingChildRequest(reportID: string, excludedIOUReportID: string) { + const reportActions = getAllReportActions(reportID); + return !!Object.values(reportActions).find((action) => { + const iouReportID = getIOUReportIDFromReportActionPreview(action); + if (iouReportID === excludedIOUReportID) { return false; } - return ReportUtils.getReport(iouReportID)?.hasOutstandingChildRequest; - }) + return getReportOrDraftReport(iouReportID)?.hasOutstandingChildRequest; + }); } function getPayMoneyRequestParams( From f522eb6de6bdd2b53de6e471298404668748aaf6 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 20 Feb 2025 11:59:48 +0700 Subject: [PATCH 3/6] use default value --- 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 2ac77107091a2..9ea980e51d5d3 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7844,7 +7844,7 @@ function getPayMoneyRequestParams( ...chatReport, lastReadTime: DateUtils.getDBTime(), lastVisibleActionCreated: optimisticIOUReportAction.created, - hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID ?? ''), + hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID ?? CONST.DEFAULT_NUMBER_ID), iouReportID: null, lastMessageText: getReportActionText(optimisticIOUReportAction), lastMessageHtml: getReportActionHtml(optimisticIOUReportAction), From b6b2fce545e994543e57d4e44269f41347bf4ec2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 20 Feb 2025 13:09:58 +0700 Subject: [PATCH 4/6] fix type --- src/libs/actions/IOU.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9ea980e51d5d3..407a1bf407fbd 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7746,7 +7746,7 @@ function getReportFromHoldRequestsOnyxData( }; } -function hasOutstandingChildRequest(reportID: string, excludedIOUReportID: string) { +function hasOutstandingChildRequest(reportID: string, excludedIOUReportID?: string) { const reportActions = getAllReportActions(reportID); return !!Object.values(reportActions).find((action) => { const iouReportID = getIOUReportIDFromReportActionPreview(action); @@ -7843,8 +7843,7 @@ function getPayMoneyRequestParams( const optimisticChatReport = { ...chatReport, lastReadTime: DateUtils.getDBTime(), - lastVisibleActionCreated: optimisticIOUReportAction.created, - hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID ?? CONST.DEFAULT_NUMBER_ID), + hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID), iouReportID: null, lastMessageText: getReportActionText(optimisticIOUReportAction), lastMessageHtml: getReportActionHtml(optimisticIOUReportAction), From 7c2b71452c09c220d7b0f97cadd5c21576da4752 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 3 Mar 2025 15:53:08 +0700 Subject: [PATCH 5/6] update hasOutstandingChildRequest --- src/libs/actions/IOU.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 4d49c9987c0b4..ea54b4a638d2e 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7840,14 +7840,16 @@ function getReportFromHoldRequestsOnyxData( }; } -function hasOutstandingChildRequest(reportID: string, excludedIOUReportID?: string) { - const reportActions = getAllReportActions(reportID); +function hasOutstandingChildRequest(chatReport: OnyxTypes.Report, excludedIOUReport: OnyxEntry, policy: OnyxEntry) { + const reportActions = getAllReportActions(chatReport.reportID); return !!Object.values(reportActions).find((action) => { const iouReportID = getIOUReportIDFromReportActionPreview(action); - if (iouReportID === excludedIOUReportID) { + if (iouReportID === excludedIOUReport?.reportID) { return false; } - return getReportOrDraftReport(iouReportID)?.hasOutstandingChildRequest; + const iouReport = getReportOrDraftReport(iouReportID); + const transactions = getReportTransactions(iouReportID); + return canIOUBePaid(iouReport, chatReport, policy, transactions) || canIOUBePaid(iouReport, chatReport, policy, transactions, true); }); } @@ -7937,7 +7939,7 @@ function getPayMoneyRequestParams( const optimisticChatReport = { ...chatReport, lastReadTime: DateUtils.getDBTime(), - hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport.reportID, iouReport?.reportID), + hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport, activePolicy), iouReportID: null, lastMessageText: getReportActionText(optimisticIOUReportAction), lastMessageHtml: getReportActionHtml(optimisticIOUReportAction), From e71dff407fdf675c7e8ca79b025ab3fc0f6a43a6 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 7 Mar 2025 10:44:24 +0700 Subject: [PATCH 6/6] add ach account check --- src/libs/actions/IOU.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 7f343ca2463ee..805f00e898660 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7852,7 +7852,11 @@ function getReportFromHoldRequestsOnyxData( }; } -function hasOutstandingChildRequest(chatReport: OnyxTypes.Report, excludedIOUReport: OnyxEntry, policy: OnyxEntry) { +function hasOutstandingChildRequest(chatReport: OnyxTypes.Report, excludedIOUReport: OnyxEntry, 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); @@ -7951,7 +7955,7 @@ function getPayMoneyRequestParams( const optimisticChatReport = { ...chatReport, lastReadTime: DateUtils.getDBTime(), - hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport, activePolicy), + hasOutstandingChildRequest: hasOutstandingChildRequest(chatReport, iouReport, iouReport?.policyID), iouReportID: null, lastMessageText: getReportActionText(optimisticIOUReportAction), lastMessageHtml: getReportActionHtml(optimisticIOUReportAction),