Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD for payment 2024-05-22] Tax - Unable to save valid tax rate amount when changing currency for the first time #42047

Closed
6 tasks done
izarutskaya opened this issue May 13, 2024 · 30 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering

Comments

@izarutskaya
Copy link

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: 1.4.73-0
Reproducible in staging?: Y
Reproducible in production?: N
Logs: https://stackoverflow.com/c/expensify/questions/4856
Issue reported by: Applause-internal team

Action Performed:

Precondition:

  • Workspace has enabled tax rate.
  • Workspace currency default is tax exempt (0%).
  • Foreign currency default have different tax rate (non-zero rate).
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Go to + > Submit expense.
  4. Enter amount (maintain local currency) > Next.
  5. On confirmation page, click Tax amount.
  6. Change the currency to any foreign currency.
  7. After changing to foreign currency, the tax rate will automatically adjust to the non-zero tax rate (Foreign currency default).
  8. Enter a valid tax amount (now that the rate is no longer 0%).
  9. Save it.

Expected Result:

User will be able to save the tax amount as long as the tax amount falls within the limit of the new rate (Foreign currency default).

Actual Result:

When saving a valid tax amount, error shows up. The maximum rate amount in the error message still follows the previous tax rate (Workspace currency default). User will need to save 0 tax amount and return to Tax amount after saving to save the new tax amount.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6479175_1715595255890.foreign_tax.mp4

View all open jobs on GitHub

@izarutskaya izarutskaya added DeployBlockerCash This issue or pull request should block deployment Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. DeployBlocker Indicates it should block deploying the API labels May 13, 2024
Copy link

melvin-bot bot commented May 13, 2024

Triggered auto assignment to @lakchote (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

Copy link

melvin-bot bot commented May 13, 2024

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

Copy link

melvin-bot bot commented May 13, 2024

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

  1. If you find which PR caused the issue/bug, you can reassign it to the person responsible for it.
    • If the author is OOO or won’t get online before the daily deploy is due, you are responsible for finding the best fix/path forward. Don’t hesitate to ask for help!
  2. Try to reproduce the issue, if the bug is on production, remove the DeployBlocker label but stay assigned to fix it (or find out which PR broke it to get help from the author).
    • You can adjust the urgency of the issue to better represent the gravity of the bug.
    • If the issue is super low priority, feel free to un-assign yourself.
    • Be careful with PHP warnings, sometimes it is more complex than just adding a null coalescing operator as they might be uncovering some bigger bug.
    • If it was a one-off issue that requires no action (for example, Bedrock was down or it is a duplicated issue), you can close it.

Remember rule #2: Never un-assign yourself from a real DeployBlocker unless you are 100% sure someone else is assigned and will take care of it.

@melvin-bot melvin-bot bot added Engineering Hourly KSv2 and removed Hourly KSv2 labels May 13, 2024
@github-actions github-actions bot added Hourly KSv2 and removed Daily KSv2 labels May 13, 2024
Copy link
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.

@izarutskaya
Copy link
Author

@abekkala I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors.

@izarutskaya
Copy link
Author

We think this issue might be related to the #collect project.

@izarutskaya
Copy link
Author

Production

Recording.2448.mp4

@ShridharGoel
Copy link
Contributor

ShridharGoel commented May 13, 2024

I can quickly open a PR. This was caused by #40443.

Proposal

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

Unable to save valid tax rate amount when changing currency for the first time

What is the root cause of that problem?

We are not using the selected currency while finding the tax rate in IOURequestStepTaxAmountPage.

function getTaxAmount(transaction: OnyxEntry<Transaction>, policy: OnyxEntry<Policy>, isEditing: boolean): number | undefined {
if (!transaction?.amount) {
return;
}
const transactionTaxAmount = TransactionUtils.getAmount(transaction);
const transactionTaxCode = transaction?.taxCode ?? '';
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction) ?? '';
const getTaxValue = (taxCode: string) => TransactionUtils.getTaxValue(policy, transaction, taxCode);
const defaultTaxValue = getTaxValue(defaultTaxCode);
const moneyRequestTaxPercentage = (transactionTaxCode ? getTaxValue(transactionTaxCode) : defaultTaxValue) ?? '';
const editingTaxPercentage = (transactionTaxCode ? getTaxValue(transactionTaxCode) : moneyRequestTaxPercentage) ?? '';
const taxPercentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage;
return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, transactionTaxAmount));
}

function getDefaultTaxCode(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>) {
const defaultExternalID = policy?.taxRates?.defaultExternalID;
const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
return policy?.outputCurrency === getCurrency(transaction) ? defaultExternalID : foreignTaxDefault;
}

We are always taking the currency via the transaction.

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

Pass currency to getTaxAmount.

taxAmount={getTaxAmount(transaction, policy, currency, Boolean(backTo || isEditing))}
function getTaxAmount(transaction: OnyxEntry<Transaction>, policy: OnyxEntry<Policy>, currency: string | undefined, isEditing: boolean): number | undefined {
    if (!transaction?.amount) {
        return;
    }
    const transactionTaxAmount = TransactionUtils.getAmount(transaction);
    const transactionTaxCode = transaction?.taxCode ?? '';
    const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? '';
    const getTaxValue = (taxCode: string) => TransactionUtils.getTaxValue(policy, transaction, taxCode);
    const defaultTaxValue = getTaxValue(defaultTaxCode);
    const moneyRequestTaxPercentage = (transactionTaxCode ? getTaxValue(transactionTaxCode) : defaultTaxValue) ?? '';
    const editingTaxPercentage = (transactionTaxCode ? getTaxValue(transactionTaxCode) : moneyRequestTaxPercentage) ?? '';
    const taxPercentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage;
    return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, transactionTaxAmount));
}

Pass the currency to getDefaultTaxCode:

function getDefaultTaxCode(policy: OnyxEntry<Policy>, transaction: OnyxEntry<Transaction>, currency: string | undefined) {
    const defaultExternalID = policy?.taxRates?.defaultExternalID;
    const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
    return policy?.outputCurrency === (currency ?? getCurrency(transaction)) ? defaultExternalID : foreignTaxDefault;
}

@allroundexperts
Copy link
Contributor

@ShridharGoel's proposal works good. The RCA seems to be correct as well. We are always taking into account the transaction currency rather than the selected currency.

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented May 13, 2024

Current assignees @cristipaval and @lakchote are eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@cristipaval
Copy link
Contributor

This one seems to be the offending PR. @MonilBhavsar could you please have a look at this deploy blocker?

@cristipaval
Copy link
Contributor

ah, sorry @lakchote , it seems you were on it already 🙇
Unassigning myself.

@lakchote
Copy link
Contributor

@ShridharGoel feel free to raise a PR whenever you can so we can test it timely and fix the blocker.

@cristipaval cristipaval removed their assignment May 13, 2024
@Beamanator
Copy link
Contributor

PR CP'd, @lakchote confirmed it's fixed on staging so marking NAB!

@Beamanator Beamanator removed the DeployBlockerCash This issue or pull request should block deployment label May 14, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels May 15, 2024
@melvin-bot melvin-bot bot changed the title Tax - Unable to save valid tax rate amount when changing currency for the first time [HOLD for payment 2024-05-22] Tax - Unable to save valid tax rate amount when changing currency for the first time May 15, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 15, 2024
Copy link

melvin-bot bot commented May 15, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented May 15, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.73-7 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-05-22. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented May 15, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
  • [@allroundexperts] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@allroundexperts] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@allroundexperts] Determine if we should create a regression test for this bug.
  • [@allroundexperts] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels May 21, 2024
Copy link

melvin-bot bot commented May 22, 2024

Issue is ready for payment but no BZ is assigned. @strepanier03 you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

Copy link

melvin-bot bot commented May 22, 2024

Payment Summary

Upwork Job

BugZero Checklist (@strepanier03)

  • I have verified the correct assignees and roles are listed above and updated the neccesary 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 paid out the Upwork contracts or cancelled the ones that are incorrect
  • I have verified the payment summary above is correct

@strepanier03
Copy link
Contributor

I hired your in Upwork @ShridharGoel, I'll check tomorrow to see if I can pay it out.

@allroundexperts - I'll finish up the payment summary once the checklist is done, thanks!

@allroundexperts
Copy link
Contributor

Checklist

  1. support for offline tax tracking #40443
  2. N/A since this was a regression
  3. N/A
  4. A regression test would be helpful. The test steps look simple enough to me!

@melvin-bot melvin-bot bot added the Overdue label May 28, 2024
@strepanier03
Copy link
Contributor

Payment Summary

@JmillsExpensify - Payment request incoming.

@strepanier03
Copy link
Contributor

@ShridharGoel - Please accept the Upwork job so it can be paid?

@melvin-bot melvin-bot bot removed the Overdue label Jun 2, 2024
@strepanier03
Copy link
Contributor

I am out of the office from June 3-10 - If you need BZ action in that time please reach out in Slack to ask for an assist.

@melvin-bot melvin-bot bot added the Overdue label Jun 4, 2024
@JmillsExpensify
Copy link

Contributor paid out. @allroundexperts going to close this issue and see you again when I receive the payment request.

@JmillsExpensify
Copy link

$250 approved for @allroundexperts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering
Projects
None yet
Development

No branches or pull requests

10 participants