Skip to content

[Due for payment 2026-07-01] Per diem - Unable to move per diem to a new report after changing workspace #81307

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.11-25
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #80948
Email or phone of affected tester (no customers): sdjosdjnosjnsodnjsoi@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.1 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Create two workspaces - A and B.
  • Workspace A has per diem rates.
  • Do not enable per diem feature on workspace B.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat A.
  3. Create a per diem expense.
  4. Open the per diem expense.
  5. Click More > Change workspace.
  6. Select workspace B.
  7. After moving per diem report to workspace B, create one more expense (any expense) in the same report.
  8. Select the per diem expense via checkbox.
  9. Click dropdown button > Move expense.
  10. Click Create report.

Expected Result:

The per diem expense will be moved to a new report.

Actual Result:

The per diem expense cannot be moved to a new report after changing workspace.
It disappears from the original report and reappears.
A new empty report is created in workspace chat B.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7065403_1770128473522.11.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    External
    Daily
    Bug
    on Feb 3, 2026
  2. added
    Help Wanted
    on Feb 3, 2026
  3. melvin-bot commented on Feb 3, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)

  4. melvin-bot commented on Feb 3, 2026

    @melvin-bot

    Triggered auto assignment to @johncschuster (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. daledah commented on Feb 3, 2026

    @daledah
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-04-28 04:26:54 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    The per diem expense cannot be moved to a new report after changing workspace.
    It disappears from the original report and reappears.
    A new empty report is created in workspace chat B.

    What is the root cause of that problem?

    The bug is in IOURequestEditReport.tsx, which handles the bulk "Move expense > Create report" flow (via checkbox selection).

    IOURequestEditReportCommon validates the "Create report" action against policyForMovingExpenses?.id — the per-diem-capable policy resolved by usePolicyForMovingExpenses (workspace A):

    const handleCreateReport = useCallback(() => {
    if (!validatePerDiemMove(policyForMovingExpenses?.id)) {
    return;
    }
    createReport?.();
    }, [validatePerDiemMove, policyForMovingExpenses?.id, createReport]);

    However, IOURequestEditReport.createReportForPolicy was creating the new report using selectedReportPolicy (workspace B, which does not support per diem):

    const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;

    This mismatch means:

    1. Validation passes using workspace A.
    2. An optimistic report is created in workspace B.
    3. selectReport is called with the synthetic item {value, keyForList} — missing policyID — so changeTransactionsReport receives policy: undefined.
    4. The backend rejects moving a workspace-A per diem transaction into a workspace-B report.
    5. The optimistic move rolls back, the expense reappears in the original report, and the empty workspace-B report remains.

    Additionally, the billing restriction check in createReport was using selectedReport?.policyID (workspace B) instead of policyForMovingExpensesID (workspace A) for per diem transactions, so restriction checks were applied against the wrong workspace.

    What changes do you think we should make in order to solve the problem?

    Fix IOURequestEditReport.tsx so that validation, report creation, billing restriction checks, and the optimistic move all use the same policy (policyForMovingExpenses):

    1. Create the new report with policyForMovingExpenses (not selectedReportPolicy):

    - const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;
    - const optimisticReport = createNewReport(..., policyForNewReport, ...);
    + const optimisticReport = createNewReport(..., policyForMovingExpenses, ...);

    2. Pass policyID in the synthetic list item so changeTransactionsReport receives the correct policy:

      selectReport(
          {
              value: optimisticReport.reportID,
              keyForList: optimisticReport.reportID,
    +         policyID: optimisticReport.policyID,
          },
          optimisticReport,
      );

    3. Use policyForMovingExpensesID for billing restriction checks:

    - const restrictionPolicyID = hasPerDiemTransactions ? selectedReport?.policyID : policyForMovingExpensesID;
    + const restrictionPolicyID = policyForMovingExpensesID;

    With these changes, the entire "Create report" flow — validation, report creation, and the changeTransactionsReport call — consistently uses workspace A (the per-diem-capable workspace), so the backend accepts the move and the expense is transferred successfully.

    What alternative solutions did you explore? (Optional)

    An alternative would be to pass selectedReport?.policyID to usePolicyForMovingExpenses via an expensePolicyID argument and let the hook resolve the correct per-diem-capable policy, then update createReportForPolicy accordingly. However, the proposed fix is more direct: it removes the selectedReportPolicy detour and ensures consistent policy usage throughout the entire "Create report" flow with minimal changes.

  6. twinkle-react commented on Feb 3, 2026

    @twinkle-react

    🚨 Edited by proposal-police: This proposal was edited at 2026-02-03 15:26:27 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Per-diem expenses created under a workspace where per-diem is enabled cannot be moved to a new report after the report is changed to a workspace where per-diem is disabled. The transaction disappears from the original report, a new empty report is created, and the per-diem transaction is not moved.

    What is the root cause of that problem?

    In this implementation, the earliest incorrect assumption is in src/libs/actions/Report/index.ts inside buildOptimisticChangePolicyData, where the code assumes that a transaction’s per-diem customUnitID remains valid after a report changes policy. The function updates report and currency fields but does not remap or clear transaction.comment.customUnit.customUnitID, which leaves per-diem transactions pointing to a custom unit from the source policy and directly causes the move to fail validation for the destination policy.

    What changes do you think we should make in order to solve the problem?

    Single invariant (exact)
    Guarantee: "After changeReportPolicy (optimistic or final) completes, every per-diem transaction in the moved report has transaction.comment.customUnit.customUnitID that is valid for the destination policy, or transaction.comment.customUnit is cleared when the destination policy does not support per-diem."

    Earliest incorrect assumption (first divergence)
    File: src/libs/actions/Report/index.ts
    Function: buildOptimisticChangePolicyData
    Assumption: Transactions' per-diem customUnitID remain valid after changing report policy; the function updates currency and convertedAmount but does not remap or clear comment.customUnit for per-diem transactions.

    Smallest shared-layer fix (owner layer)
    Modify buildOptimisticChangePolicyData in the same file to normalize per-diem comment.customUnit for each transaction in the report.
    If the destination policy supports per-diem and has a per-diem custom unit, remap the per-diem customUnitID to the destination customUnitID.
    If the destination policy does not support per-diem, or the transaction has a missing or fake ID, clear comment.customUnit.
    Skip the optimistic merge when no change is needed.

    Exact code delta and scope
    Files changed: src/libs/actions/Report/index.ts
    Function modified: buildOptimisticChangePolicyData
    Scope size: one file, one function, around 40 lines added, no new files.

    Add this import near the other imports at the top of the file.

    // File: src/libs/actions/Report/index.ts
    import {isPerDiemRequest as isPerDiemRequestUtil} from '@libs/TransactionUtils';

    Insert this block immediately after:

    const transactions = getReportTransactions(reportID);

    and before the existing convertedAmount logic inside buildOptimisticChangePolicyData.

    // File: src/libs/actions/Report/index.ts
    
    // 6a. Normalize per-diem transaction customUnit for the destination policy.
    // If destination supports per-diem, map to the destination per-diem custom unit.
    // If destination does not support per-diem, or transaction has missing/fake ID, clear the customUnit.
    
    const destinationHasPerDiem =
        !!policy?.arePerDiemRatesEnabled && !isEmpty(policy?.customUnits);
    
    const destinationPerDiemUnit = destinationHasPerDiem
        ? Object.values(policy.customUnits ?? {}).find(
              (unit) => unit.name === CONST.CUSTOM_UNITS.NAME_PER_DIEM_INTERNATIONAL,
          )
        : undefined;
    
    for (const transaction of transactions) {
        if (
            !transaction ||
            !isPerDiemRequestUtil(transaction) ||
            !transaction.comment?.customUnit
        ) {
            continue;
        }
    
        const currentCustomUnitID =
            transaction.comment?.customUnit?.customUnitID;
    
        const isFakeOrMissing =
            !currentCustomUnitID ||
            currentCustomUnitID === CONST.CUSTOM_UNITS.FAKE_P2P_ID;
    
        const shouldClear =
            !destinationHasPerDiem ||
            !destinationPerDiemUnit ||
            isFakeOrMissing;
    
        // No-op if already mapped to the destination per-diem unit
        if (
            !shouldClear &&
            currentCustomUnitID === destinationPerDiemUnit.customUnitID
        ) {
            continue;
        }
    
        const newCustomUnit = shouldClear
            ? null
            : {
                  ...(transaction.comment?.customUnit ?? {}),
                  customUnitID: destinationPerDiemUnit.customUnitID,
              };
    
        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
            value: {
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
                comment: {
                    ...(transaction.comment ?? {}),
                    customUnit: newCustomUnit,
                },
            },
        });
    
        successData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
            value: {
                pendingAction: null,
            },
        });
    
        // Preserve full original comment for rollback
        failureData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
            value: {
                pendingAction: transaction.pendingAction ?? null,
                comment: transaction.comment,
            },
        });
    }

    Note risk and ownership
    Owner: libs/actions/Report, which already owns report mutation and optimistic updates.
    Regression risk is low because the change follows existing optimistic and failure merge patterns in the same function and only affects the report policy change path for per-diem transactions.
    Rollback behavior is safe because failureData restores the original transaction.comment.
    A no-op guard avoids unnecessary Onyx writes.

    What to change (summary)
    Add the import line.
    Insert the per-diem normalization block immediately after const transactions = getReportTransactions(reportID);.
    Keep the change limited to buildOptimisticChangePolicyData in src/libs/actions/Report/index.ts.

    What alternative solutions did you explore? (Optional)

    Caller-side UI fixes were explored but rejected because they duplicate logic and do not correct inconsistent transaction data created during policy change.
    A backend-only fix would require API or data migrations and higher rollout risk, so it is better as a follow-up.
    UI-only workarounds that hide validation errors were rejected because they mask the real data issue.

  7. github-actions commented on Feb 3, 2026

    @github-actions
    Contributor

    ⚠️ @annaweber830 Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  8. annaweber830 commented on Feb 3, 2026

    @annaweber830
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    After changing a per diem report to a workspace that does not have per diem enabled, moving that per diem expense to a new report fails: the expense disappears then reappears, and the newly created report stays empty. We need the move flow to validate against the actual destination policy so we don't create an invalid report and rollback the transaction move.

    What is the root cause of that problem?

    The create-report flow for moving expenses uses the destination report's policy (the selected report's policy) for per diem transactions, but the per diem validation for “Create report” uses a different policy (derived from usePolicyForMovingExpenses and often pointing to the active workspace). After changing the report to a workspace without per diem, the validation still passes against the active policy, so the UI proceeds to create a new report in the destination policy that cannot accept the per diem custom unit; the server rejects the move and the optimistic update rolls back.

    const handleCreateReport = useCallback(() => {
    if (!validatePerDiemMove(policyForMovingExpenses?.id)) {
    return;
    }
    createReport?.();
    }, [validatePerDiemMove, policyForMovingExpenses?.id, createReport]);

    What changes do you think we should make in order to solve the problem?

    Align the per diem validation with the policy that will actually be used to create the destination report. For per diem moves, validate against the selected report’s policy ID (the same policy used by the create-report action), so we surface the per diem warning before creating an invalid report and avoid the rollback/empty-report behavior.

    const handleCreateReport = useCallback(() => {
    if (!validatePerDiemMove(policyForMovingExpenses?.id)) {
    return;
    }
    createReport?.();
    }, [validatePerDiemMove, policyForMovingExpenses?.id, createReport]);

    Updated code:

    const handleCreateReport = useCallback(() => {
        const destinationPolicyID = isPerDiemRequest ? selectedReport?.policyID : policyForMovingExpenses?.id;
        if (!validatePerDiemMove(destinationPolicyID)) {
            return;
        }
        createReport?.();
    }, [validatePerDiemMove, isPerDiemRequest, selectedReport?.policyID, policyForMovingExpenses?.id, createReport]);
    

    What alternative solutions did you explore? (Optional)

    • Blocking the workspace change for reports that contain per diem transactions when the destination workspace lacks per diem rates. This avoids the inconsistent state entirely, but is a broader behavior change and not limited to the move-expense flow.
  9. etCoderDysto commented on Feb 3, 2026

    @etCoderDysto
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-02-03 16:53:03 UTC.

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Users are unable to move a per diem expense to a new report after changing workspaces.

    What is the root cause of that problem?

    In IOURequestEditReportCommon.tsx, we call usePolicyForMovingExpenses to determine the policy the expense should be moved to. This policy is also displayed under the Create report title.

    const {policyForMovingExpenses} = usePolicyForMovingExpenses(isPerDiemRequest, selectedReport?.policyID);

    Inside usePolicyForMovingExpenses, we check whether the policy where the current expense report lives is valid for moving expenses by calling isPolicyValidForMovingExpenses. Within isPolicyValidForMovingExpenses, there is a canSubmitPerDiemExpenseFromWorkspace check. Since the current workspace (workspace B) does not have the per diem feature enabled, isPolicyValidForMovingExpenses returns false.

    if (expensePolicyID) {
    const expensePolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${expensePolicyID}`];
    if (expensePolicy && isPolicyValidForMovingExpenses(expensePolicy, login, isPerDiemRequest)) {
    return {policyForMovingExpensesID: expensePolicyID, policyForMovingExpenses: expensePolicy, shouldSelectPolicy: false};
    }

    We then check whether the user can submit a per diem expense to the current active policy. If so, we return the current active policy that has the per diem feature enabled (workspace A). As a result, workspace A is displayed under the Create report button.

    if (activePolicy && (!isPerDiemRequest || canSubmitPerDiemExpenseFromWorkspace(activePolicy))) {
    return {policyForMovingExpensesID: activePolicyID, policyForMovingExpenses: activePolicy, shouldSelectPolicy: false};
    }

    In summary, usePolicyForMovingExpenses checks whether the policy where the current report lives is valid for moving a per diem expense. If it is not valid, it returns the current active policy that has the per diem feature enabled. To determine where the current report lives, it uses the expensePolicyID parameter.

    However, in IOURequestEditReport.tsx, when the transaction is a per diem expense, we use selectedReportPolicy as the destination policy. selectedReportPolicy represents the policy where the current expense lives, which is workspace B (where the per diem feature is not enabled). Since we cannot move a per diem expense to a policy without the per diem feature, the backend returns an error. As a result, we revert the per diem expense state to its original state and move it back to a report in workspace B.

    What we should do instead is create a new report in workspace A (which has the per diem feature enabled) and move the expense there.

    const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;

    What changes do you think we should make in order to solve the problem?

    When hasPerDiemTransactions is true, we should move the expense to a policy that has the per diem feature enabled. policyForMovingExpenses is the active policy that has per diem feature enabled, and it is a result of usePolicyForMovingExpenses.

    const policyForNewReport = hasPerDiemTransactions ? policyForMovingExpenses : selectedReportPolicy;

    const policyForNewReport = hasPerDiemTransactions ? selectedReportPolicy : policyForMovingExpenses;

    What alternative solutions did you explore? (Optional)

    An alternative approach is to pass selectedReport?.policyID to usePolicyForMovingExpenses so it can determine the policy where the current expense lives. If that policy supports per diem expenses, we will use it. if the policy doesn't have per diem feature, usePolicyForMovingExpenses will return the active policy that has a per diem feature enabled which is workspace A.

    const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(
        hasPerDiemTransactions,
        selectedReport?.policyID,
    );

    const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions);

    We can then use policyForMovingExpenses directly as the destination policy:

    const optimisticReport = createNewReport(
        ownerPersonalDetails,
        hasViolations,
        isASAPSubmitBetaEnabled,
        policyForMovingExpenses,
        false,
        shouldDismissEmptyReportsConfirmation,
    );

    const optimisticReport = createNewReport(ownerPersonalDetails, hasViolations, isASAPSubmitBetaEnabled, policyForNewReport, false, shouldDismissEmptyReportsConfirmation);

    Note: this approach will mirror the same approach we are using IOURequestEditReportCommon.tsx

    const {policyForMovingExpenses} = usePolicyForMovingExpenses(isPerDiemRequest, selectedReport?.policyID);

    Alternative solution 2
    We can filter out policy that doesn't have perdiem feature when we change the workspace of a per diem expense in step 5

    const {data, shouldShowNoResultsFoundMessage, shouldShowSearchInput} = useWorkspaceList({

    Result Video
    Screen.Recording.2026-02-03.at.9.56.22.at.night.mp4
  10. etCoderDysto commented on Feb 13, 2026

    @etCoderDysto
    Contributor

    Hi @abdulrahuman5196, I think Melvin automation is failing here - it is not commenting on the issue to move it forward.

  11. 61 remaining items

  12. madmax330 commented on Jun 30, 2026

    @madmax330
    Contributor

    LGTM

  13. added
    Daily
    Awaiting Payment
    and removed
    Weekly
    on Jun 30, 2026
  14. melvin-bot commented on Jun 30, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  15. melvin-bot commented on Jun 30, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants//hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  16. mallenexpensify commented on Jul 2, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @daledah due $250 via NewDot
    Contributor+: @abdulrahuman5196 due $250 via NewDot

    ^ Test case created. Thx

  17. laurenreidexpensify commented on Jul 6, 2026

    @laurenreidexpensify
    Contributor

    $250 approved for @abdulrahuman5196

  18. quinthar commented on Sep 26, 2026

    @quinthar
    Contributor

    Approved $250 to @daledah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions