-
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
Use suitable decimals while calculating tax #43948
Conversation
@DylanDylann 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] |
Pending: Android video because of build issue. |
@ShridharGoel Please merge the latest main and re-test on Android |
src/libs/TransactionUtils.ts
Outdated
@@ -714,9 +715,11 @@ function hasWarningTypeViolation(transactionID: string, transactionViolations: O | |||
/** | |||
* Calculates tax amount from the given expense amount and tax percentage | |||
*/ | |||
function calculateTaxAmount(percentage: string, amount: number) { | |||
function calculateTaxAmount(percentage: string, amount: number, currency: string | undefined = undefined) { |
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.
Should we update to
currency?: string
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.
One more thing, why don't we pass currency in all cases?
if (amountAsInt === null || amountAsInt === undefined) { | ||
return ''; | ||
} | ||
return convertToFrontendAmountAsInteger(amountAsInt).toFixed(2); | ||
const decimals = getCurrencyDecimals(currency); | ||
return convertToFrontendAmountAsInteger(amountAsInt, currency).toFixed(decimals); |
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.
Why we need to use toFixed(decimals) here? we just used toFixed(decimals) in convertToFrontendAmountAsInteger
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.
@ShridharGoel How about this?
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.
This is needed to convert it to a String (we can also use just the toString() method).
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 we should use toString method
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.
This seems to be needed because in 2 decimals, Number
changes 25.00 to 25. We again need to change it back to 25.00 when calling convertToFrontendAmountAsString
.
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.
yeah, make sense
tests/unit/CurrencyUtilsTest.ts
Outdated
}); | ||
}); | ||
|
||
describe('convertToFrontendAmountAsInteger VND', () => { |
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.
Please write a clear description to describe that we need to fix in this PR
tests/unit/CurrencyUtilsTest.ts
Outdated
}); | ||
}); | ||
|
||
describe('convertToFrontendAmountAsString VND', () => { |
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.
same above
@ShridharGoel Could you process this PR soon? Because It relates to another PR that we need to prioritise |
Sure, checking. |
Will update this within a few hours. |
@ShridharGoel Is this PR ready for the next reviewing round? I see that you still post proposals while this PR is still pending from you. Please follow the guideline App/contributingGuides/CONTRIBUTING.md Line 98 in 36e9217
|
Yes, this is ready.
…On Friday 5 July 2024, DylanDylann ***@***.***> wrote:
@ShridharGoel <https://github.com/ShridharGoel> Is this PR ready for the
next reviewing round? I see that you still post proposals while this PR is
still pending from you. Please follow the guideline
https://github.com/Expensify/App/blob/36e92179c5e1c9f70d4352dba07395
243732de0d/contributingGuides/CONTRIBUTING.md?plain=1#L98
—
Reply to this email directly, view it on GitHub
<#43948 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIPLJHBNXZ56DC5YPMYRDGTZKZJMLAVCNFSM6AAAAABJQUCGH6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJQGQZDCNZQGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@DylanDylann I had already updated the PR yesterday.
…On Friday 5 July 2024, Shridhar Goel ***@***.***> wrote:
Yes, this is ready.
On Friday 5 July 2024, DylanDylann ***@***.***> wrote:
> @ShridharGoel <https://github.com/ShridharGoel> Is this PR ready for the
> next reviewing round? I see that you still post proposals while this PR is
> still pending from you. Please follow the guideline
>
> https://github.com/Expensify/App/blob/36e92179c5e1c9f70d4352
> dba07395243732de0d/contributingGuides/CONTRIBUTING.md?plain=1#L98
>
> —
> Reply to this email directly, view it on GitHub
> <#43948 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AIPLJHBNXZ56DC5YPMYRDGTZKZJMLAVCNFSM6AAAAABJQUCGH6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJQGQZDCNZQGI>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
@ShridharGoel Typescript check failure |
@ShridharGoel One more thing, in the next time please ping me or leave a message when you finish the update |
@DylanDylann Updated. |
tests/unit/CurrencyUtilsTest.ts
Outdated
* VND uses 0 decimals, so this test is needed. | ||
* https://github.com/Expensify/App/pull/43948 | ||
*/ | ||
describe('convertToFrontendAmountAsInteger VND', () => { |
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.
App/tests/unit/CurrencyUtilsTest.ts
Lines 134 to 144 in 8d6b1b3
describe('convertToDisplayString', () => { | |
test.each([ | |
[CONST.CURRENCY.USD, 25, '$0.25'], | |
[CONST.CURRENCY.USD, 2500, '$25.00'], | |
[CONST.CURRENCY.USD, 150, '$1.50'], | |
[CONST.CURRENCY.USD, 250000, '$2,500.00'], | |
['JPY', 2500, '¥25'], | |
['JPY', 250000, '¥2,500'], | |
['JPY', 2500.5, '¥25'], | |
['RSD', 100, 'RSD\xa01.00'], | |
['RSD', 145, 'RSD\xa01.45'], |
I think we should do like above reference instead of creating new test
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.
Updated.
@ShridharGoel Also please check this comment |
tests/unit/CurrencyUtilsTest.ts
Outdated
[null, '', 'USD'], | ||
[undefined, '', 'USD'], | ||
[0, '0.00', 'USD'], | ||
// VND uses 0 decimals. |
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.
// VND uses 0 decimals. |
tests/unit/CurrencyUtilsTest.ts
Outdated
[undefined, '', 'USD'], | ||
[0, '0.00', 'USD'], | ||
// VND uses 0 decimals. | ||
// https://github.com/Expensify/App/pull/43948 |
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.
// https://github.com/Expensify/App/pull/43948 |
tests/unit/CurrencyUtilsTest.ts
Outdated
[25, 0.25, 'USD'], | ||
[2500, 25, 'USD'], | ||
[2500.5, 25, 'USD'], // The backend should never send a decimal .5 value | ||
// VND uses 0 decimals. |
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.
// VND uses 0 decimals. |
tests/unit/CurrencyUtilsTest.ts
Outdated
[2500, 25, 'USD'], | ||
[2500.5, 25, 'USD'], // The backend should never send a decimal .5 value | ||
// VND uses 0 decimals. | ||
// https://github.com/Expensify/App/pull/43948 |
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.
// https://github.com/Expensify/App/pull/43948 |
@ShridharGoel Minor things, everything else looks good |
Reviewer Checklist
Screenshots/VideosAndroid: NativeScreen.Recording.2024-07-08.at.14.46.36.movAndroid: mWeb ChromeScreen.Recording.2024-07-08.at.14.44.14.moviOS: NativeScreen.Recording.2024-07-08.at.14.48.11.moviOS: mWeb SafariScreen.Recording.2024-07-08.at.14.45.15.movMacOS: Chrome / SafariScreen.Recording.2024-07-08.at.12.37.13.movMacOS: DesktopScreen.Recording.2024-07-08.at.14.42.47.mov |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/francoisl in version: 9.0.6-0 🚀
|
🚀 Deployed to staging by https://github.com/francoisl in version: 9.0.6-0 🚀
|
🚀 Cherry-picked to staging by https://github.com/Julesssss in version: 9.0.6-1 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
🚀 Cherry-picked to staging by https://github.com/Julesssss in version: 9.0.6-1 🚀
@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes. |
🚀 Deployed to production by https://github.com/thienlnam in version: 9.0.6-8 🚀
|
🚀 Deployed to production by https://github.com/thienlnam in version: 9.0.7-8 🚀
|
@@ -329,10 +329,10 @@ function MoneyRequestConfirmationList({ | |||
taxCode = transaction?.taxCode ?? TransactionUtils.getDefaultTaxCode(policy, transaction) ?? ''; | |||
} | |||
const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxCode) ?? ''; | |||
const taxAmount = TransactionUtils.calculateTaxAmount(taxPercentage, taxableAmount); | |||
const taxAmount = TransactionUtils.calculateTaxAmount(taxPercentage, taxableAmount, currency); |
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.
Why did we use currency
and not transcation.currency
? currency
seems to be the currency associated to the mileage rate or the policy: (mileageRate as MileageRate)?.currency ?? policyCurrency;
. What if the transaction is not a distance transaction and it has a different currency from the policy default?
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.
@aldo-expensify This makes sense, we can update it to use transaction.currency
instead. Should I open a PR for this?
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.
No worries, I'll update it here: #43519
Details
Use suitable decimals while calculating tax.
Fixed Issues
$ #42601
PROPOSAL: #42601 (comment)
Tests
QA Steps
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
Screen.Recording.2024-07-06.at.3.14.02.PM.mov
Android: mWeb Chrome
Screenrecording_20240626_011750.mp4
iOS: Native
Screen.Recording.2024-06-26.at.12.25.44.AM.mov
iOS: mWeb Safari
Screen.Recording.2024-06-26.at.12.33.02.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-06-25.at.7.05.18.PM.mov
MacOS: Desktop
Screen.Recording.2024-06-26.at.12.20.33.AM.mov