fix(pricing): Calculate prices with multiple rule values (#13079)
This commit is contained in:
+172
-14
@@ -473,7 +473,6 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
{ context }
|
||||
)
|
||||
|
||||
|
||||
expect(calculatedPrice).toEqual([
|
||||
{
|
||||
id: "price-set-PLN",
|
||||
@@ -1233,11 +1232,27 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
])
|
||||
})
|
||||
|
||||
it("should return best price list price first when price list conditions match", async () => {
|
||||
await createPriceLists(service)
|
||||
it("should return cheapest price list price first when price list conditions match", async () => {
|
||||
await createPriceLists(
|
||||
service,
|
||||
{
|
||||
title: "Test Price List One",
|
||||
description: "test description",
|
||||
type: PriceListType.OVERRIDE,
|
||||
status: PriceListStatus.ACTIVE,
|
||||
},
|
||||
{},
|
||||
defaultPriceListPrices
|
||||
)
|
||||
|
||||
await createPriceLists(
|
||||
service,
|
||||
{
|
||||
title: "Test Price List Two",
|
||||
description: "test description",
|
||||
type: PriceListType.OVERRIDE,
|
||||
status: PriceListStatus.ACTIVE,
|
||||
},
|
||||
{},
|
||||
defaultPriceListPrices.map((price) => {
|
||||
return { ...price, amount: price.amount / 2 }
|
||||
@@ -1245,7 +1260,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
)
|
||||
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
{ id: ["price-set-EUR", "price-set-PLN"] },
|
||||
{ id: ["price-set-PLN"] },
|
||||
{
|
||||
context: {
|
||||
currency_code: "PLN",
|
||||
@@ -1261,32 +1276,32 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
id: "price-set-PLN",
|
||||
is_calculated_price_price_list: true,
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
calculated_amount: 232,
|
||||
calculated_amount: 116,
|
||||
raw_calculated_amount: {
|
||||
value: "232",
|
||||
value: "116",
|
||||
precision: 20,
|
||||
},
|
||||
is_original_price_price_list: false,
|
||||
is_original_price_price_list: true,
|
||||
is_original_price_tax_inclusive: false,
|
||||
original_amount: 400,
|
||||
original_amount: 116,
|
||||
raw_original_amount: {
|
||||
value: "400",
|
||||
value: "116",
|
||||
precision: 20,
|
||||
},
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: expect.any(String),
|
||||
price_list_type: "sale",
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
original_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
price_list_id: expect.any(String),
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
},
|
||||
])
|
||||
@@ -1978,6 +1993,149 @@ moduleIntegrationTestRunner<IPricingModuleService>({
|
||||
])
|
||||
})
|
||||
|
||||
it("should return price list prices for multiple price lists with customer groups", async () => {
|
||||
const [{ id }] = await createPriceLists(
|
||||
service,
|
||||
{ type: "override" },
|
||||
{
|
||||
["customer.groups.id"]: ["vip-customer-group-id"],
|
||||
},
|
||||
[
|
||||
{
|
||||
amount: 600,
|
||||
currency_code: "EUR",
|
||||
price_set_id: "price-set-EUR",
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
const [{ id: idTwo }] = await createPriceLists(
|
||||
service,
|
||||
{ type: "override" },
|
||||
{
|
||||
["customer.groups.id"]: ["vip-customer-group-id-1"],
|
||||
},
|
||||
[
|
||||
{
|
||||
amount: 400,
|
||||
currency_code: "EUR",
|
||||
price_set_id: "price-set-EUR",
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
{ id: ["price-set-EUR"] },
|
||||
{
|
||||
context: {
|
||||
currency_code: "EUR",
|
||||
// @ts-ignore
|
||||
customer: {
|
||||
groups: {
|
||||
id: ["vip-customer-group-id", "vip-customer-group-id-1"],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceSetsResult).toEqual([
|
||||
{
|
||||
id: "price-set-EUR",
|
||||
is_calculated_price_price_list: true,
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
calculated_amount: 400,
|
||||
raw_calculated_amount: {
|
||||
value: "400",
|
||||
precision: 20,
|
||||
},
|
||||
is_original_price_price_list: true,
|
||||
is_original_price_tax_inclusive: false,
|
||||
original_amount: 400,
|
||||
raw_original_amount: {
|
||||
value: "400",
|
||||
precision: 20,
|
||||
},
|
||||
currency_code: "EUR",
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: idTwo,
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
original_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: idTwo,
|
||||
price_list_type: "override",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should return price list prices when price list conditions match within prices", async () => {
|
||||
await createPriceLists(service, {}, { region_id: ["DE", "PL"] }, [
|
||||
...defaultPriceListPrices,
|
||||
{
|
||||
amount: 111,
|
||||
currency_code: "PLN",
|
||||
price_set_id: "price-set-PLN",
|
||||
rules: {
|
||||
region_id: "DE",
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
const priceSetsResult = await service.calculatePrices(
|
||||
{ id: ["price-set-EUR", "price-set-PLN"] },
|
||||
{
|
||||
context: {
|
||||
currency_code: "PLN",
|
||||
region_id: "DE",
|
||||
customer_group_id: "vip-customer-group-id",
|
||||
company_id: "medusa-company-id",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
expect(priceSetsResult).toEqual([
|
||||
{
|
||||
id: "price-set-PLN",
|
||||
is_calculated_price_price_list: true,
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
calculated_amount: 111,
|
||||
raw_calculated_amount: {
|
||||
value: "111",
|
||||
precision: 20,
|
||||
},
|
||||
is_original_price_price_list: false,
|
||||
is_original_price_tax_inclusive: false,
|
||||
original_amount: 400,
|
||||
raw_original_amount: {
|
||||
value: "400",
|
||||
precision: 20,
|
||||
},
|
||||
currency_code: "PLN",
|
||||
calculated_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: expect.any(String),
|
||||
price_list_type: "sale",
|
||||
min_quantity: null,
|
||||
max_quantity: null,
|
||||
},
|
||||
original_price: {
|
||||
id: expect.any(String),
|
||||
price_list_id: null,
|
||||
price_list_type: null,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
},
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("should not return price list prices when price list conditions are met but price rules are not", async () => {
|
||||
await createPriceLists(service, {}, { region_id: ["DE", "PL"] }, [
|
||||
...defaultPriceListPrices,
|
||||
|
||||
Reference in New Issue
Block a user