Skip to content

Expense - Tax amount does not update after merging expenses #85179

Closed

Description

@mitarachim

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.37-0
Reproducible in staging?: Yes
Reproducible in production?: N/A - new feature, doesn't exist in prod
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #83587
Email or phone of affected tester (no customers): sodinjsoijnisojodj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Enable Taxes
  • Create 5% and 10% tax rate.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create an expense with amount 100.00 and 5% tax.
  4. Create an expense with amount 200.00 and 10% tax.
  5. Open the expense with amount 200.00.
  6. Click Tax amount and change it to 10.00.
  7. Click More > Merge.
  8. Select the 100.00 expense > Continue.
  9. Select 100.00 amount and 10% tax rate.
  10. Click Continue and Merge expenses.
    → Merge confirm page shows 9.09 tax amount.
  11. Click Tax field.
  12. Click Save.

Expected Result:

After merging expenses, Tax amount will update to 9.09 as shown on confirm page in Step 10.

Actual Result:

After merging expenses, Tax amount remains as 10.00, which is not the same as confirm page in Step 10.
Tax amount 10.00 exceeds the tax limit which is 9.09.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7101715_1773364836280.8.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @dominictb

Activity

  1. added
    DeployBlockerCash
    Daily
    Bug
    DeployBlocker
    on Mar 13, 2026
  2. melvin-bot commented on Mar 13, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #83587

  3. melvin-bot commented on Mar 13, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  4. github-actions commented on Mar 13, 2026

    @github-actions
    Contributor

    👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  5. OSBotify commented on Mar 13, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #83587 - "[Merge] Merge tax rates v2" by @dominictb (High confidence)
    Related Issues: None

    Recommendation: REVERT

    This PR introduces a bug in the tax amount calculation when merging expenses. The fix would be straightforward but given the complexity of the merge tax logic, reverting is the safer approach to unblock the deploy.

    Labels: Removed DeployBlocker (this is a frontend bug, not a backend bug). Kept DeployBlockerCash as this blocks the App deploy.

    Detailed Analysis

    Evidence

    PR #83587 was identified by melvin-bot as the causing PR and adds tax rate merging functionality. The bug occurs specifically when:

    1. Two expenses are merged with different amounts and tax rates
    2. User selects an amount during the merge process
    3. The tax amount should be recalculated based on the selected amount and tax rate
    4. Instead, the tax amount is calculated incorrectly

    Verification

    The PR modifies the following key files related to tax calculation during merges:

    • src/libs/MergeTransactionUtils.ts - Core merge logic
    • src/libs/actions/MergeTransaction.ts - Merge action handler
    • src/pages/TransactionMerge/DetailsReviewPage.tsx - UI for reviewing merge details

    Confirmed that PR #83587 modifies src/libs/MergeTransactionUtils.ts where the tax calculation logic resides.

    Root Cause

    In src/libs/MergeTransactionUtils.ts, the getMergeFieldUpdatedValues function has a bug when handling the amount field selection (around line 606-610 in the PR diff):

    if (field === 'amount') {
        updatedValues.currency = getCurrency(transaction);
        if (mergeTransaction?.taxValue && transaction?.amount) {
            updatedValues.taxAmount = convertToBackendAmount(
                calculateTaxAmount(mergeTransaction?.taxValue, transaction.amount, ...)
            );
        }
    }

    The issue is that it uses transaction.amount (the amount from the specific transaction object being processed) instead of using the actual selected amount value (fieldValue) that will be applied to the merged transaction. This causes the tax amount to be calculated based on the wrong base amount.

    In the reproduction scenario:

    • Expense 1: 100.00 with 5% tax
    • Expense 2: 200.00 with 10% tax (manually set to 10.00)
    • When merging and selecting 100.00 amount + 10% tax rate
    • Expected: Tax should be recalculated to 9.09 (100.00 * 10%)
    • Actual: Tax uses 200.00 (from transaction.amount) instead of 100.00 (the selected amount)

    When the user then clicks on the Tax field and clicks Save without making changes, the UI displays the old incorrect tax amount (10.00). Since it matches what is stored in the transaction, no update occurs even though the correct calculated tax amount should be 9.09.

    The same pattern is handled correctly in the taxValue field handler, where it uses mergeTransaction.amount for the calculation, showing the inconsistency in the implementation.

  6. removed
    DeployBlocker
    on Mar 13, 2026
  7. MelvinBot commented on Mar 13, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When merging two expenses with different tax rates, the merge confirmation page correctly shows the recalculated tax amount (e.g., 9.09 for $100.00 at 10% tax-inclusive), but after confirming the merge, the tax amount reverts to the old value (10.00) from the source expense rather than updating to the recalculated value.

    What is the root cause of that problem?

    The mergeTransactionRequest function in src/libs/actions/MergeTransaction.ts:341-364 builds the API params sent to the backend but omits both taxAmount and taxValue from the params object. It sends taxCode and taxPolicyID but not the recalculated tax amount.

    The full data flow:

    1. When the user selects a tax rate or amount during the merge flow, getMergeFieldUpdatedValues in src/libs/MergeTransactionUtils.ts:636-642 correctly recalculates taxAmount using calculateTaxAmount() and stores it in the mergeTransaction Onyx store.
    2. The confirmation page reads mergeTransaction.taxAmount via buildMergedTransactionData() and correctly displays 9.09.
    3. The optimistic update also correctly sets the recalculated taxAmount on the transaction temporarily.
    4. However, the API params object at MergeTransaction.ts:341-364 never includes taxAmount or taxValue — so the backend never receives the recalculated tax amount.
    5. When the server processes the merge and responds, it overwrites the optimistic data, reverting the tax amount to the old value (10.00).

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

    Add taxAmount and taxValue to the API params in mergeTransactionRequest() at src/libs/actions/MergeTransaction.ts:341-364:

    • Add taxAmount: mergeTransaction.taxAmount to the params object
    • Add taxValue: mergeTransaction.taxValue to the params object

    Also update MergeTransactionParams at src/libs/API/parameters/MergeTransactionParams.ts to include taxAmount and taxValue in the type definition (and ideally also the other fields that are sent at runtime but missing from the type: amount, currency, taxCode, taxPolicyID, reportID).

    What alternative solutions did you explore? (Optional)

    An alternative would be to have the backend recalculate taxAmount from the taxCode + amount it already receives, but this is riskier because:

    • The backend calculation might differ from the frontend's calculateTaxAmount() (tax-inclusive extraction)
    • Sending the explicit value from the frontend ensures consistency with what was shown on the confirmation page

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  8. 3 remaining items

  9. dominictb commented on Mar 13, 2026

    @dominictb
    Contributor

    I think the culprit is here

  10. dominictb commented on Mar 13, 2026

    @dominictb
    Contributor
  11. added
    Reviewing
    on Mar 13, 2026
  12. luacmartins commented on Mar 13, 2026

    @luacmartins
    Contributor

    @dominictb is there a FE PR that's exposing this option in App? It seems like we have quite a few blockers related to tax and merged expenses, so we might need to revert that to continue with App deploy

  13. luacmartins commented on Mar 13, 2026

    @luacmartins
    Contributor

    We can demote this. The user can refresh the page to get the updated result and the fix is in Auth

  14. removed
    DeployBlockerCash
    on Mar 13, 2026
  15. self-assigned this
    on Mar 16, 2026
  16. added
    Daily
    and removed
    Hourly
    on Mar 16, 2026
  17. luacmartins commented on Mar 17, 2026

    @luacmartins
    Contributor

    BE PR is merged

  18. luacmartins commented on Mar 18, 2026

    @luacmartins
    Contributor

    @dominictb can you retest this one to confirm the fix please?

  19. dominictb commented on Mar 19, 2026

    @dominictb
    Contributor

    Fixed on prod:

    Screen.Recording.2026-03-19.at.10.31.12-compressed.mov
  20. removed
    Reviewing
    on Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDailyEngineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions