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

Handle tax for split requests #40240

Merged
merged 19 commits into from
May 24, 2024
Merged

Handle tax for split requests #40240

merged 19 commits into from
May 24, 2024

Conversation

MonilBhavsar
Copy link
Contributor

@MonilBhavsar MonilBhavsar commented Apr 15, 2024

Details

Pass taxCode and taxAmount to Split API commands.
Tracks tax both online and offline optimistically for split expense with policy expense chat

Fixed Issues

$ #39690
PROPOSAL:

Tests

Same as QA steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA steps

QA Steps

Prerequisite: Tax is enabled on workspace

  1. Go to FAB > Split > Select a workspace chat
  2. Ensure tax rate and tax amount are selected
  3. Update currency, expense amount and tax rate and ensure tax rate and tax amount are updated accordingly. Note the taxAmount at this point
  4. Split the expense
  5. Go to money request with workspace and ensure tax rate is selected as it is and tax amount is divided by half

Now we repeat by splitting with individuals

  1. Go to FAB > Split > Select a workspace chat
  2. Ensure tax rate and tax amount are not displayed
  3. Go to individual money requests and ensure tax rate and tax amount are no displayed
  4. Repeat for offline

Testing split scans

  1. Go to FAB and select Split Expense and select Scan
  2. Add a receipt
  3. While in scanning state, update tax rate and ensure tax rate and tax amount are updated in draft transaction accordingly and no API call is being made
  4. While in scanning state, update tax amount and ensure tax amount are updated in draft transaction accordingly and no API call is being made
  5. While in scanning state, update expense amount and currency and ensure tax rate and tax amount are updated in draft transaction accordingly and no API call is being made
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native See MacOS: Chrome / Safari
Android: mWeb Chrome See MacOS: Chrome / Safari
iOS: Native See MacOS: Chrome / Safari
iOS: mWeb Safari See MacOS: Chrome / Safari
MacOS: Chrome / Safari

https://drive.google.com/file/d/1C6T9vQ1VwujJJKlCbNNo8cZ_udQZmc3W/view?usp=sharing

MacOS: Desktop See MacOS: Chrome / Safari

@MonilBhavsar MonilBhavsar self-assigned this Apr 15, 2024
@MonilBhavsar MonilBhavsar marked this pull request as ready for review May 15, 2024 14:04
@MonilBhavsar MonilBhavsar requested a review from a team as a code owner May 15, 2024 14:04
@MonilBhavsar MonilBhavsar requested review from dukenv0307 and removed request for a team May 15, 2024 14:12
@dukenv0307
Copy link
Contributor

@MonilBhavsar I found the following bug

  1. Go to FAB > Split
  2. Enter small value
  3. Select a workspace chat
  4. Click Next
  5. Observe that tax rate and tax amount are shown
  6. Go back to amount page
  7. Enter large value
  8. Select the same workspace as before
  9. Click Next
  10. Observe that tax rate and tax amount are not shown
web-resize.mp4

@dukenv0307
Copy link
Contributor

It worked well when I enter the large value at the beginning

@MonilBhavsar
Copy link
Contributor Author

Good catch! I have reproduced. Looking into it

@MonilBhavsar
Copy link
Contributor Author

Typescript checks are broken on main and being fixed here #42256

const selectedReportID = useRef<string>(reportID);

// We need to set selectedReportID if user has navigated back from confirmation page and navigates to confirmation page with already selected participant
const selectedReportID = useRef<string>(participants?.length === 1 ? participants[0]?.reportID ?? reportID : reportID);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug was

  1. User enters amount
  2. Selects participants and clicks "Next"
  3. Goes to confirmation page and see's Category, Tags and Tax fields
  4. User goes back to 1 and edit's amount(doesn't matter)
  5. User without selecting a participant clicks "Next" because participant was already selected(This is root cause)
  6. Goes to confirmation page and doesn't see Category, Tags and Tax fields because reportID and policyID is not properly set from 5 above.

Let me know if you think this is not the correct way and should use separate hook or may be something else. Open to other solutions.

@MonilBhavsar
Copy link
Contributor Author

TypeScript checks are passing now

@dukenv0307
Copy link
Contributor

@MonilBhavsar

Bug:

  1. Go to FAB > Split
  2. Enter any value
  3. Select a workspace chat
  4. Click Next
  5. Observe that tax rate and tax amount are shown
  6. Go back to amount page
  7. Enter other value
  8. Select the same workspace as before
  9. Click Next
  10. Observe that the tax amount is not updated
web-resize.mp4

Comment on lines -377 to -379
if (transaction?.taxAmount && previousTransactionAmount === transaction?.amount && previousTransactionCurrency === transaction?.currency) {
return IOU.setMoneyRequestTaxAmount(transactionID, transaction?.taxAmount ?? 0, true);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly think this was pre optimization. When the user updates transactionAmount, previousTransactionAmount was not being changed, and we we were not setting updated taxAmount in Onyx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this introduced a bug where taxAmount is not being updated in draft transaction. looking...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed now with latest commit - c671c7a

@@ -326,12 +324,6 @@ const IOURequestStepAmountWithOnyx = withOnyx<IOURequestStepAmountProps, IOURequ
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`;
},
},
draftTransaction: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withFullTransactionOrNotFound() returns draftTransaction or transaction depending upon condition. So I think we can remove this

@MonilBhavsar
Copy link
Contributor Author

@dukenv0307 I have fixed the bug and also noticed bugs with Split scan flow. So also fixed that. Please take a look and let me know what do you think. Thank you! 🙌

@MonilBhavsar
Copy link
Contributor Author

Thanks for reporting bugs 😄
I've fixed them. Let me know what do you think!

@MonilBhavsar MonilBhavsar changed the title Handle tax for split bill requests Handle tax for split requests May 23, 2024
@dukenv0307
Copy link
Contributor

code looks good and tests well

@melvin-bot melvin-bot bot requested a review from jasperhuangg May 24, 2024 04:16
Copy link

melvin-bot bot commented May 24, 2024

@jasperhuangg Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@jasperhuangg jasperhuangg merged commit c5c1120 into main May 24, 2024
18 checks passed
@jasperhuangg jasperhuangg deleted the monil-splitBillTaxUpdate branch May 24, 2024 20:02
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/jasperhuangg in version: 1.4.76-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@blimpich
Copy link
Contributor

I think this caused a few minor deploy blockers in the most recent deploy checklist.

@bondydaa
Copy link
Contributor

I reverted this PR locally to see if it would fix #42655 and it appears to. so I think this might have caused a few blockers.

@bondydaa
Copy link
Contributor

created a revert PR here #42670

discussion is on going in this thread https://expensify.slack.com/archives/C07J32337/p1716843389797979

@bondydaa
Copy link
Contributor

we did revert this PR and cp'd it to staging

@Julesssss
Copy link
Contributor

Just adding a linked bug reported here. I'm going to remove the blocking label though.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.76-7 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants