Fix(medusa): Swaps in tax inclusive regions (#2557)

**What**
- Ensure that swaps can be created for orders with discounts in tax inclusive regions

**How**
- Retrieve cart with discounts and region before creating adjustments for line items in cart. 
  - In `discountService.calculateDiscountForLineItem` we used the method `totalsService.getLineItemTotals` if a line-item is tax inclusive. This method uses some fields from the cart that aren't populated on cart creation (such a `items` which caused the original error).

**Testing**
- add integration test `swaps > tax inclusive > "Complete swap flow with discount"` that creates a swap in the following environment
  - tax inclusive region 
  - tax inclusive line item to be swapped
  - fixed type discount with allocation: total

Fixes CORE-748
This commit is contained in:
Philip Korsholm
2022-11-07 10:47:26 +00:00
committed by GitHub
parent 434b11af46
commit 15d6f92964
4 changed files with 552 additions and 302 deletions
@@ -14,7 +14,7 @@ export type ProductVariantFactoryData = {
inventory_quantity?: number
title?: string
options?: { option_id: string; value: string }[]
prices?: { currency: string; amount: number }[]
prices?: { currency: string; amount: number, region_id?: string }[]
}
export const simpleProductVariantFactory = async (
@@ -32,7 +32,7 @@ export const simpleProductVariantFactory = async (
const toSave = manager.create(ProductVariant, {
id,
product_id: data.product_id,
sku: data.sku ?? null,
sku: data.sku ,
inventory_quantity:
typeof data.inventory_quantity !== "undefined"
? data.inventory_quantity
@@ -59,6 +59,7 @@ export const simpleProductVariantFactory = async (
variant_id: id,
currency_code: p.currency,
amount: p.amount,
region_id: p.region_id ,
})
}