Skip to content
Merged
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
16 changes: 14 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4472,19 +4482,21 @@ 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<Report>,
iouReport: Report,
comment = '',
transaction: OnyxInputOrEntry<Transaction> = null,
childReportID?: string,
reportActionID?: string,
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
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,
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string, Pick<OnyxTypes.Report, 'parentReportActionID' | 'parentReportID' | 'chatReportID'>> = {};
const addHoldReportActions: OnyxTypes.ReportActions = {};
Expand Down