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
1 change: 1 addition & 0 deletions src/pages/Search/SearchTransactionsChangeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function SearchTransactionsChangeReport() {
isEditing
isUnreported={areAllTransactionsUnreported}
targetOwnerAccountID={targetOwnerAccountID}
transactionPolicyID={selectedReportPolicyID}
isPerDiemRequest={hasPerDiemTransactions}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestEditReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {

const hasPerDiemTransactions = useHasPerDiemTransactions(transactionIDs);

const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions, undefined, selectedReport?.policyID);
const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions, undefined, undefined);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined;
Expand Down
9 changes: 4 additions & 5 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ function IOURequestEditReportCommon({
return currentUserPersonalDetails.accountID;
}, [targetOwnerAccountID, selectedReport?.ownerAccountID, currentUserPersonalDetails.accountID]);
const reportPolicy = usePolicy(selectedReport?.policyID);
// Pass the expense's policyID so that the "Create report" button shows the correct workspace
// instead of defaulting to the user's active workspace
// we need to fall back to transactionPolicyID because for a new workspace there is no report created yet
// and if we choose this workspace as participant we want to create a new report in the chosen workspace
const {policyForMovingExpenses} = usePolicyForMovingExpenses(isPerDiemRequest, isTimeRequest, selectedReport?.policyID ?? transactionPolicyID);
// Use the caller-provided transactionPolicyID so that the "Create report" button shows the correct workspace.
// Each caller is responsible for passing the appropriate policyID (e.g., selectedReport?.policyID ?? transactionPolicyID).
// When no transactionPolicyID is provided (e.g., from IOURequestEditReport), the hook falls back to the user's default workspace.
const {policyForMovingExpenses} = usePolicyForMovingExpenses(isPerDiemRequest, isTimeRequest, transactionPolicyID);
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 per-diem source policy when resolving create-report workspace

Using only transactionPolicyID here regresses the IOURequestEditReport per-diem flow, because that caller now passes undefined while createReportForPolicy still creates the new report in selectedReportPolicy. In that case, IOURequestEditReportCommon validates per-diem moves against the active/default workspace instead of the actual destination policy, so users with multiple workspaces can see the wrong workspace label and may be blocked by the per-diem warning modal even though creating in the source workspace would be valid.

Useful? React with 👍 / 👎.

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.

@MelvinBot please check this comment

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 investigated this comment and it's valid — there is a real mismatch in the per-diem flow introduced by this PR.

The problem

For per-diem transactions in IOURequestEditReport:

  1. Display & validation (IOURequestEditReportCommon): usePolicyForMovingExpenses receives undefined as transactionPolicyID → falls back to the user's default/active workspace.
  2. Report creation (IOURequestEditReport line 121): createReportForPolicy uses selectedReportPolicy (the source workspace):
    const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;

Concrete scenario

User has per-diem expenses on workspace B (non-default), default workspace is A:

  • Create report button shows workspace A's name (wrong)
  • Per-diem validation checks workspace A's custom units
  • Report is actually created in workspace B
  • If workspace A lacks matching per-diem custom unit IDs, the warning modal blocks the user even though creating in workspace B would be valid

Why it regressed

Before this PR, IOURequestEditReportCommon used selectedReport?.policyID ?? transactionPolicyID, which resolved to the source workspace — keeping display, validation, and creation aligned. The PR removed this fallback, breaking consistency for the per-diem path.

Suggested fix

Either:

  • Pass selectedReport?.policyID as transactionPolicyID from IOURequestEditReport to IOURequestEditReportCommon (so the common component validates against the source workspace for per-diem)
  • Or update createReportForPolicy in IOURequestEditReport to also use the default workspace for per-diem, matching the new validation behavior


const [perDiemWarningModalVisible, setPerDiemWarningModalVisible] = useState(false);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
transactionIDs={transaction ? [transaction.transactionID] : []}
selectedReportID={selectedReportID}
selectedPolicyID={selectedPolicyID}
transactionPolicyID={transactionPolicyID}
transactionPolicyID={selectedReport?.policyID ?? transactionPolicyID}
removeFromReport={removeFromReport}
isEditing={isEditing}
isUnreported={isUnreported}
Expand Down
Loading