fix(types,medusa): calculate taxes for original price (#11692)
This commit is contained in:
6
.changeset/chilled-kings-flow.md
Normal file
6
.changeset/chilled-kings-flow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/types": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(types,medusa): calculate taxes for original price
|
||||
@@ -2369,6 +2369,12 @@ medusaIntegrationTestRunner({
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"calculated_amount_without_tax"
|
||||
)
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_with_tax"
|
||||
)
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_without_tax"
|
||||
)
|
||||
})
|
||||
|
||||
it("should not return tax pricing if automatic taxes are off when listing products", async () => {
|
||||
@@ -2386,6 +2392,12 @@ medusaIntegrationTestRunner({
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"calculated_amount_without_tax"
|
||||
)
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_with_tax"
|
||||
)
|
||||
expect(products[0].variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_without_tax"
|
||||
)
|
||||
})
|
||||
|
||||
it("should return prices with and without tax for a tax inclusive region when listing products", async () => {
|
||||
@@ -2430,6 +2442,66 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("should return prices with and without tax for a tax inclusive region when listing products with a price list sale", async () => {
|
||||
const customerGroup = (
|
||||
await api.post(
|
||||
"/admin/customer-groups",
|
||||
{ name: "VIP" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.customer_group
|
||||
|
||||
await api.post(
|
||||
`/admin/customer-groups/${customerGroup.id}/customers`,
|
||||
{ add: [customer.id] },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
await api.post(
|
||||
`/admin/price-lists`,
|
||||
{
|
||||
title: "test price list",
|
||||
description: "test",
|
||||
status: PriceListStatus.ACTIVE,
|
||||
type: PriceListType.SALE,
|
||||
prices: [
|
||||
{
|
||||
amount: 35,
|
||||
currency_code: euRegion.currency_code,
|
||||
variant_id: product1.variants[0].id,
|
||||
},
|
||||
],
|
||||
rules: { "customer.groups.id": [customerGroup.id] },
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const products = (
|
||||
await api.get(
|
||||
`/store/products?fields=id,*variants.calculated_price®ion_id=${euRegion.id}&country_code=it`,
|
||||
storeHeadersWithCustomer
|
||||
)
|
||||
).data.products
|
||||
|
||||
expect(products.length).toBe(2)
|
||||
expect(products[0].variants).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
calculated_price: expect.objectContaining({
|
||||
currency_code: "eur",
|
||||
calculated_amount: 35,
|
||||
original_amount: 45,
|
||||
is_calculated_price_price_list: true,
|
||||
calculated_amount_with_tax: 38.5,
|
||||
calculated_amount_without_tax: 35,
|
||||
original_amount_with_tax: 45,
|
||||
original_amount_without_tax: 40.90909090909091,
|
||||
}),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should return prices with and without tax for a tax exclusive region when listing products", async () => {
|
||||
const products = (
|
||||
await api.get(
|
||||
@@ -2547,6 +2619,13 @@ medusaIntegrationTestRunner({
|
||||
expect(product.variants[0].calculated_price).not.toHaveProperty(
|
||||
"calculated_amount_without_tax"
|
||||
)
|
||||
|
||||
expect(product.variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_with_tax"
|
||||
)
|
||||
expect(product.variants[0].calculated_price).not.toHaveProperty(
|
||||
"original_amount_without_tax"
|
||||
)
|
||||
})
|
||||
|
||||
it("should return prices with and without tax for a tax inclusive region when fetching a single product", async () => {
|
||||
|
||||
@@ -46,6 +46,16 @@ export interface BaseCalculatedPriceSet {
|
||||
*/
|
||||
original_amount: number | null
|
||||
|
||||
/**
|
||||
* The amount of the original price with taxes included. If the original price is tax inclusive, this field will be the same as `original_amount`.
|
||||
*/
|
||||
original_amount_with_tax: number | null
|
||||
|
||||
/**
|
||||
* The amount of the original price without taxes included. If the original price is tax exclusive, this field will be the same as `original_amount`.
|
||||
*/
|
||||
original_amount_without_tax: number | null
|
||||
|
||||
/**
|
||||
* The currency code of the calculated price, or null if there isn't a calculated price.
|
||||
*/
|
||||
|
||||
@@ -77,6 +77,19 @@ export const wrapProductsWithTaxPrices = async <T>(
|
||||
|
||||
variant.calculated_price.calculated_amount_with_tax = priceWithTax
|
||||
variant.calculated_price.calculated_amount_without_tax = priceWithoutTax
|
||||
|
||||
const {
|
||||
priceWithTax: originalPriceWithTax,
|
||||
priceWithoutTax: originalPriceWithoutTax,
|
||||
} = calculateAmountsWithTax({
|
||||
taxLines: taxRatesForVariant,
|
||||
amount: variant.calculated_price!.original_amount!,
|
||||
includesTax: variant.calculated_price!.is_original_price_tax_inclusive!,
|
||||
})
|
||||
|
||||
variant.calculated_price.original_amount_with_tax = originalPriceWithTax
|
||||
variant.calculated_price.original_amount_without_tax =
|
||||
originalPriceWithoutTax
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user