fix(core-flows): fix update tax lines to apply tax rule by product type (#13202)

* test(draft-order): add draft order creation test with tax application by product type

* fix: add `product_type.id` and `items.product_type_id` fields to order utilities

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Jan Biardzki
2025-08-14 20:07:43 +02:00
committed by GitHub
parent 623cf05fab
commit 257e71f988
3 changed files with 166 additions and 0 deletions

View File

@@ -386,6 +386,169 @@ medusaIntegrationTestRunner({
expect(response.status).toEqual(200)
})
it("should create a draft order and apply tax by product type", async () => {
const productType = await productModule.createProductTypes({
value: "test_product_type",
})
const region = await regionModuleService.createRegions({
name: "US",
currency_code: "usd",
})
const [taxRegion] = await taxModule.createTaxRegions([{
country_code: "US",
provider_id: "tp_system",
default_tax_rate: { name: "US Default Rate", rate: 5, code: "US_DEF" },
}])
const [taxRate] = await taxModule.createTaxRates([
{
tax_region_id: taxRegion.id,
name: "US Reduced",
rate: 3,
code: "USREDUCE_PROD_TYPE",
}])
await taxModule.createTaxRateRules([
{
reference: "product_type",
reference_id: productType.id,
tax_rate_id: taxRate.id,
}
])
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
const location = await stockLocationModule.createStockLocations({
name: "Warehouse",
})
const [product] = await productModule.createProducts([
{
title: "Test product",
type_id: productType.id,
variants: [
{
title: "Test variant",
},
],
},
])
const inventoryItem = await inventoryModule.createInventoryItems({
sku: "inv-1234",
})
await inventoryModule.createInventoryLevels([
{
inventory_item_id: inventoryItem.id,
location_id: location.id,
stocked_quantity: 2,
reserved_quantity: 0,
},
])
const [priceSet] = await pricingModule.createPriceSets([
{
prices: [
{
amount: 3000,
currency_code: "usd",
},
],
},
])
await api.post(
"/admin/price-preferences",
{
attribute: "currency_code",
value: "usd",
is_tax_inclusive: true,
},
adminHeaders
)
await remoteLink.create([
{
[Modules.PRODUCT]: {
variant_id: product.variants[0].id,
},
[Modules.PRICING]: {
price_set_id: priceSet.id,
},
},
{
[Modules.SALES_CHANNEL]: {
sales_channel_id: salesChannel.id,
},
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
},
{
[Modules.PRODUCT]: {
variant_id: product.variants[0].id,
},
[Modules.INVENTORY]: {
inventory_item_id: inventoryItem.id,
},
},
])
const payload = {
email: "oli@test.dk",
region_id: region.id,
sales_channel_id: salesChannel.id,
currency_code: "usd",
shipping_address: {
first_name: "Test",
last_name: "Test",
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
phone: "12345",
},
billing_address: {
first_name: "Test",
last_name: "Test",
address_1: "Test",
city: "Test",
country_code: "US",
postal_code: "12345",
},
promo_codes: ["testytest"],
items: [
{
variant_id: product.variants[0].id,
product_type_id: productType.id,
quantity: 2,
},
],
shipping_methods: [
{
name: "test-method",
shipping_option_id: "test-option",
amount: 100,
},
],
}
const response = await api.post(
"/admin/draft-orders",
payload,
adminHeaders
)
expect(response.data.draft_order.items[0].tax_lines[0].code).toEqual("USREDUCE_PROD_TYPE")
expect(response.data.draft_order.items[0].tax_lines[0].rate).toEqual(3)
})
})
},
})

View File

@@ -11,6 +11,7 @@ export const productVariantsFields = [
"product.subtitle",
"product.thumbnail",
"product.type.value",
"product.type.id",
"product.collection.title",
"product.handle",
"calculated_price.*",

View File

@@ -24,6 +24,7 @@ const completeOrderFields = [
"items.product_description",
"items.product_subtitle",
"items.product_type",
"items.product_type_id",
"items.product_collection",
"items.product_handle",
"items.variant_sku",
@@ -107,6 +108,7 @@ const lineItemFields = [
"product_description",
"product_subtitle",
"product_type",
"product_type_id",
"product_collection",
"product_handle",
"variant_sku",