Skip to content
12 changes: 8 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6672,16 +6672,17 @@ function buildOptimisticExpenseReport(
nonReimbursableTotal = 0,
parentReportActionID?: string,
optimisticIOUReportID?: string,
reportPolicy?: OnyxEntry<Policy>,
): OptimisticExpenseReport {
// The amount for Expense reports are stored as negative value in the database
const storedTotal = total * -1;
const storedNonReimbursableTotal = nonReimbursableTotal * -1;
const report = chatReportID ? getReportOrDraftReport(chatReportID) : undefined;
const policyName = getPolicyName({report});
const policyName = reportPolicy?.name ?? getPolicyName({report});
const formattedTotal = convertToDisplayString(storedTotal, currency);
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policyReal = getPolicy(policyID);
const policyReal = reportPolicy ?? getPolicy(policyID);
const policyDraft = allPolicyDrafts?.[`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`];
const policy = policyReal ?? policyDraft;

Expand Down Expand Up @@ -6721,8 +6722,11 @@ function buildOptimisticExpenseReport(
expenseReport.managerID = submitToAccountID;
}

const titleReportField = getTitleReportField(getReportFieldsByPolicyID(policyID) ?? {});
if (!!titleReportField && isGroupPolicy(policy?.type ?? '')) {
const titleReportField = getTitleReportField(policy?.fieldList ?? {});
if (!!titleReportField && isPaidGroupPolicyPolicyUtils(policy)) {
expenseReport.reportName = populateOptimisticReportFormula(titleReportField.defaultValue, expenseReport, policy);
}
if (!!titleReportField && isPaidGroupPolicyExpenseReport(expenseReport)) {
expenseReport.reportName = populateOptimisticReportFormula(titleReportField.defaultValue, expenseReport, policy);
}

Expand Down