@@ -193,6 +193,7 @@ import {
193193 isSettled,
194194 isTestTransactionReport,
195195 isTrackExpenseReport,
196+ populateOptimisticReportFormula,
196197 prepareOnboardingOnyxData,
197198 shouldCreateNewMoneyRequestReport as shouldCreateNewMoneyRequestReportReportUtils,
198199 shouldEnableNegative,
@@ -2890,6 +2891,22 @@ function getDeleteTrackExpenseInformation(
28902891 return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport};
28912892}
28922893
2894+ /**
2895+ * Recalculates the report name using the policy's custom title formula.
2896+ * This is needed when report totals change (e.g., adding expenses or changing reimbursable status)
2897+ * to ensure the report title reflects the updated values like {report:reimbursable}.
2898+ */
2899+ function recalculateOptimisticReportName(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>): string | undefined {
2900+ if (!policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]) {
2901+ return undefined;
2902+ }
2903+ const titleFormula = policy.fieldList[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.defaultValue ?? '';
2904+ if (!titleFormula) {
2905+ return undefined;
2906+ }
2907+ return populateOptimisticReportFormula(titleFormula, iouReport as Parameters<typeof populateOptimisticReportFormula>[1], policy);
2908+ }
2909+
28932910/**
28942911 * 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
28952912 * it creates optimistic versions of them and uses those instead
@@ -3011,6 +3028,12 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
30113028 iouReport.nonReimbursableTotal = (iouReport.nonReimbursableTotal ?? 0) - amount;
30123029 }
30133030 }
3031+
3032+ // Recalculate reportName to reflect updated totals
3033+ const updatedReportName = recalculateOptimisticReportName(iouReport, policy);
3034+ if (updatedReportName) {
3035+ iouReport.reportName = updatedReportName;
3036+ }
30143037 }
30153038 if (typeof iouReport.unheldTotal === 'number') {
30163039 // Use newReportTotal in scenarios where the total is based on more than just the current transaction amount, and we need to override it manually
@@ -4075,6 +4098,12 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
40754098 updatedMoneyRequestReport.unheldNonReimbursableTotal += updatedTransaction.reimbursable ? -updatedTransaction.amount : updatedTransaction.amount;
40764099 }
40774100 }
4101+
4102+ // Recalculate reportName after all totals are updated
4103+ const updatedReportName = recalculateOptimisticReportName(updatedMoneyRequestReport, policy);
4104+ if (updatedReportName) {
4105+ updatedMoneyRequestReport.reportName = updatedReportName;
4106+ }
40784107 } else {
40794108 updatedMoneyRequestReport = updateIOUOwnerAndTotal(
40804109 iouReport,
0 commit comments