@@ -186,6 +186,7 @@ import {
186186 isSettled,
187187 isTestTransactionReport,
188188 isTrackExpenseReport,
189+ populateOptimisticReportFormula,
189190 prepareOnboardingOnyxData,
190191 shouldCreateNewMoneyRequestReport as shouldCreateNewMoneyRequestReportReportUtils,
191192 shouldEnableNegative,
@@ -3006,6 +3007,22 @@ function getDeleteTrackExpenseInformation(
30063007 return {parameters, optimisticData, successData, failureData, shouldDeleteTransactionThread, chatReport};
30073008}
30083009
3010+ /**
3011+ * Recalculates the report name using the policy's custom title formula.
3012+ * This is needed when report totals change (e.g., adding expenses or changing reimbursable status)
3013+ * to ensure the report title reflects the updated values like {report:reimbursable}.
3014+ */
3015+ function recalculateOptimisticReportName(iouReport: OnyxTypes.Report, policy: OnyxEntry<OnyxTypes.Policy>): string | undefined {
3016+ if (!policy?.fieldList?.[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]) {
3017+ return undefined;
3018+ }
3019+ const titleFormula = policy.fieldList[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]?.defaultValue ?? '';
3020+ if (!titleFormula) {
3021+ return undefined;
3022+ }
3023+ return populateOptimisticReportFormula(titleFormula, iouReport as Parameters<typeof populateOptimisticReportFormula>[1], policy);
3024+ }
3025+
30093026/**
30103027 * 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
30113028 * it creates optimistic versions of them and uses those instead
@@ -3148,6 +3165,12 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
31483165 iouReport.nonReimbursableTotal = (iouReport.nonReimbursableTotal ?? 0) - amount;
31493166 }
31503167 }
3168+
3169+ // Recalculate reportName to reflect updated totals
3170+ const updatedReportName = recalculateOptimisticReportName(iouReport, policy);
3171+ if (updatedReportName) {
3172+ iouReport.reportName = updatedReportName;
3173+ }
31513174 }
31523175 if (typeof iouReport.unheldTotal === 'number') {
31533176 // Use newReportTotal in scenarios where the total is based on more than just the current transaction amount, and we need to override it manually
@@ -4260,6 +4283,12 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
42604283 updatedMoneyRequestReport.unheldNonReimbursableTotal += updatedTransaction.reimbursable ? -updatedTransaction.amount : updatedTransaction.amount;
42614284 }
42624285 }
4286+
4287+ // Recalculate reportName after all totals are updated
4288+ const updatedReportName = recalculateOptimisticReportName(updatedMoneyRequestReport, policy);
4289+ if (updatedReportName) {
4290+ updatedMoneyRequestReport.reportName = updatedReportName;
4291+ }
42634292 } else {
42644293 updatedMoneyRequestReport = updateIOUOwnerAndTotal(
42654294 iouReport,
0 commit comments