feat(promotion, dashboard, core-flows, cart, types, utils, medusa): tax inclusive promotions (#12412)
* feat: tax inclusive promotions * feat: add a totals test case * feat: add integration test * chore: changeset * fix: typo * chore: refactor * fix: tests * fix: rest of buyget action tests * fix: cart spec * chore: expand integration test with item level totals * feat: add a few more test cases --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
@@ -2913,6 +2913,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
item_id: expect.any(String),
|
||||
is_tax_inclusive: false,
|
||||
promotion_id: null,
|
||||
deleted_at: null,
|
||||
amount: 100,
|
||||
@@ -3020,6 +3021,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
item_id: expect.any(String),
|
||||
is_tax_inclusive: false,
|
||||
promotion_id: null,
|
||||
deleted_at: null,
|
||||
amount: 200,
|
||||
|
||||
@@ -998,6 +998,16 @@
|
||||
"nullable": false,
|
||||
"mappedType": "decimal"
|
||||
},
|
||||
"is_tax_inclusive": {
|
||||
"name": "is_tax_inclusive",
|
||||
"type": "boolean",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "false",
|
||||
"mappedType": "boolean"
|
||||
},
|
||||
"provider_id": {
|
||||
"name": "provider_id",
|
||||
"type": "text",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20250508081553 extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`alter table if exists "cart_line_item_adjustment" add column if not exists "is_tax_inclusive" boolean not null default false;`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`alter table if exists "cart_line_item_adjustment" drop column if exists "is_tax_inclusive";`);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ const LineItemAdjustment = model
|
||||
description: model.text().nullable(),
|
||||
code: model.text().nullable(),
|
||||
amount: model.bigNumber(),
|
||||
is_tax_inclusive: model.boolean().default(false),
|
||||
provider_id: model.text().nullable(),
|
||||
promotion_id: model.text().nullable(),
|
||||
metadata: model.json().nullable(),
|
||||
|
||||
@@ -189,12 +189,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 100,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -326,18 +328,21 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 30,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -434,12 +439,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -497,6 +504,7 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 500,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -624,12 +632,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 10,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 15,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -726,24 +736,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 30,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 45,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 10.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -813,12 +827,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMO_PERCENTAGE_1",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMO_PERCENTAGE_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -915,12 +931,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1103,12 +1121,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 100,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 300,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1177,12 +1197,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 100,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 300,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1278,24 +1300,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 12.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 37.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 7.5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 22.5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1391,12 +1417,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1574,12 +1602,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 20,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 60,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1648,12 +1678,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 20,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 60,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1748,24 +1780,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 15,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 4.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 13.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -1838,24 +1874,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 150,
|
||||
code: "PROMO_PERCENTAGE_1",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_wool_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMO_PERCENTAGE_1",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 75,
|
||||
code: "PROMO_PERCENTAGE_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_wool_tshirt",
|
||||
amount: 25,
|
||||
code: "PROMO_PERCENTAGE_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -1914,12 +1954,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 300,
|
||||
code: "PROMO_PERCENTAGE_3",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_wool_tshirt",
|
||||
amount: 100,
|
||||
code: "PROMO_PERCENTAGE_3",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -2014,24 +2056,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 15,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 4.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 13.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -4174,12 +4220,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -4241,12 +4289,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -4329,24 +4379,28 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 12.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 37.5,
|
||||
code: "PROMOTION_TEST_2",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 7.5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 22.5,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -4429,12 +4483,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 50,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
@@ -4519,12 +4575,14 @@ moduleIntegrationTestRunner({
|
||||
item_id: "item_cotton_tshirt",
|
||||
amount: 100,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
{
|
||||
action: "addItemAdjustment",
|
||||
item_id: "item_cotton_sweater",
|
||||
amount: 150,
|
||||
code: "PROMOTION_TEST",
|
||||
is_tax_inclusive: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -332,6 +332,16 @@
|
||||
"default": "false",
|
||||
"mappedType": "boolean"
|
||||
},
|
||||
"is_tax_inclusive": {
|
||||
"name": "is_tax_inclusive",
|
||||
"type": "boolean",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"default": "false",
|
||||
"mappedType": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250508081510 extends Migration {
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(
|
||||
`alter table if exists "promotion" add column if not exists "is_tax_inclusive" boolean not null default false;`
|
||||
)
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(
|
||||
`alter table if exists "promotion" drop column if exists "is_tax_inclusive";`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ const Promotion = model
|
||||
id: model.id({ prefix: "promo" }).primaryKey(),
|
||||
code: model.text().searchable(),
|
||||
is_automatic: model.boolean().default(false),
|
||||
is_tax_inclusive: model.boolean().default(false),
|
||||
type: model.enum(PromotionUtils.PromotionType).index("IDX_promotion_type"),
|
||||
status: model
|
||||
.enum(PromotionUtils.PromotionStatus)
|
||||
|
||||
@@ -164,6 +164,7 @@ function applyPromotionToItems(
|
||||
item_id: item.id,
|
||||
amount,
|
||||
code: promotion.code!,
|
||||
is_tax_inclusive: promotion.is_tax_inclusive,
|
||||
})
|
||||
} else if (isTargetShippingMethod) {
|
||||
computedActions.push({
|
||||
|
||||
Reference in New Issue
Block a user