Skip to content

Commit c5fea78

Browse files
committed
use reports by policy ID in canEditFieldOfMoneyRequest
1 parent 3ee664b commit c5fea78

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/components/MoneyRequestConfirmationListFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function MoneyRequestConfirmationListFooter({
288288
const policyID = selectedParticipants?.at(0)?.policyID;
289289
const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID;
290290
const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID);
291-
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0);
291+
const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, Object.values(allReports ?? {})).at(0);
292292
let reportName: string | undefined;
293293
if (shouldUseTransactionReport) {
294294
reportName = transactionReport.reportName;

src/libs/ReportUtils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,9 +4235,12 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry<ReportAction>
42354235
// Unreported transaction from OldDot can have the reportID as an empty string
42364236
const isUnreported = !transaction?.reportID || transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
42374237
return isUnreported
4238-
? Object.values(allPolicies ?? {}).flatMap((currentPolicy) => getOutstandingReportsForUser(currentPolicy?.id, currentUserAccountID, allReports ?? {})).length > 0
4239-
: Object.values(allPolicies ?? {}).flatMap((currentPolicy) => getOutstandingReportsForUser(currentPolicy?.id, moneyRequestReport?.ownerAccountID, allReports ?? {})).length > 1 ||
4240-
isOwner;
4238+
? Object.values(allPolicies ?? {}).flatMap((currentPolicy) =>
4239+
getOutstandingReportsForUser(currentPolicy?.id, currentUserAccountID, reportsByPolicyID?.[currentPolicy?.id ?? CONST.DEFAULT_NUMBER_ID] ?? {}),
4240+
).length > 0
4241+
: Object.values(allPolicies ?? {}).flatMap((currentPolicy) =>
4242+
getOutstandingReportsForUser(currentPolicy?.id, moneyRequestReport?.ownerAccountID, reportsByPolicyID?.[currentPolicy?.id ?? CONST.DEFAULT_NUMBER_ID] ?? {}),
4243+
).length > 1 || isOwner;
42414244
}
42424245

42434246
return true;
@@ -10033,13 +10036,13 @@ function isReportOutstanding(
1003310036
function getOutstandingReportsForUser(
1003410037
policyID: string | undefined,
1003510038
reportOwnerAccountID: number | undefined,
10036-
reports: OnyxCollection<Report> = allReports,
10039+
reports: Array<OnyxEntry<Report>> = Object.values(allReports ?? {}),
1003710040
reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = allReportNameValuePair,
1003810041
): Array<OnyxEntry<Report>> {
1003910042
if (!reports) {
1004010043
return [];
1004110044
}
10042-
return Object.values(reports)
10045+
return reports
1004310046
.filter((report) => isReportOutstanding(report, policyID, reportNameValuePairs) && report?.ownerAccountID === reportOwnerAccountID)
1004410047
.sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0);
1004510048
}

src/pages/iou/request/step/IOURequestEditReportCommon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport,
7272
const reports = getOutstandingReportsForUser(
7373
policyID,
7474
transactionsReports.at(0)?.ownerAccountID ?? currentUserPersonalDetails.accountID,
75-
allReports ?? {},
75+
Object.values(allReports ?? {}),
7676
reportNameValuePairs,
7777
);
7878
return reports;

0 commit comments

Comments
 (0)