Skip to content

Distance tax - Distance rate with non-zero tax rate shows 0% rate when submitting next expense #43137

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: 1.4-79-2
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Issue found when executing PR #42909

Action Performed:

Precondition:

  • Track Tax distance is enabled on Old Dot
  • Workspace has a few distance rates and the distance rates are associated with tax rates
  1. Go to staging.new.expensify.com
  2. Go to workspace chat
  3. Submit a distance expense with distance rate that has non-zero tax rate (so that this distance rate will be the default one when creating the next distance expense)
  4. Go to workspace chat
  5. Go to + > Submit expense > Distance
  6. Enter waypoints > Next
  7. Note that the tax rate for the distance in Step 3 becomes tax exempt (0%)
  8. Change to another distance rate and change again back to the same distance rate in Step 8
  9. Note that the distance rate only shows the correct tax rate after reselecting distance rate

Expected Result:

In Step 7, the selected distance rate should show the correct tax rate when creating another distance expense

Actual Result:

In Step 7, the selected distance rate should show the incorrect tax rate (it shows tax exempt 0%) when creating another distance expense
It only shows the correct tax rate when reselecting the distance rate (Step 8)

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

Add any screenshot/video evidence

Bug6502346_1717567663584.bandicam_2024-06-05_14-03-07-751.mp4

View all open jobs on GitHub

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 5, 2024
  2. melvin-bot commented on Jun 5, 2024

    @melvin-bot

    Triggered auto assignment to @joekaufmanexpensify (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. lanitochka17 commented on Jun 5, 2024

    @lanitochka17
    Author

    @joekaufmanexpensify FYI 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

  4. lanitochka17 commented on Jun 5, 2024

    @lanitochka17
    Author

    We think that this bug might be related to #vip-vsp

  5. bernhardoj commented on Jun 6, 2024

    @bernhardoj
    Contributor

    Proposal

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

    The distance tax rate isn't set automatically.

    What is the root cause of that problem?

    When we select a distance rate, we also update the tax rate here.

    function selectDistanceRate(customUnitRateID: string) {
    if (policy?.customUnits && customUnitID && shouldShowTax) {
    const policyCustomUnitRate = policy?.customUnits[customUnitID].rates[customUnitRateID];
    const taxRateExternalID = policyCustomUnitRate.attributes?.taxRateExternalID ?? '';
    const taxAmount = CurrencyUtils.convertToBackendAmount(DistanceRequestUtils.calculateTaxAmount(policy, transaction, customUnitRateID));
    IOU.setMoneyRequestTaxAmount(transactionID, taxAmount);
    IOU.setMoneyRequestTaxRate(transactionID, taxRateExternalID);
    }
    IOU.updateDistanceRequestRate(transactionID, customUnitRateID, policy?.id ?? '');
    navigateBack();

    But we don't do the same when initializing it. The app will currently only initialize the distance rate.

    useEffect(() => {
    if (customUnitRateID || !canUseP2PDistanceRequests) {
    return;
    }
    if (!customUnitRateID) {
    const rateID = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultMileageRate?.customUnitRateID ?? '';
    IOU.setCustomUnitRateID(transactionID, rateID);
    }
    }, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, canUseP2PDistanceRequests, transactionID]);

    So the tax rate will always be the default one.

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

    Initialize the tax rate too when the page is initialized.

    useEffect(() => {
        if (!customUnitRateID) {
            return;
        }
        const distanceUnit = PolicyUtils.getCustomUnit(policy);
        const customUnitID = distanceUnit?.customUnitID;
        if (policy?.customUnits && customUnitID && shouldShowTax) {
            const policyCustomUnitRate = policy?.customUnits[customUnitID].rates[customUnitRateID];
            const taxRateExternalID = policyCustomUnitRate.attributes?.taxRateExternalID ?? '';
            const taxAmount = CurrencyUtils.convertToBackendAmount(DistanceRequestUtils.calculateTaxAmount(policy, transaction, customUnitRateID));
            IOU.setMoneyRequestTaxAmount(transactionID, taxAmount, true);
            IOU.setMoneyRequestTaxRate(transactionID, taxRateExternalID);
        }
    }, [customUnitRateID, isPolicyExpenseChat, policy, isDistanceRequest, transaction, transactionID]);
    

    maybwe we should move it to a util function

  6. joekaufmanexpensify commented on Jun 6, 2024

    @joekaufmanexpensify
    Contributor

    I followed the reproduction steps above, and can't reproduce this. We are using the correct tax rate when I create the second expense, rather than defaulting to $0.

    2024-06-06_16-51-54.mp4
  7. joekaufmanexpensify commented on Jun 6, 2024

    @joekaufmanexpensify
    Contributor

    Gonna close this out for now since it doesn't appear to be reproducible, but LMK if there is some other way to reproduce this, and happy to take another look

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.DailyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions