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 #39616][$250] [Track Tax] - Tax does not show up in the Expense report when created offline #40051

Closed
5 of 6 tasks
lanitochka17 opened this issue Apr 10, 2024 · 18 comments
Closed
5 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@lanitochka17
Copy link

lanitochka17 commented Apr 10, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.62-0
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
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team

Issue found when executing PR #39723

Action Performed:

Prerequisites:
Create WS collect, include Tax, add 5% rate.

  1. Open https://staging.new.expensify.com/
  2. Navigate to a workspace room
  3. Switch on offline
  4. Create and send to the IOU room with 5% tax.
  5. Navigate to the IOU details

Expected Result:

The tax should appear in the IOU report when created offline

Actual Result:

Tax does not show up in the IOU report when created offline

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

Bug6445180_1712786974295.Recording__34.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d25bb36f4e169f12
  • Upwork Job ID: 1779966508736303104
  • Last Price Increase: 2024-04-15
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Apr 10, 2024
Copy link

melvin-bot bot commented Apr 10, 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.

@lanitochka17
Copy link
Author

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

@lanitochka17
Copy link
Author

We think that this bug might be related to #wave-collect - Release 1

@allgandalf
Copy link
Contributor

Proposal

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

Tax amount is not stored optimistically when we create IOU request offline

What is the root cause of that problem?

When we create the request offline, we call IOU.requestMoney and in requestMoney, we build out a report optimistically :

function buildOptimisticTransaction(
amount: number,
currency: string,
reportID: string,
comment = '',
created = '',
source = '',
originalTransactionID = '',
merchant = '',
receipt: Receipt = {},
filename = '',
existingTransactionID: string | null = null,
category = '',
tag = '',
billable = false,
pendingFields: Partial<{[K in TransactionPendingFieldsKey]: ValueOf<typeof CONST.RED_BRICK_ROAD_PENDING_ACTION>}> | undefined = undefined,
reimbursable = true,
): Transaction {

But in here we do not save the tax rate and tax amount optimistically , we only send them to the BE:

App/src/libs/actions/IOU.ts

Lines 2338 to 2352 in 8ae5491

taxCode,
taxAmount,
billable,
// This needs to be a string of JSON because of limitations with the fetch() API and nested objects
gpsPoints: gpsPoints ? JSON.stringify(gpsPoints) : undefined,
transactionThreadReportID,
createdReportActionIDForThread,
};
API.write(WRITE_COMMANDS.REQUEST_MONEY, parameters, onyxData);
resetMoneyRequestInfo();
Navigation.dismissModal(activeReportID);
if (activeReportID) {
Report.notifyNewAction(activeReportID, payeeAccountID);
}

but here we forgot to consider the case when IOU is created Offline at this case when we call buildOptimisticTransaction we do not pass and store both values optimistically.

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

We need to send additional props for tax rate and tax amount, this will be passed down to buildOptimisticTransaction via getMoneyRequestInformation, and then we will return the value of tax amount and rate stored optimistically so that we can see the rate and tax amount even in offline mode

} = getMoneyRequestInformation(

Result Video

Screen.Recording.2024-04-11.at.7.03.14.AM.mov

Note: Same approach would be followed for tax rate as well, in the video I have only implemented taxamount

@nkdengineer
Copy link
Contributor

nkdengineer commented Apr 11, 2024

Proposal

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

  • Tax - Tax does not show up in the IOU report when created offline

What is the root cause of that problem?

  • In requestMoney the onyxData does not contain the taxCode and taxAmount, that leads to there is no tax data shown in offline mode.

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

    let optimisticTransaction = TransactionUtils.buildOptimisticTransaction(
        ReportUtils.isExpenseReport(iouReport) ? -amount : amount,
        ...
        taxCode,
        ReportUtils.isExpenseReport(iouReport) ? -taxAmount : taxAmount,
    );
  • An additional bug is that, we do not have correct optimistic tax data when editing taxCode. When editing taxCode, we do not update the taxAmount accordingly. Solution: we can add check if the transactionChanges in here contains taxCode field. If it is, update the taxAmount as well. To do it, we can add the below logic to this:
if ('taxCode' in transactionChanges && !('taxAmount' in transactionChanges)) {
        const taxRates = policy?.taxRates;
        const getTaxAmount = (taxRates, selectedTaxRate: string, amount: number) => {
            const percentage = Object.values(OptionsListUtils.transformedTaxRates(taxRates)).find((taxRate) => taxRate.code?.includes(selectedTaxRate))?.value;
            if (percentage) {
                return TransactionUtils.calculateTaxAmount(percentage, amount);
            }
        };
        const taxAmount = getTaxAmount(taxRates, transactionChanges.taxCode, transaction?.amount);
        const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(taxAmount);
        optimisticData.push({
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
            value: {
                taxAmount: amountInSmallestCurrencyUnits,
            },
        });
    }
  • Then we need to add the failureData and successData properly.

What alternative solutions did you explore? (Optional)

  • NA

@melvin-bot melvin-bot bot added the Overdue label Apr 15, 2024
@abekkala abekkala added the External Added to denote the issue can be worked on by a contributor label Apr 15, 2024
@melvin-bot melvin-bot bot changed the title Tax - Tax does not show up in the IOU report when created offline [$250] Tax - Tax does not show up in the IOU report when created offline Apr 15, 2024
Copy link

melvin-bot bot commented Apr 15, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01d25bb36f4e169f12

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 15, 2024
Copy link

melvin-bot bot commented Apr 15, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

@abekkala
Copy link
Contributor

@jayeshmangwani it looks like we've already received a couple proposals for review! 🎉

@allgandalf
Copy link
Contributor

allgandalf commented Apr 15, 2024

Note for @jayeshmangwani : I have added the result video during the time of proposal itself rather than providing you with long lengthy code lines as in our proposal guidelines it states that:

Please use plain English, be brief and avoid jargon. Feel free to use images.
Do not post large multi-line diffs or write walls of text.

Code is something which is considered as implementation details and not the core idea, I have clearly stated where the changes would be implemented and what changes are required, I hope that helps you in making the decision, thanks 🥂

@jayeshmangwani
Copy link
Contributor

Will review proposals today

@jayeshmangwani
Copy link
Contributor

Thanks @GandalfGwaihir and @nkdengineer for the proposals

Both proposals are correct, and RCA is on point. @nkdengineer has added some extra details than @GandalfGwaihir for editing taxCode, but that is additional to the original issue. @GandalfGwaihir proposed a working solution first for the described issue, so in this case, we can go with user @GandalfGwaihir 's Proposal

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Apr 17, 2024

Triggered auto assignment to @arosiclair, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@trjExpensify trjExpensify changed the title [$250] Tax - Tax does not show up in the IOU report when created offline [$250] Tax - Tax does not show up in the Expense report when created offline Apr 18, 2024
@trjExpensify
Copy link
Contributor

👋 Just a heads up to make sure we distinguish between iouReport and expenseReport in the title and OP of the issue. A request to a workspace goes onto an expense report. Tax tracking is a feature of workspaces. You can't track tax on requests to individuals, that go on iou Reports.

@trjExpensify trjExpensify changed the title [$250] Tax - Tax does not show up in the Expense report when created offline [$250] [Track Tax] - Tax does not show up in the Expense report when created offline Apr 18, 2024
@trjExpensify
Copy link
Contributor

CC: @MonilBhavsar as it's Track Tax related.

@nkdengineer
Copy link
Contributor

@arosiclair More about this C+ comment: We have addtional bugs related to the tax flow in offline mode (mentioned in my proposal), should we plan to fix it in this issue? If not, I think we can go with the selected proposal

@MonilBhavsar
Copy link
Contributor

This is dupe of implementation issue - #39616

@MonilBhavsar MonilBhavsar changed the title [$250] [Track Tax] - Tax does not show up in the Expense report when created offline [HOLD #39616][$250] [Track Tax] - Tax does not show up in the Expense report when created offline Apr 18, 2024
@arosiclair
Copy link
Contributor

This is dupe of implementation issue - #39616

Should we just close this then?

@MonilBhavsar
Copy link
Contributor

Let's close it 👍

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. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
No open projects
Archived in project
Development

No branches or pull requests

8 participants