diff --git a/integration-tests/modules/__tests__/order/draft-order.spec.ts b/integration-tests/modules/__tests__/order/draft-order.spec.ts index b3d26b1766..6aee2d4a2b 100644 --- a/integration-tests/modules/__tests__/order/draft-order.spec.ts +++ b/integration-tests/modules/__tests__/order/draft-order.spec.ts @@ -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) + }) }) }, }) diff --git a/packages/core/core-flows/src/order/utils/fields.ts b/packages/core/core-flows/src/order/utils/fields.ts index c53bb7ea54..a82aea39a2 100644 --- a/packages/core/core-flows/src/order/utils/fields.ts +++ b/packages/core/core-flows/src/order/utils/fields.ts @@ -11,6 +11,7 @@ export const productVariantsFields = [ "product.subtitle", "product.thumbnail", "product.type.value", + "product.type.id", "product.collection.title", "product.handle", "calculated_price.*", diff --git a/packages/core/core-flows/src/order/workflows/update-tax-lines.ts b/packages/core/core-flows/src/order/workflows/update-tax-lines.ts index a7cf15f1a2..3333f45471 100644 --- a/packages/core/core-flows/src/order/workflows/update-tax-lines.ts +++ b/packages/core/core-flows/src/order/workflows/update-tax-lines.ts @@ -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",