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: new sellingPrice value considering unit multiplier and tax percentage for product price #114

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"es6": true,
"jest": true
}
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- SellingPriceWithUnitMultiplierAndTax variable for ICU
### Fixed

- I18n on readme file.
Expand Down
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ In addition, remember to take into account the message variables for each block,
| `measurementUnit` | `string` | Unit of measure text. |
| `hasUnitMultiplier` | `boolean` | Determines whether the product has a unit multiplier different from 1 (`true`) or not (`false`). |
| `unitMultiplier` | `string` | Value of the unit multiplier. |
| Message variable | Type | Description |
| --- | --- | --- |
| `sellingPriceValue` | `string` | Selling price value. |
| `sellingPriceWithTax` | `string` | Selling price with tax. |
| `sellingPriceWithUnitMultiplier` | `string` | Selling price multiplied by unit multiplier. |
| `sellingPriceWithUnitMultiplierAndTax` | `string` | Selling price multiplied by unit multiplier and added tax. |
| `taxPercentage` | `string` | Tax percentage. |
| `hasListPrice` | `boolean` | Whether the product has a list price (`true`) or not (`false`). |
| `taxValue` | `string` | Tax value. |
| `hasMeasurementUnit` | `boolean` | Whether the product has a measurement unit (`true`) or not (`false`). |
| `measurementUnit` | `string` | Measure unit text. |
| `hasUnitMultiplier` | `boolean` | Whether the product has a unit multiplier different than 1 (`true`) or not (`false`). |
| `unitMultiplier` | `string` | Value of the unit multiplier. |

You can use the `product-selling-price` `sellingPriceWithUnitMultiplier`, `hasMeasurementUnit`, `unitMultiplier`, and `measurementUnit` variables together to render the unit of measure and unit multiplier on products that have it.

Expand Down
2 changes: 1 addition & 1 deletion messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"admin/selling-price-range-message.title": "Preço de venda (faixa)",
"admin/selling-price-range-no-range-message.description": "Mensagem a ser mostrada quando não houver diferença de preço entre SKUs.\nValores disponíveis para interpolação: '{sellingPriceValue}, {sellingPriceWithTax}'",
"admin/selling-price-range-no-range-message.title": "Preço de venda (sem faixa)"
}
}
14 changes: 13 additions & 1 deletion react/SellingPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const CSS_HANDLES = [
'sellingPriceValue',
'sellingPriceWithTax',
'sellingPriceWithUnitMultiplier',
'sellingPriceWithUnitMultiplierAndTax',
'taxPercentage',
'taxValue',
'measurementUnit',
Expand Down Expand Up @@ -75,7 +76,10 @@ function SellingPrice({
productContextValue?.selectedItem?.measurementUnit ?? ''

const unitMultiplier = productContextValue?.selectedItem?.unitMultiplier ?? 1
const sellingPriceWithUnitMultiplier = commercialOffer.Price * unitMultiplier
const sellingPriceWithUnitMultiplier = sellingPriceValue * unitMultiplier

const sellingPriceWithUnitMultiplierAndTax =
(sellingPriceValue + sellingPriceValue * (taxPercentage/unitMultiplier)) * unitMultiplier

const taxValue = commercialOffer.Tax

Expand Down Expand Up @@ -118,6 +122,14 @@ function SellingPrice({
<FormattedCurrency value={sellingPriceWithUnitMultiplier} />
</span>
),
sellingPriceWithUnitMultiplierAndTax: (
<span
key="sellingPriceWithUnitMultiplierAndTax"
className={handles.sellingPriceWithUnitMultiplierAndTax}
>
<FormattedCurrency value={sellingPriceWithUnitMultiplierAndTax} />
</span>
),
taxPercentage: (
<span key="taxPercentage" className={handles.taxPercentage}>
<FormattedNumber value={taxPercentage} style="percent" />
Expand Down
Loading