Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.33k stars 2.76k forks source link

[Help Wanted] Search - Tax field for the expense does not auto update after changing distance rate #48121

Open IuliiaHerets opened 2 weeks ago

IuliiaHerets commented 2 weeks ago

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: v9.0.25-2 Reproducible in staging?: Y Reproducible in production?: Y Email or phone of affected tester (no customers): applausetester+kh050806@applause.expensifail.com Issue reported by: Applause Internal Team

Action Performed:

Precondition:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Submit a distance expense, with a distance rate that has tax rate and tax reclaimable on.
  4. Go to Search.
  5. Click on the submitted expense in Step 3.
  6. Click Rate.
  7. Select a different distance rate that has tax rate and tax reclaimable on.
  8. Close the RHP.

Expected Result:

The Tax field for the expense will update.

Actual Result:

The Tax field for the expense does not update, unless user switches to another tab and back to Expenses tab.

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/3ff338c0-f658-481d-a751-2247ae3f9451

View all open jobs on GitHub

melvin-bot[bot] commented 2 weeks ago

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

IuliiaHerets commented 2 weeks ago

We think that this bug might be related to #wave-control

IuliiaHerets commented 2 weeks ago

@strepanier03 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

daledah commented 2 weeks ago

Proposal

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

The Tax field for the expense does not update, unless user switches to another tab and back to Expenses tab.

What is the root cause of that problem?

We use updateMoneyRequestDistanceRate here to update tax rate. This function gets optimistic data for transaction when updating using getUpdateMoneyRequestParams here.

This function calculates updated data using TransactionUtils.getUpdatedTransaction here.

However, when we update the tax rate, there are only customUnitRateID in transactionChanges :

https://github.com/Expensify/App/blob/ac5ee2ef790231c67ca3ddb14dc481d77da5bcea/src/libs/actions/IOU.ts#L3123-L3133

So, in TransactionUtils.getUpdatedTransaction, only customUnitRateID will be updated

https://github.com/Expensify/App/blob/ac5ee2ef790231c67ca3ddb14dc481d77da5bcea/src/libs/TransactionUtils/index.ts#L257-L260

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

Add a function to calculate tax amount using custom rateID, transactionID:

function getTaxAmountOfTransaction(policy: OnyxEntry<Policy>, customUnitRateID: string, transactionID: string) {
    const distanceUnit = PolicyUtils.getCustomUnit(policy);
    const customUnitRate = PolicyUtils.getCustomUnitRate(policy, customUnitRateID);
    if (!distanceUnit || !distanceUnit?.customUnitID || !customUnitRate) {
        return 0;
    }
    const transaction = TransactionUtils.getTransaction(transactionID);
    const unit = distanceUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES;
    const distance = TransactionUtils.getDistanceInMeters(transaction, unit);
    const rate = customUnitRate?.rate ?? 0;
    const amount = getDistanceRequestAmount(distance, unit, rate);
    const taxClaimablePercentage = customUnitRate.attributes?.taxClaimablePercentage ?? 0;
    const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, customUnitRate?.attributes?.taxRateExternalID ?? '') ?? '';
    return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, amount * taxClaimablePercentage, customUnitRate.currency ?? CONST.CURRENCY.USD));
}

Then add taxAmount to transactionChanges here:

https://github.com/Expensify/App/blob/ac5ee2ef790231c67ca3ddb14dc481d77da5bcea/src/libs/actions/IOU.ts#L3131-L3133

    const transactionChanges: TransactionChanges = {
        customUnitRateID: rateID,
        taxAmount: getTaxAmountOfTransaction(policy, rateID, transactionID)
    };

What alternative solutions did you explore? (Optional)

FitseTLT commented 2 weeks ago

This is a BE issue as we don't support optimistic data for Search.

melvin-bot[bot] commented 1 week ago

@strepanier03 Huh... This is 4 days overdue. Who can take care of this?

strepanier03 commented 1 week ago

Hmmm, I'm not able to reproduce this as described. During my testing the tax field was updating after making a change and closing the RHP, I didn't need to toggle to another tab to get it to update.

I'm also receiving some inconsistent behavior as sometimes I'm unable to change the tax rate on the expense. I'm going to test this some more.

melvin-bot[bot] commented 5 days ago

@strepanier03 Huh... This is 4 days overdue. Who can take care of this?

strepanier03 commented 5 days ago

Okay, got past the inconsistent behavior I was running into and was able to reproduce this successfully.

melvin-bot[bot] commented 4 days ago

@strepanier03 this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] commented 1 day ago

@strepanier03 Whoops! This issue is 2 days overdue. Let's get this updated quick!

strepanier03 commented 1 day ago

No update yet. Tied to a project and labeled.