Skip to content

[Awaiting checklist completion] [Splits in NewDot] [$250] Expense - Card expense splits appear as cash expense when split offline #72395

Closed

Description

@jponikarchuk

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.2.29-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/TR-1235/41237176/945414899?q=split&issue_type=jira
Email or phone of affected tester (no customers): applausetester+101001kh@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Mac 15.5 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Workspace has card transactions.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Open the card transaction.
  4. Go offline.
  5. Click More > Split.
  6. Click Save.
  7. Open the split.
    → The split appears as cash instead of card expense when card transaction is split offline. Amount field shows Cash. Card field is missing.
  8. Go online.
    → The split becomes card transaction after returning online.

Expected Result:

In Step 7, when card expense is split offline, the transaction thread of the split will show the same card details as the original card expense.

Actual Result:

In Step 7, when card expense is split offline, the transaction thread of the split does not show the same card details as the original card expense.
Amount field shows Cash.
Card field is missing. It shows Reimbursable toggle instead of Card field.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021977721126903414051
  • Upwork Job ID: 1977721126903414051
  • Last Price Increase: 2025-10-20
  • Automatic offers:
    • nkdengineer | Contributor | 109184708
Issue OwnerCurrent Issue Owner: @hoangzinh

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 12, 2025
  2. melvin-bot commented on Oct 12, 2025

    @melvin-bot

    Triggered auto assignment to @twisterdotcom (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.

  3. abzokhattab commented on Oct 12, 2025

    @abzokhattab
    Contributor

    Proposal

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

    When splitting a card expense while offline, the split transactions incorrectly appear as cash expenses instead of preserving the card transaction type.

    What is the root cause of that problem?

    The buildOptimisticTransaction function does not preserve card-related fields (managedCard, cardName, cardID, bank, cardNumber, posted) from the existingTransaction when creating new optimistic transactions for splits. This causes split transactions to lose their card transaction properties and appear as cash expenses.

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

    File: src/libs/TransactionUtils/index.ts

    In the buildOptimisticTransaction function:

    • Check if existingTransaction?.managedCard is truthy to identify card transactions
    • If true, extract and preserve the card-related fields: bank, cardName, cardNumber, managedCard, cardID, and posted

    so we should modify the return to:

        const cardFields = existingTransaction?.managedCard
            ? {
                  bank: existingTransaction.bank,
                  cardName: existingTransaction.cardName,
                  cardNumber: existingTransaction.cardNumber,
                  managedCard: existingTransaction.managedCard,
                  cardID: existingTransaction.cardID,
                  posted: existingTransaction.posted,
                  reimbursable: existingTransaction.reimbursable,// optionally
    
              }
            : {};
    
        return {
            ...(!isEmptyObject(pendingFields) ? {pendingFields} : {}),
            transactionID,
            amount,
            currency,
            reportID,
            comment: commentJSON,
            merchant: merchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
            created: created || DateUtils.getDBTime(),
            pendingAction,
            receipt: receipt?.source
                ? {source: receipt.source, filename: receipt?.name ?? filename, state: receipt.state ?? CONST.IOU.RECEIPT_STATE.SCAN_READY, isTestDriveReceipt: receipt.isTestDriveReceipt}
                : {},
            filename: (receipt?.source ? (receipt?.name ?? filename) : filename).toString(),
            category,
            tag,
            taxCode,
            taxAmount,
            modifiedAmount,
            billable,
            reimbursable,
            inserted: DateUtils.getDBTime(),
            participants,
            ...cardFields,

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    in the TransactionUtilsTest file, Add test cases to verify:

    • Card-related fields are preserved when building an optimistic transaction from an existing card transaction
    • Card fields are not added when building from a non-card (cash) transaction
    code changes
        describe('buildOptimisticTransaction', () => {
            it('should preserve card-related fields from existing card transaction', () => {
                // Create an existing card transaction with card-related fields
                const existingCardTransaction: Transaction = {
                    ...generateTransaction(),
                    managedCard: true,
                    bank: 'expensify',
                    cardName: 'Test Card',
                    cardNumber: '1234',
                    cardID: 123,
                    posted: '2023-10-01',
                };
    
                // Build a new optimistic transaction based on the existing card transaction
                const newTransaction = TransactionUtils.buildOptimisticTransaction({
                    existingTransaction: existingCardTransaction,
                    transactionParams: {
                        amount: 200,
                        currency: 'USD',
                        reportID: '1',
                        comment: 'Test split',
                        attendees: [],
                        created: '2023-10-02',
                    },
                });
    
                // Verify that card-related fields are preserved
                expect(newTransaction.managedCard).toBe(true);
                expect(newTransaction.bank).toBe('expensify');
                expect(newTransaction.cardName).toBe('Test Card');
                expect(newTransaction.cardNumber).toBe('1234');
                expect(newTransaction.cardID).toBe(123);
                expect(newTransaction.posted).toBe('2023-10-01');
            });
    
            it('should not add card fields if existing transaction is not a card transaction', () => {
                // Create an existing cash transaction without card-related fields
                const existingCashTransaction: Transaction = {
                    ...generateTransaction(),
                };
    
                // Build a new optimistic transaction based on the existing cash transaction
                const newTransaction = TransactionUtils.buildOptimisticTransaction({
                    existingTransaction: existingCashTransaction,
                    transactionParams: {
                        amount: 200,
                        currency: 'USD',
                        reportID: '1',
                        comment: 'Test split',
                        attendees: [],
                        created: '2023-10-02',
                    },
                });
    
                // Verify that card-related fields are not present
                expect(newTransaction.managedCard).toBeUndefined();
                expect(newTransaction.bank).toBeUndefined();
                expect(newTransaction.cardName).toBeUndefined();
                expect(newTransaction.cardNumber).toBeUndefined();
                expect(newTransaction.cardID).toBeUndefined();
                expect(newTransaction.posted).toBeUndefined();
            });
        });

    What alternative solutions did you explore? (Optional)

    NA

  4. nkdengineer commented on Oct 13, 2025

    @nkdengineer
    Contributor

    Proposal

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

    In Step 7, when card expense is split offline, the transaction thread of the split does not show the same card details as the original card expense.
    Amount field shows Cash.
    Card field is missing. It shows Reimbursable toggle instead of Card field.

    What is the root cause of that problem?

    The optimistic transaction doesn't include the card expense data from existingTransaction. We have the logic to merge the existingTransaction with optimisticTransaction here, but it's only applied for distance requests.

    App/src/libs/actions/IOU.ts

    Lines 3530 to 3540 in 89c45c9

    if (isDistanceRequest) {
    optimisticTransaction = fastMerge(existingTransaction, optimisticTransaction, false);
    }
    // STEP 4: Build optimistic reportActions. We need:
    // 1. CREATED action for the chatReport
    // 2. CREATED action for the iouReport
    // 3. IOU action for the iouReport
    // 4. The transaction thread, which requires the iouAction, and CREATED action for the transaction thread
    // 5. REPORT_PREVIEW action for the chatReport
    // Note: The CREATED action for the IOU report must be optimistically generated before the IOU action so there's no chance that it appears after the IOU action in the chat

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

    We should also merge the existingTransaction with optimisticTransaction if we're splitting the expense

    if ((!!isSplitExpense || isDistanceRequest) && existingTransaction) {
        optimisticTransaction = fastMerge(existingTransaction, optimisticTransaction, false);
    }
    

    App/src/libs/actions/IOU.ts

    Lines 3530 to 3540 in 89c45c9

    if (isDistanceRequest) {
    optimisticTransaction = fastMerge(existingTransaction, optimisticTransaction, false);
    }
    // STEP 4: Build optimistic reportActions. We need:
    // 1. CREATED action for the chatReport
    // 2. CREATED action for the iouReport
    // 3. IOU action for the iouReport
    // 4. The transaction thread, which requires the iouAction, and CREATED action for the transaction thread
    // 5. REPORT_PREVIEW action for the chatReport
    // Note: The CREATED action for the IOU report must be optimistically generated before the IOU action so there's no chance that it appears after the IOU action in the chat

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    Update saveSplitTransactions test to verify that the split transaction keeps the card data from the original transaction.

    What alternative solutions did you explore? (Optional)

    We can always merge existingTransaction with optimistic transaction data in buildOptimisticTransaction function

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 13, 2025
  6. changed the title [-]Expense - Card expense splits appear as cash expense when split offline[/-] [+][$250] Expense - Card expense splits appear as cash expense when split offline[/+] on Oct 13, 2025
  7. melvin-bot commented on Oct 13, 2025

    @melvin-bot
  8. twisterdotcom commented on Oct 13, 2025

    @twisterdotcom
    Contributor
  9. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 13, 2025
  10. melvin-bot commented on Oct 13, 2025

    @melvin-bot

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

  11. changed the title [-][$250] Expense - Card expense splits appear as cash expense when split offline[/-] [+][Splits in NewDot] [$250] Expense - Card expense splits appear as cash expense when split offline[/+] on Oct 13, 2025
  12. 24 remaining items

  13. twisterdotcom commented on Nov 5, 2025

    @twisterdotcom
    Contributor

    @hoangzinh please complete the checklist

  14. twisterdotcom commented on Nov 5, 2025

    @twisterdotcom
    Contributor

    Payment Summary:

  15. changed the title [-][Due for payment 2025-11-03] [Splits in NewDot] [$250] Expense - Card expense splits appear as cash expense when split offline[/-] [+][Awaiting checklist completion] [Splits in NewDot] [$250] Expense - Card expense splits appear as cash expense when split offline[/+] on Nov 5, 2025
  16. hoangzinh commented on Nov 6, 2025

    @hoangzinh
    Contributor

    BugZero Checklist:

    Regression Test Proposal

    Precondition:

    • Workspace has card transactions.

    Test:

    1. Go to workspace chat.
    2. Open the card transaction.
    3. Go offline.
    4. Click More > Split.
    5. Click Save.
    6. Open a split expense
    7. Verify that the transaction thread of the split will show the same card details as the original card expense.

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-ce18-a801-6dad-5b4788cd6841
  17. hoangzinh commented on Nov 6, 2025

    @hoangzinh
    Contributor

    Thanks @twisterdotcom. I requested in ND

  18. nkdengineer commented on Nov 7, 2025

    @nkdengineer
    Contributor

    @nkdengineer paid $250 here (Contributor)

    @twisterdotcom I get paid via NewDot now

  19. twisterdotcom commented on Nov 7, 2025

    @twisterdotcom
    Contributor

    @hoangzinh has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-fe00-a4db-a2da-f0c7ee41b561
  20. trjExpensify commented on Nov 7, 2025

    @trjExpensify
    Contributor

    I can indeed. Payment summary looks correct!

  21. JmillsExpensify commented on Dec 17, 2025

    @JmillsExpensify
    Contributor

    $250 approved for @nkdengineer

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions