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
7 changes: 4 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import {
} from '@libs/NextStepUtils';
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
import {handleUnvalidatedAccount, selectPaymentType} from '@libs/PaymentUtils';
import {getConnectedIntegration, getValidConnectedIntegration, hasDynamicExternalWorkflow, sortPoliciesByName} from '@libs/PolicyUtils';
import {getConnectedIntegration, getValidConnectedIntegration, hasDynamicExternalWorkflow, isPolicyAccessible, sortPoliciesByName} from '@libs/PolicyUtils';
import {
getFilteredReportActionsForReportView,
getIOUActionForReportID,
Expand Down Expand Up @@ -1931,8 +1931,9 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
temporarilyDisableDuplicateReportAction();
wasDuplicateReportTriggered.current = true;

const targetPolicyForDuplicate = policy ?? defaultExpensePolicy;
const targetChatForDuplicate = policy ? chatReport : activePolicyExpenseChat;
const isSourcePolicyValid = !!policy && isPolicyAccessible(policy, currentUserLogin ?? '');
const targetPolicyForDuplicate = isSourcePolicyValid ? policy : defaultExpensePolicy;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve distance/per-diem rows when rerouting deleted-workspace copies

When policy is inaccessible we now reroute the duplicate into defaultExpensePolicy, which makes duplicateReport() treat every deleted-workspace copy as cross-workspace. In src/libs/actions/IOU/Duplicate.ts:846-847, cross-workspace duplication drops all distance and per-diem transactions, so a deleted-workspace report containing those expenses will still duplicate as an empty/partial report instead of preserving its contents. This only affects deleted-workspace reports with distance or per-diem items, but it leaves that workflow broken.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to find a reason for the logic below, but it seems really weird and I couldn’t find any references. @hungvu193 Do you remember anything about this?

if (isCrossWorkspace && (isPerDiemRequest(transaction) || isDistanceRequest(transaction))) {
return false;
}

cc: @Valforte

@hungvu193 hungvu193 Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess when it's cross workspace, they have different rate, mileage/custom units...etc, so you filtered it out? @Krishna2323

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so but can't recall 😭

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That filter makes sense with what @hungvu193 commented. There's also the issue that Per diem, distance and time can be disable in the workspace. What happens if the user tries to duplicate and there are different rates? Will the original rate be used or the rate of the target workspace? If it's the second I believe we can allow the duplication.

const targetChatForDuplicate = isSourcePolicyValid ? chatReport : activePolicyExpenseChat;
Comment thread
Krishna2323 marked this conversation as resolved.
Resolved
const activePolicyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${targetPolicyForDuplicate?.id}`] ?? {};

// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand Down
3 changes: 3 additions & 0 deletions src/libs/API/parameters/CreateDistanceRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type CreateDistanceRequestParams = {
odometerEnd?: number;
gpsCoordinates?: string;
customUnitPolicyID?: string;

/** When true, the backend defers auto-submit so batch expense creation (e.g. duplicate report) can finish before the report is submitted */
shouldDeferAutoSubmit?: boolean;
};

export default CreateDistanceRequestParams;
3 changes: 3 additions & 0 deletions src/libs/API/parameters/CreatePerDiemRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type CreatePerDiemRequestParams = {
reimbursable?: boolean;
attendees?: string;
customUnitPolicyID?: string;

/** When true, the backend defers auto-submit so batch expense creation (e.g. duplicate report) can finish before the report is submitted */
shouldDeferAutoSubmit?: boolean;
};

export default CreatePerDiemRequestParams;
3 changes: 3 additions & 0 deletions src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type RequestMoneyParams = {

/** Unit for time tracking (e.g., 'h' for hours) */
unit?: ValueOf<typeof CONST.TIME_TRACKING.UNIT>;

/** When true, the backend defers auto-submit so batch expense creation (e.g. duplicate report) can finish before the report is submitted */
shouldDeferAutoSubmit?: boolean;
};

export default RequestMoneyParams;
12 changes: 9 additions & 3 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ function buildDuplicateTransactionParams(transaction: OnyxTypes.Transaction, tra
const transactionParams = {
...transactionWithoutLinkedAction,
...transactionDetails,
amount: Math.abs(transactionDetails?.amount ?? 0),
taxAmount: Math.abs(transactionDetails?.taxAmount ?? 0),
amount: transactionDetails?.amount ?? 0,
taxAmount: transactionDetails?.taxAmount ?? 0,
convertedAmount: undefined,
originalAmount: undefined,
actionableWhisperReportActionID: undefined,
Expand Down Expand Up @@ -861,12 +861,17 @@ function duplicateReport({

let currentIOUReport = newReport as OnyxEntry<OnyxTypes.Report>;

for (const transaction of eligibleTransactions) {
for (let i = 0; i < eligibleTransactions.length; i++) {
const transaction = eligibleTransactions.at(i);
if (!transaction) {
continue;
}
const transactionDetails = getTransactionDetails(transaction);
if (!transactionDetails) {
continue;
}

const isLastExpense = i === eligibleTransactions.length - 1;
const {transactionParams, waypoints} = buildDuplicateTransactionParams(transaction, transactionDetails);

const params: RequestMoneyInformation = {
Expand Down Expand Up @@ -896,6 +901,7 @@ function duplicateReport({
isSelfTourViewed,
betas,
personalDetails,
shouldDeferAutoSubmit: !isLastExpense,
};

const result = createExpenseByType({
Expand Down
3 changes: 3 additions & 0 deletions src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ type PerDiemExpenseInformation = {
shouldHandleNavigation?: boolean;
shouldPlaySound?: boolean;
optimisticReportPreviewActionID?: string;
shouldDeferAutoSubmit?: boolean;
};

type PerDiemExpenseInformationParams = {
Expand Down Expand Up @@ -903,6 +904,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
shouldHandleNavigation = true,
shouldPlaySound: shouldPlaySoundParam = true,
optimisticReportPreviewActionID,
shouldDeferAutoSubmit,
} = submitPerDiemExpenseInformation;
const {payeeAccountID} = participantParams;
const {currency, comment = '', category, tag, created, customUnit, attendees, isFromGlobalCreate} = transactionParams;
Expand Down Expand Up @@ -990,6 +992,7 @@ function submitPerDiemExpense(submitPerDiemExpenseInformation: PerDiemExpenseInf
reimbursable,
attendees: attendees ? JSON.stringify(attendees) : undefined,
customUnitPolicyID,
shouldDeferAutoSubmit,
};

if (shouldPlaySoundParam) {
Expand Down
6 changes: 6 additions & 0 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
import type {Comment, Receipt, ReceiptSource, Routes, SplitShares, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
import type {FileObject} from '@src/types/utils/Attachment';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {resolveDetachReceiptConflicts} from '../RequestConflictUtils';

Check warning on line 263 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected parent import '../RequestConflictUtils'. Use '@userActions/RequestConflictUtils' instead

type IOURequestType = ValueOf<typeof CONST.IOU.REQUEST_TYPE>;

Expand Down Expand Up @@ -537,6 +537,7 @@
isSelfTourViewed: boolean;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
shouldDeferAutoSubmit?: boolean;
};

type MoneyRequestInformationParams = {
Expand Down Expand Up @@ -649,6 +650,7 @@
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
betas: OnyxEntry<OnyxTypes.Beta[]>;
optimisticReportPreviewActionID?: string;
shouldDeferAutoSubmit?: boolean;
};

type CreateSplitsTransactionParams = Omit<BaseTransactionParams, 'customUnitRateID'> & {
Expand Down Expand Up @@ -778,7 +780,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 783 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -911,7 +913,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 916 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -925,7 +927,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 930 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -934,7 +936,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 939 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -948,7 +950,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 953 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -961,7 +963,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 966 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -970,7 +972,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 975 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -980,7 +982,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 985 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -989,7 +991,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 994 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -6301,6 +6303,7 @@
isSelfTourViewed,
betas,
personalDetails,
shouldDeferAutoSubmit,
} = requestMoneyInformation;
const {payeeAccountID} = participantParams;
const parsedComment = getParsedComment(transactionParams.comment ?? '');
Expand Down Expand Up @@ -6521,6 +6524,7 @@
unit,
}
: {}),
shouldDeferAutoSubmit,
};
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.write(WRITE_COMMANDS.REQUEST_MONEY, parameters, onyxData);
Expand Down Expand Up @@ -7533,6 +7537,7 @@
personalDetails,
betas,
optimisticReportPreviewActionID,
shouldDeferAutoSubmit,
} = distanceRequestInformation;
const {policy, policyCategories, policyTagList, policyRecentlyUsedCategories, policyRecentlyUsedTags} = policyParams;
const parsedComment = getParsedComment(transactionParams.comment);
Expand Down Expand Up @@ -7762,6 +7767,7 @@
description: parsedComment,
attendees: attendees ? JSON.stringify(attendees) : undefined,
gpsCoordinates,
shouldDeferAutoSubmit,
};
}

Expand Down
Loading