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
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ function MoneyRequestView({
});

// eslint-disable-next-line @typescript-eslint/no-deprecated
const reportNameToDisplay = isFromMergeTransaction ? (updatedTransaction?.reportName ?? translate('common.none')) : (parentReport?.reportName ?? getReportName(parentReport));
const reportNameToDisplay = isFromMergeTransaction ? (updatedTransaction?.reportName ?? translate('common.none')) : getReportName(parentReport) || parentReport?.reportName;
const shouldShowReport = !!parentReportID || (isFromMergeTransaction && !!reportNameToDisplay);
const reportCopyValue = !canEditReport && reportNameToDisplay !== translate('common.none') ? reportNameToDisplay : undefined;
const shouldShowCategoryAnalyzing = isCategoryBeingAnalyzed(updatedTransaction ?? transaction);
Expand Down
6 changes: 0 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6615,19 +6615,13 @@ function populateOptimisticReportFormula(formula: string, report: OptimisticExpe

const createdDate = report.lastVisibleActionCreated ? new Date(report.lastVisibleActionCreated) : undefined;

const totalAmount = report.total !== undefined && !Number.isNaN(report.total) ? Math.abs(report.total) : 0;
const nonReimbursableTotal =
'nonReimbursableTotal' in report && report.nonReimbursableTotal !== undefined && !Number.isNaN(report.nonReimbursableTotal) ? Math.abs(report.nonReimbursableTotal) : 0;
const reimbursableAmount = totalAmount - nonReimbursableTotal;

const result = formula
// We don't translate because the server response is always in English
.replaceAll(/\{report:type\}/gi, 'Expense Report')
.replaceAll(/\{report:startdate\}/gi, createdDate ? format(createdDate, CONST.DATE.FNS_FORMAT_STRING) : '')
.replaceAll(/\{report:enddate\}/gi, createdDate ? format(createdDate, CONST.DATE.FNS_FORMAT_STRING) : '')
.replaceAll(/\{report:id\}/gi, getBase62ReportID(Number(report.reportID)))
.replaceAll(/\{report:total\}/gi, report.total !== undefined && !Number.isNaN(report.total) ? convertToDisplayString(Math.abs(report.total), report.currency).toString() : '')
.replaceAll(/\{report:reimbursable\}/gi, report.total !== undefined && !Number.isNaN(report.total) ? convertToDisplayString(reimbursableAmount, report.currency).toString() : '')
.replaceAll(/\{report:currency\}/gi, report.currency ?? '')
.replaceAll(/\{report:policyname\}/gi, policy?.name ?? '')
.replaceAll(/\{report:workspacename\}/gi, policy?.name ?? '')
Expand Down
29 changes: 0 additions & 29 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ import {
isSettled,
isTestTransactionReport,
isTrackExpenseReport,
populateOptimisticReportFormula,
prepareOnboardingOnyxData,
shouldCreateNewMoneyRequestReport as shouldCreateNewMoneyRequestReportReportUtils,
shouldEnableNegative,
Expand Down Expand Up @@ -2892,22 +2891,6 @@ function getDeleteTrackExpenseInformation(
return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport};
}

/**
* Recalculates the report name using the policy's custom title formula.
* This is needed when report totals change (e.g., adding expenses or changing reimbursable status)
* to ensure the report title reflects the updated values like {report:reimbursable}.
*/
function recalculateOptimisticReportName(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>): string | undefined {
if (!policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]) {
return undefined;
}
const titleFormula = policy.fieldList[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.defaultValue ?? '';
if (!titleFormula) {
return undefined;
}
return populateOptimisticReportFormula(titleFormula, iouReport as Parameters<typeof populateOptimisticReportFormula>[1], policy);
}

/**
* Gathers all the data needed to submit an expense. It attempts to find existing reports, iouReports, and receipts. If it doesn't find them, then
* it creates optimistic versions of them and uses those instead
Expand Down Expand Up @@ -3029,12 +3012,6 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
iouReport.nonReimbursableTotal = (iouReport.nonReimbursableTotal ?? 0) - amount;
}
}

// Recalculate reportName to reflect updated totals
const updatedReportName = recalculateOptimisticReportName(iouReport, policy);
if (updatedReportName) {
iouReport.reportName = updatedReportName;
}
}
if (typeof iouReport.unheldTotal === 'number') {
// Use newReportTotal in scenarios where the total is based on more than just the current transaction amount, and we need to override it manually
Expand Down Expand Up @@ -4099,12 +4076,6 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
updatedMoneyRequestReport.unheldNonReimbursableTotal += updatedTransaction.reimbursable ? -updatedTransaction.amount : updatedTransaction.amount;
}
}

// Recalculate reportName after all totals are updated
const updatedReportName = recalculateOptimisticReportName(updatedMoneyRequestReport, policy);
if (updatedReportName) {
updatedMoneyRequestReport.reportName = updatedReportName;
}
} else {
updatedMoneyRequestReport = updateIOUOwnerAndTotal(
iouReport,
Expand Down