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
| * 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.
Should we update to
currency?: string
There was a problem hiding this comment.
One more thing, why don't we pass currency in all cases?
| } | ||
| return convertToFrontendAmountAsInteger(amountAsInt).toFixed(2); | ||
| const decimals = getCurrencyDecimals(currency); | ||
| return convertToFrontendAmountAsInteger(amountAsInt, currency).toFixed(decimals); |
There was a problem hiding this comment.
Why we need to use toFixed(decimals) here? we just used toFixed(decimals) in convertToFrontendAmountAsInteger
There was a problem hiding this comment.
This is needed to convert it to a String (we can also use just the toString() method).
There was a problem hiding this comment.
I think we should use toString method
There was a problem hiding this comment.
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.
tests/unit/CurrencyUtilsTest.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| describe('convertToFrontendAmountAsInteger VND', () => { |
There was a problem hiding this comment.
Please write a clear description to describe that we need to fix in this PR
tests/unit/CurrencyUtilsTest.ts
Outdated
| }); | ||
| }); | ||
|
|
||
| describe('convertToFrontendAmountAsString VND', () => { |
|
@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.
App/tests/unit/CurrencyUtilsTest.ts
Lines 134 to 144 in 8d6b1b3
I think we should do like above reference instead of creating new test
|
@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.
| // 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.
| // 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.
| // 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.
| // 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 🚀
|
| } | ||
| 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.
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.
@aldo-expensify This makes sense, we can update it to use transaction.currency instead. Should I open a PR for this?
Details
Use suitable decimals while calculating tax.
Fixed Issues
$ #42601
PROPOSAL: #42601 (comment)
Tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.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