⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@dominictb
Copy link
Contributor

@dominictb dominictb commented Sep 24, 2025

Explanation of Change

Enable users to select tax rate when merging expenses, auto-calculate tax amount.

Fixed Issues

$ #70058
PROPOSAL:

Tests

Test case 1: Merge in the same workspace with tax enabled

  1. Create a workspace with tax enabled and create a few different tax rates
  2. Create 2 expenses with the same tax rate to the same workspace
  3. Go to any of these expenses > More > Merge with the other expense
  4. In confirmation step, Verify the tax rate from step 1 is automatically selected
  5. Verify the tax amount is automatically calculated based on selected amount and selected tax rate
  6. Create 2 other expenses with different tax rates
  7. Go to any of these expenses > More > Merge with the other expense
  8. In review details step, Verify the tax rates of theses expenses are selectable
  9. In confirmation step, Verify the tax amount is automatically calculated based on selected amount and selected tax rate

Test case 2: Merge in different workspaces with tax enabled in both workspaces

  1. Repeat steps 1 - 10 with 2 expenses from different workspaces with tax enabled in both workspaces
  2. This can lead to tax rate violation if the selected tax rate does not exist in the destination workspace

Test case 3: Merge in different workspaces with tax enabled and tax disabled

  1. Verify:
  • In review details step, Tax field does not show (it's auto selected depending on destination report).

  • After merging:

    • If the destination report supports tax, the initial expense tax value is kept and tax amount is calculated based on that tax value and merged amount.
    • Otherwise, there's no tax.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2025-11-06.at.15.17.04.mov
Android: mWeb Chrome
Screen.Recording.2025-11-06.at.15.20.35.mov
iOS: Native
Screen.Recording.2025-11-06.at.15.09.13-compressed.mov
iOS: mWeb Safari
Screen.Recording.2025-11-06.at.15.12.26-compressed.mov
MacOS: Chrome / Safari

Test case 1 & 2:

Screen.Recording.2025-10-09.at.17.37.15-compressed.mov

Test case 3:

Screen.Recording.2025-10-17.at.02.49.32.mov
Screen.Recording.2025-10-17.at.02.48.35.mov
MacOS: Desktop
Screen.Recording.2025-11-06.at.15.25.52-compressed.mov

@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/hooks/useSelectedTransactionsActions.ts 82.35% <100.00%> (+0.10%) ⬆️
src/libs/DebugUtils.ts 68.63% <100.00%> (+0.06%) ⬆️
src/libs/TransactionUtils/index.ts 72.89% <100.00%> (+0.18%) ⬆️
src/pages/Search/SearchPage.tsx 23.50% <ø> (+0.52%) ⬆️
src/pages/TransactionMerge/ReceiptReviewPage.tsx 0.00% <0.00%> (ø)
src/libs/actions/MergeTransaction.ts 48.09% <80.00%> (+0.39%) ⬆️
.../TransactionMerge/MergeTransactionsListContent.tsx 0.00% <0.00%> (ø)
src/pages/TransactionMerge/ConfirmationPage.tsx 0.00% <0.00%> (ø)
src/hooks/useMergeTransactions.ts 0.00% <0.00%> (ø)
...c/components/ReportActionItem/MoneyRequestView.tsx 0.24% <0.00%> (ø)
... and 2 more
... and 31 files with indirect coverage changes

@dominictb dominictb marked this pull request as ready for review September 29, 2025 19:46
@dominictb dominictb requested a review from a team as a code owner September 29, 2025 19:46
@melvin-bot melvin-bot bot requested review from hoangzinh and removed request for a team September 29, 2025 19:46
@melvin-bot
Copy link

melvin-bot bot commented Sep 29, 2025

@hoangzinh Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@hoangzinh
Copy link
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

Comment on lines 166 to 167
const taxAmountInSmallestCurrencyUnits = convertToBackendAmount(Number.parseFloat(taxAmount.toString()));
return taxAmountInSmallestCurrencyUnits;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to convert taxAmount to a string, then parse it to a float? Besides that, I guess we can put this function into TransactionUtils to reuse later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied from here:

const taxAmount = calculateTaxAmount(taxPercentage, taxableAmount, transaction.currency);
const taxAmountInSmallestCurrencyUnits = convertToBackendAmount(Number.parseFloat(taxAmount.toString()));

But I think it's not needed. It was initially added because calculateTaxAmount previously did not handle floating-point precision.

const taxAmount = calculateTaxAmount(taxPercentage, taxableAmount, transaction.currency);
const taxAmountInSmallestCurrencyUnits = convertToBackendAmount(Number.parseFloat(taxAmount.toString()));

Just removed that conversion

@hoangzinh
Copy link
Contributor

@dominictb can you upload recordings for platform?

@dominictb
Copy link
Contributor Author

dominictb commented Oct 1, 2025

I'll add recordings later after implementing the changes that I'm asking Garett in #70058 (comment)

@trjExpensify
Copy link
Contributor

@dominictb, did you get that added? Can you add recordings, and @hoangzinh can you start review?

@hoangzinh
Copy link
Contributor

@trjExpensify I finished code review. Whenever @dominictb uploads his recordings, I will complete review checklist

@dominictb
Copy link
Contributor Author

Clarifying some points in the issue thread #70058

@dominictb
Copy link
Contributor Author

BUG: Tax is not saved if I initiate the merge from the expense that does not support tax

  1. Have 2 expenses from 2 workspaces, one with non-zero tax rate and the other without tax rate
  2. Go to the expense that does not have tax enabled
  3. Trigger the merge flow from here
  4. In review details step, select the report with tax enabled as the destination report. Since the destination report supports tax, we'll automatically select the non-zero tax rate
  5. After merging, notice that the tax field is set to 0% - tax exempt

This only happens if I initiate the merge flow from the expense that does not have tax enabled. Other cases work fine.

Screen.Recording.2025-10-09.at.16.57.44.mov

In the Transaction_Merge payload, I did pass the correct taxAmount, taxCode and taxValue params.

@youssef-lr I think this is a BE bug. Can you take a look?

@dominictb
Copy link
Contributor Author

Checking that

@dominictb
Copy link
Contributor Author

dominictb commented Jan 5, 2026

I was wrong to assume that other fields had the same bug. Indeed only fields that are dependent on report and policy (report name, workspace, tax,...) are affected. Root cause is we don't update transaction.reportID to the selected reportID. Thus it uses the target transaction reportID to get policy here. That's why if we had 2 expenses having the same taxCode (but different tax percentages), we would always end up seeing the target transaction tax name.

Also here we should retain the source report if it is the selected report to find the corresponding policyID.

@trjExpensify
Copy link
Contributor

Is this ready for another review @dominictb?

@dominictb
Copy link
Contributor Author

dominictb commented Jan 6, 2026

Yes cc @hoangzinh

Copy link
Contributor

@hoangzinh hoangzinh left a comment

Choose a reason for hiding this comment

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

All goods. I have a few feedback. Going to test PR today

targetTransactionReport = targetTransactionReport ?? currentSearchResults?.data[`${ONYXKEYS.COLLECTION.REPORT}${targetTransaction?.reportID}`];
sourceTransactionReport = sourceTransactionReport ?? currentSearchResults?.data[`${ONYXKEYS.COLLECTION.REPORT}${sourceTransaction?.reportID}`];
// If we're on search, search snapshot policies are more up to date
targetTransactionPolicy = currentSearchResults?.data[`${ONYXKEYS.COLLECTION.POLICY}${targetTransactionReport?.policyID}`];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
targetTransactionPolicy = currentSearchResults?.data[`${ONYXKEYS.COLLECTION.POLICY}${targetTransactionReport?.policyID}`];
targetTransactionPolicy = targetTransactionPolicy ?? currentSearchResults?.data[`${ONYXKEYS.COLLECTION.POLICY}${targetTransactionReport?.policyID}`];

I thought onyx data is more up-to-date than snapshot, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're on search page, the snapshot data is more up to date. See #71244 (comment)

) {
const conflictFields: string[] = [];
const mergeableData: Record<string, unknown> = {};
const mergeableData: Record<string, unknown> = {selectedTransactionByField: {}};
Copy link
Contributor

Choose a reason for hiding this comment

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

can you elaborate on this change? @dominictb. I'm worried it will reset selected options when this function is triggered.

Copy link
Contributor Author

@dominictb dominictb Jan 8, 2026

Choose a reason for hiding this comment

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

Thanks, that makes sense. 6518595

@hoangzinh
Copy link
Contributor

Bug: Unable to merge transactions

  1. Policy A with tax enabled
  2. Policy B with tax disabled
  3. Submit expense X to workspace chat of policy A
  4. Submit expense Y to workspace chat of policy B
  5. Go to Reports -> Expenses
  6. Select expense X and Y to merge (select X first)
  7. Select report of expense Y to keep
  8. Continue with merging steps
Screen.Recording.2026-01-07.at.18.25.11.mov

@trjExpensify
Copy link
Contributor

@dominictb can you address the feedback today please? Let's get this over the line!

@dominictb
Copy link
Contributor Author

dominictb commented Jan 8, 2026

Sure. I'm closely monitoring this. @hoangzinh Do you have any other concerns or bugs you found? I'm addressing the current ones but appreciate it if we can batch and fix them all.

@hoangzinh
Copy link
Contributor

So far, so good from me. I tried to test various cases yesterday, but it's only bug I found so far.

@trjExpensify
Copy link
Contributor

Nice one! But dammit, we've picked up a conflict. 😮‍💨

@dominictb
Copy link
Contributor Author

@youssef-lr I think this #71244 (comment) is a BE bug. When the target workspace has tax enabled but source workspace does not -> Transaction_Merge returns 402 Policy has tax tracking set to false error. This used to work previously. Can you check?

@MonilBhavsar
Copy link
Contributor

The error seems to be coming from here in BE https://github.com/Expensify/Auth/blob/92178dc621df6b83c81536b8cff5ff599a769a2b/auth/lib/Transaction.cpp#L7664
What is expected behavior in this case? The transaction does not have tax data, right?

@dominictb
Copy link
Contributor Author

I think we can ignore the taxCode param if the destination report/workspace does not support tax instead of throwing exception.

Same thing happens when you moving an expense with tax to a workspace/report without tax, taxCode, taxValue and taxAmount are persistent in the transaction but they just don't show up.

@trjExpensify
Copy link
Contributor

Gotcha, are we unblocked to continue reviewing this one?

@dominictb
Copy link
Contributor Author

I think we can ignore the taxCode param if the destination report/workspace does not support tax instead of throwing exception.

Oh what I meant in #71244 (comment) is that we need to update backend to do this.

Also I resolved @hoangzinh latest feedbacks in f12a935. He can continue reviewing those changes while waiting for the backend update.

@hoangzinh
Copy link
Contributor

Also I resolved @hoangzinh latest feedbacks in f12a935. He can continue reviewing those changes while waiting for the backend update.

I will manage to review the PR over the weekend, in the meantime

@hoangzinh
Copy link
Contributor

I think we can ignore the taxCode param if the destination report/workspace does not support tax instead of throwing exception.

Oh what I meant in #71244 (comment) is that we need to update backend to do this.

ah, @youssef-lr @MonilBhavsar do you agree with @dominictb's suggestion above?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants