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

feat: added price with tax without unit multiplier #121

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"extends": "vtex",
"root": true,
"env": {
"node": true,
"es6": true,
"jest": true
"node": true
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `sellingPriceWithTaxWithoutUnit` and `listPriceWithTaxWithoutUnit`

### Fixed

Expand Down
11 changes: 11 additions & 0 deletions react/ListPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const CSS_HANDLES = [
'listPrice',
'listPriceValue',
'listPriceWithTax',
'listPriceWithTaxWithoutUnit',
'listPriceWithUnitMultiplier',
'taxPercentage',
'taxValue',
Expand Down Expand Up @@ -78,6 +79,8 @@ function ListPrice({
const hasMeasurementUnit = measurementUnit && measurementUnit !== 'un'
const hasUnitMultiplier = unitMultiplier !== 1

const listPriceWithTaxWithoutUnit = listPriceValue + (listPriceValue * taxPercentage / unitMultiplier)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here

Copy link
Author

Choose a reason for hiding this comment

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

Hi @icazevedo
Like I mentioned in the other comment, these variables will return a different value. The regular listPriceWithTax will return the tax for all units in a sku with unit multiplier, so it is not enough. We need to be able to display the price of a single unit with taxes only for that unit, not the price for 1 unit but the tax for all units in the SKU.


if (listPriceValue <= sellingPriceValue) {
return null
}
Expand Down Expand Up @@ -111,6 +114,14 @@ function ListPrice({
<FormattedCurrency value={listPriceWithTax} />
</span>
),
listPriceWithTaxWithoutUnit: (
<span
key="listPriceWithTaxWithoutUnit"
className={`${handles.listPriceWithTaxWithoutUnit} strike`}
>
<FormattedCurrency value={listPriceWithTaxWithoutUnit} />
</span>
),
listPriceWithUnitMultiplier: (
<span
key="listPriceWithUnitMultiplier"
Expand Down
12 changes: 12 additions & 0 deletions react/SellingPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const CSS_HANDLES = [
'sellingPrice',
'sellingPriceValue',
'sellingPriceWithTax',
'sellingPriceWithTaxWithoutUnit',
'sellingPriceWithUnitMultiplier',
'taxPercentage',
'taxValue',
Expand Down Expand Up @@ -79,6 +80,9 @@ function SellingPrice({

const taxValue = commercialOffer.Tax

const sellingPriceWithTaxWithoutUnit =
sellingPriceValue + (sellingPriceValue * taxPercentage / unitMultiplier)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the correct sellingPriceWithTax calculation, so it seems like there's no need to create another property for it. I suggest altering the sellingPriceWithTax value to what would be sellingPriceWithTaxWithoutUnit as it would properly represent the selling price of the product with taxes.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @icazevedo
The issue is that the commercial offer Tax that is used in the sellingPriceWithTax will return the tax for the entire multiplied value of the product.

If there is a product that costs 100$ and has a 10% tax and the product has a 5.0 unit multiplier then the commercialOffer.Tax will return the tax for all 5 units.
10% of 100 = 10
commercialOffer.Tax = 50

So when displaying the price of a product without the unit multiplier but with the tax, that value will be wrong (150$ instead of 110$)

Please check the description of this PR, and also the video recording I attached.

You can test on this workspace to see the variable.
on the master workspace you will see the sellingPriceWithTax variable.

Screen.Recording.2023-07-13.at.13.56.37.mov

Copy link
Author

Choose a reason for hiding this comment

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

Regarding modifying the sellingPriceWithTax it would mean modifying the commercialOffer.Tax and I think that would impact existing implementations. This way it will not be a breaking change. Maybe there are some use cases where the original sellingPriceWithTax calculation is used.


const hasListPrice = sellingPriceValue !== listPriceValue
const hasMeasurementUnit = measurementUnit && measurementUnit !== 'un'
const hasUnitMultiplier = unitMultiplier !== 1
Expand Down Expand Up @@ -110,6 +114,14 @@ function SellingPrice({
<FormattedCurrency value={sellingPriceWithTax} />
</span>
),
sellingPriceWithTaxWithoutUnit: (
<span
key="sellingPriceWithTaxWithoutUnit"
className={handles.sellingPriceWithTaxWithoutUnit}
>
<FormattedCurrency value={sellingPriceWithTaxWithoutUnit} />
</span>
),
sellingPriceWithUnitMultiplier: (
<span
key="sellingPriceWithUnitMultiplier"
Expand Down
Loading