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

[Track Tax] After the IOU is created, the Tax rate changes to 0% #41408

Closed
6 tasks done
izarutskaya opened this issue May 1, 2024 · 12 comments
Closed
6 tasks done

[Track Tax] After the IOU is created, the Tax rate changes to 0% #41408

izarutskaya opened this issue May 1, 2024 · 12 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2

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: v1.4.69-0
Reproducible in staging?: Y
Reproducible in production?: Y
Found when executing PR : #41264
Email or phone of affected tester (no customers): sustinov@applausemail.com
Logs: https://stackoverflow.com/c/expensify/questions/4856
Issue reported by: Applause-Internal team

Action Performed:

  1. Open https://staging.new.expensify.com/
  2. Log in to your HT account
  3. Create a WS
  4. Enable "Taxes"
  5. Set "Tax Rate 1" as Workspace currency default
  6. Navigate to the WS room
  7. Create a manual IOU with default currency and Tax Rate 1
  8. Navigate to the details of the created IOU

Expected Result:

After the IOU is created, the Tax rate must remain the same as when the IOU was created

Actual Result:

After the IOU is created, the Tax rate changes to 0%

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

Bug6467815_1714562004733.Recording__108.mp4

View all open jobs on GitHub

@izarutskaya izarutskaya added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 1, 2024
Copy link

melvin-bot bot commented May 1, 2024

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

@izarutskaya
Copy link
Author

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

@cretadn22
Copy link
Contributor

cretadn22 commented May 1, 2024

Proposal

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

The tax rate is incorrect following the submission of the request

What is the root cause of that problem?

We do not include the default taxRateCode in the API params, the API returns an empty tax rate.

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

When generating the transactionDraft, it's essential to incorporate default tax rate as the transaction.taxRate.

What alternative solutions did you explore? (Optional)

We need to implement a useEffect to update the default taxRate for transactions, similar to how we handled billable field

useEffect(() => {
IOU.setMoneyRequestBillable(transactionID, defaultBillable);
}, [transactionID, defaultBillable]);

This is my draft implementation and it works well

useEffect(() => {
        const defaultTaxRate = policy?.taxRates?.taxes[policy?.taxRates?.defaultExternalID] ?? {}
   

    const taxRate = {
            text: defaultTaxRate.name,
            keyForList: defaultTaxRate.name,
            searchText: defaultTaxRate.name,
            tooltipText: defaultTaxRate.name,
            isDisabled: defaultTaxRate?.isDisabled,
            data: {
                ...defaultTaxRate,
                code: policy?.taxRates?.defaultExternalID
            },
    }
    
    
    IOU.setMoneyRequestTaxRate(transaction?.transactionID ?? '1', taxRate);


    }, [transaction, policy?.taxRates]);

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@Krishna2323
Copy link
Contributor

Krishna2323 commented May 1, 2024

Proposal

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

After the IOU is created, the Tax rate changes to 0%

What is the root cause of that problem?

taxAmount and taxCode isn't included in transaction optimistic data.

function buildOptimisticTransaction(

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

We need to pass taxAmount and taxCode to getMoneyRequestInformation and then buildOptimisticTransaction from requestMoney.

function requestMoney(

To TransactionUtils.buildOptimisticTransaction we need to pass taxAmount like below.

ReportUtils.isExpenseReport(iouReport) ? -taxAmount : taxAmount,

We also might need to convert the tax amount.

What alternative solutions did you explore? (Optional)

Result

tax_amount_code.mp4

@Krishna2323
Copy link
Contributor

Proposal Updated

  • Minor update in main solution
  • Result video added

@cretadn22
Copy link
Contributor

Proposal Updated

Adding an alternative solution

@allgandalf
Copy link
Contributor

Proposal

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

We are setting the value of tax code to foreign value if we do not get the value from transaction, this causes mismatch in tax code and tax amount

What is the root cause of that problem?

If we see the current OP video, we can se that when we are creating the transaction, we get the correct default rate i.e. because we get those values in MoneyRequestConfirmationList:

const taxRateTitle = taxRates && transaction ? TransactionUtils.getDefaultTaxName(taxRates, transaction) : '';

This works fine, but when we submit the transaction, we essentially submit it using IOURequestStepConfirmation for which we have the transaction as:
Screenshot 2024-05-01 at 6 24 38 PM

Now as seen above, we do not have the field transaction?.taxRate, so while submitting the expense we fallback to foreignTaxDefault:

const transactionTaxCode = transaction?.taxRate ? transaction.taxRate.data?.code : foreignTaxDefault;

As seen in the OP video the foreignTaxDefault is set to 0 tax, and thus the same gets set for the transaction and we create the transaction with 0 tax even when our default value is 5 %. This is the RCA,

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

Now, to solve this, we should follow the same approach we did in MoneyRequestConfirmationList, remember that during the creation of money request, we were able to see the correct tax code because in MoneyRequestConfirmationList we were accessing it correctly, the problem lies in the way we access tax code in IOURequestStepConfirmation, so we need to match it with MoneyRequestConfirmationList:

So update the following:

const transactionTaxCode = transaction?.taxRate ? transaction.taxRate.data?.code : foreignTaxDefault;

To:

    const taxRates = policy?.taxRates ?? null;
    const transactionTaxCode = taxRates && transaction ? TransactionUtils.getDefaultTaxName(taxRates, transaction) : '';

Also note that in the OP we can see the correct amount but not the correct tax code

Result Video:

327128107-41b3b9e5-f997-407a-8004-48e69562b5fe_RpPnCyIJ.mov

@allgandalf
Copy link
Contributor

We do not have tax code in transaction that is because tax is a property of a policy and not the transaction, so the right way to access it is via accessing the policy, you may also note that category and tags are also not present in transaction hence we take them from policy:

policyCategories: OnyxEntry<PolicyCategories>;
/** The tag configuration of the report's policy */
policyTags: OnyxEntry<PolicyTagList>;

@trjExpensify trjExpensify changed the title After the IOU is created, the Tax rate changes to 0% [Track Tax] After the IOU is created, the Tax rate changes to 0% May 1, 2024
@trjExpensify
Copy link
Contributor

CC: @MonilBhavsar is this on your radar?

@MonilBhavsar
Copy link
Contributor

Yes, we're already working on this issue in this PR #40443
Let's put this on HOLD

@MonilBhavsar MonilBhavsar self-assigned this May 3, 2024
@MonilBhavsar MonilBhavsar changed the title [Track Tax] After the IOU is created, the Tax rate changes to 0% [HOLD App PR 40443][Track Tax] After the IOU is created, the Tax rate changes to 0% May 3, 2024
@trjExpensify trjExpensify added Weekly KSv2 and removed Daily KSv2 labels May 3, 2024
@trjExpensify
Copy link
Contributor

Sounds good! Bumping down to Weekly.

@melvin-bot melvin-bot bot added the Overdue label May 13, 2024
@MonilBhavsar
Copy link
Contributor

We've merged the PR. This is fixed on main branch

@melvin-bot melvin-bot bot removed the Overdue label May 13, 2024
@MonilBhavsar MonilBhavsar changed the title [HOLD App PR 40443][Track Tax] After the IOU is created, the Tax rate changes to 0% [Track Tax] After the IOU is created, the Tax rate changes to 0% May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2
Projects
No open projects
Archived in project
Development

No branches or pull requests

6 participants