-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[CP Staging] Fix tax rate being updated when currency is updated in offline mode #42128
Conversation
@rojiphil are you available to review this PR? |
@MonilBhavsar Yes. reviewing. |
Thank you! |
How's it going here |
if (!transaction?.amount) { | ||
return; | ||
} | ||
const transactionTaxCode = transaction?.taxCode ?? ''; | ||
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction) ?? ''; | ||
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? ''; | ||
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, transactionTaxCode ?? defaultTaxCode) ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one issue I notice here. Otherwise this works fine.
Currently, the tax code
and tax amount
does not correlate correctly as displayed below. I think this is because we are giving preference to transactionTaxCode
over defaultTaxCode
here.
When a currency changes, is it intentional to reset the tax code to the default one (i.e. Foreign or workspace) even when the transaction tax code is set to a non-default one?
42128-web-chrome.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a currency changes, is it intentional to reset the tax code to the default one (i.e. Foreign or workspace) even when the transaction tax code is set to a non-default one?
Yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Got it. Thanks. Now I know what is expected here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying!
When a currency changes, is it intentional to reset the tax code to the default one (i.e. Foreign or workspace) even when the transaction tax code is set to a non-default one?
Also, this is behavior server side. When online if currency is changed, then server will update taxRate and hence taxAmount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just digged in a little deeper. Would the following solve this issue?
const transactionCurrency = TransactionUtils.getCurrency(transaction);
const taxCode = ((transactionCurrency !== currency) ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode;
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxCode) ?? '';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but we have this similar logic to get taxCode in getDefaultTaxCode()
that is used by other functions too, so let's use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic within getDefaultTaxCode()
and here are not similar. The reasoning being that getDefaultTaxCode()
returns one of the default tax codes whereas we want to choose to return either transaction’s tax code or default tax code here. But I may be missing your point. Once the code changes are done, I will take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, i think I am getting the issue now
Reviewer Checklist
Screenshots/VideosMacOS: Chrome / Safari42128-web-safari-01.mp4Android: Native42128-android-native-01.mp4Android: mWeb Chrome42128-mweb-chrome-01.mp4iOS: Native42128-ios-native-01.mp4iOS: mWeb Safari42128-mweb-safari-01.mp4MacOS: Desktop42128-desktop-01.mp4 |
@MonilBhavsar Oh! We have conflicts to address too. |
Bump @rojiphil - any updates here? This fixes a deploy blocker so please make it high priority 🙏 |
Latest is here #42128 (comment) I'm tackling another one in parallel. Should be back here once I submit another one for review |
@Beamanator Sure. This is taken with high priority. The latest update here is that we have an issue that is being worked upon here |
Ahaa, thanks gents!! 🙏 |
This is ready for review/test. Thank you @rojiphil for detailed testing and drawing my attention! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks super good. But I have just one additional comment. Please do have a look.
Post your feedback I would go ahead and complete the checklist. Thanks.
const taxAmount = getTaxAmount(transaction, policy, newAmount); | ||
// If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. | ||
const transactionTaxCode = transaction?.taxCode ?? ''; | ||
const taxCode = currency !== transactionCurrency ? TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? '' : transactionTaxCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since transactionTaxCode
may return empty, can we fallback to defaultTaxCode
as getDefaultTaxCode()
is always guaranteed to return a valid value?
Something like this:
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency);
const taxCode = (currency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode;
This way, we can avoid taxCode
being empty. This also aligns with the existing implementation i.e. transactionTaxCode ?? defaultTaxCode
where we fallback to the default one if transactionTaxCode
is empty. This will also help us keep any possible regressions at bay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and tests well too.
Checklist completed.
@cristipaval 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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…pdate [CP Staging] Fix tax rate being updated when currency is updated in offline mode (cherry picked from commit 0d424d2)
This successfully got deployed to Desktop and Web in https://github.com/Expensify/App/actions/runs/9084540534 And it should have been deployed to android & iOS in a following CP (there were 2 more last night) |
@rojiphil @MonilBhavsar are either of you around to test this in staging? |
Works well on staging for me 20240515_122012.mp4 |
🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.73-7 🚀
|
Details
Fixed Issues
$ #42049
PROPOSAL:
Tests
Precondition:
Offline tests
Same as tests
QA Steps
Precondition:
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
See MacOS: Chrome / SafariAndroid: mWeb Chrome
See MacOS: Chrome / SafariiOS: Native
See MacOS: Chrome / SafariiOS: mWeb Safari
See MacOS: Chrome / SafariMacOS: Chrome / Safari
Screen.Recording.2024-05-14.at.11.25.08.AM.mov
MacOS: Desktop
See MacOS: Chrome / Safari