From 20356345c20616fde66613a27ee9272fae335d03 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Fri, 2 Aug 2024 19:50:33 +0700 Subject: [PATCH] add report action id to expense report --- src/libs/ReportUtils.ts | 16 ++++++++++++++-- src/libs/actions/IOU.ts | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 142b319240f1..9a2c3089e623 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4097,8 +4097,17 @@ function buildOptimisticInvoiceReport(chatReportID: string, policyID: string, re * @param total - Amount in cents * @param currency * @param reimbursable – Whether the expense is reimbursable + * @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat */ -function buildOptimisticExpenseReport(chatReportID: string, policyID: string, payeeAccountID: number, total: number, currency: string, reimbursable = true): OptimisticExpenseReport { +function buildOptimisticExpenseReport( + chatReportID: string, + policyID: string, + payeeAccountID: number, + total: number, + currency: string, + reimbursable = true, + parentReportActionID?: string, +): OptimisticExpenseReport { // The amount for Expense reports are stored as negative value in the database const storedTotal = total * -1; const policyName = getPolicyName(ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`]); @@ -4126,6 +4135,7 @@ function buildOptimisticExpenseReport(chatReportID: string, policyID: string, pa notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID: chatReportID, lastVisibleActionCreated: DateUtils.getDBTime(), + parentReportActionID, }; // Get the approver/manager for this report to properly display the optimistic data @@ -4472,6 +4482,7 @@ function buildOptimisticSubmittedReportAction(amount: number, currency: string, * @param iouReport * @param [comment] - User comment for the IOU. * @param [transaction] - optimistic first transaction of preview + * @param reportActionID */ function buildOptimisticReportPreview( chatReport: OnyxInputOrEntry, @@ -4479,12 +4490,13 @@ function buildOptimisticReportPreview( comment = '', transaction: OnyxInputOrEntry = null, childReportID?: string, + reportActionID?: string, ): ReportAction { const hasReceipt = TransactionUtils.hasReceipt(transaction); const message = getReportPreviewMessage(iouReport); const created = DateUtils.getDBTime(); return { - reportActionID: NumberUtils.rand64(), + reportActionID: reportActionID ?? NumberUtils.rand64(), reportID: chatReport?.reportID, actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 08b6bfebb41a..2a010fd25ddc 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -6242,6 +6242,7 @@ function getReportFromHoldRequestsOnyxData( } { const {holdReportActions, holdTransactions} = getHoldReportActionsAndTransactions(iouReport.reportID); const firstHoldTransaction = holdTransactions[0]; + const newParentReportActionID = rand64(); const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport( chatReport.reportID, @@ -6250,8 +6251,16 @@ function getReportFromHoldRequestsOnyxData( (firstHoldTransaction?.amount ?? 0) * -1, getCurrency(firstHoldTransaction), false, + newParentReportActionID, + ); + const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview( + chatReport, + optimisticExpenseReport, + '', + firstHoldTransaction, + optimisticExpenseReport.reportID, + newParentReportActionID, ); - const optimisticExpenseReportPreview = ReportUtils.buildOptimisticReportPreview(chatReport, optimisticExpenseReport, '', firstHoldTransaction, optimisticExpenseReport.reportID); const updateHeldReports: Record> = {}; const addHoldReportActions: OnyxTypes.ReportActions = {};