diff --git a/packages/core-orders/src/director/OrderPricingSheet.ts b/packages/core-orders/src/director/OrderPricingSheet.ts index 2cf4a064af..947d3cdf32 100644 --- a/packages/core-orders/src/director/OrderPricingSheet.ts +++ b/packages/core-orders/src/director/OrderPricingSheet.ts @@ -93,13 +93,11 @@ export const OrderPricingSheet = ( }); }, - gross() { - // tax is included 2 times, this is only true for Order Pricing! - return basePricingSheet.sum() - this.taxSum(); - }, - - net() { - return basePricingSheet.sum() - this.taxSum() - this.taxSum(); + discountSum(discountId) { + return basePricingSheet.sum({ + category: OrderPricingRowCategory.Discounts, + discountId, + }); }, total({ category, useNetPrice, discountId } = { useNetPrice: false }) { diff --git a/packages/plugins/src/pricing/order-delivery.ts b/packages/plugins/src/pricing/order-delivery.ts index 5b159698c6..a7eb0fb77f 100644 --- a/packages/plugins/src/pricing/order-delivery.ts +++ b/packages/plugins/src/pricing/order-delivery.ts @@ -30,7 +30,7 @@ export const OrderDelivery: IOrderPricingAdapter = { params.context, ); const tax = pricing.taxSum(); - const shipping = pricing.gross(); + const shipping = pricing.net(); pricingAdapter .resultSheet() diff --git a/packages/plugins/src/pricing/order-discount.ts b/packages/plugins/src/pricing/order-discount.ts index c13015843d..4bb23215bc 100644 --- a/packages/plugins/src/pricing/order-discount.ts +++ b/packages/plugins/src/pricing/order-discount.ts @@ -85,7 +85,12 @@ export const OrderDiscount: IOrderPricingAdapter = { params.context, ); const tax = pricing.taxSum(); - const items = pricing.gross(); + const items = pricing.net(); return { taxes: current.taxes + tax, items: current.items + items, diff --git a/packages/plugins/src/pricing/order-payment.ts b/packages/plugins/src/pricing/order-payment.ts index 2f7a5030d2..5bcffa3853 100644 --- a/packages/plugins/src/pricing/order-payment.ts +++ b/packages/plugins/src/pricing/order-payment.ts @@ -31,7 +31,7 @@ const OrderPayment: IOrderPricingAdapter = { params.context, ); const tax = pricing.taxSum(); - const paymentFees = pricing.gross(); + const paymentFees = pricing.net(); pricingAdapter .resultSheet() diff --git a/packages/utils/src/director/BasePricingSheet.ts b/packages/utils/src/director/BasePricingSheet.ts index 538aa9b859..58cc9ac12c 100644 --- a/packages/utils/src/director/BasePricingSheet.ts +++ b/packages/utils/src/director/BasePricingSheet.ts @@ -47,17 +47,19 @@ export interface PricingSheetParams { export const BasePricingSheet = ( params: PricingSheetParams, ): IBasePricingSheet => { + const calculation = params.calculation || []; + const pricingSheet: IBasePricingSheet = { - calculation: params.calculation || [], + calculation, currency: params.currency, quantity: params.quantity, getRawPricingSheet() { - return this.calculation; + return calculation; }, isValid() { - return this.calculation.length > 0; + return calculation.length > 0; }, sum(filter) { @@ -89,7 +91,7 @@ export const BasePricingSheet = ( return { amount: Math.round(useNetPrice ? netAmount : netAmount + taxAmountForCategory), - currency: this.currency, + currency: params.currency, }; }, @@ -100,7 +102,7 @@ export const BasePricingSheet = ( (row: Calculation) => !!row && (filter[filterKey] === undefined || row[filterKey] === filter[filterKey]), ), - this.calculation, + calculation, ); return filteredCalculation; @@ -108,12 +110,12 @@ export const BasePricingSheet = ( resetCalculation(calculationSheet) { calculationSheet.filterBy().forEach(({ amount, ...row }: Calculation) => { - this.calculation.push({ + pricingSheet.calculation.push({ ...row, amount: amount * -1, } as Calculation); }); - return this.calculation; + return pricingSheet.calculation; }, }; diff --git a/tests/seeds/orders.js b/tests/seeds/orders.js index 5a0ffa9c55..a4218ce30a 100644 --- a/tests/seeds/orders.js +++ b/tests/seeds/orders.js @@ -20,7 +20,8 @@ export const SimpleOrder = { category: 'ITEMS', amount: 30000, }, - { category: 'TAXES', amount: 2144.8467966573808 }, + { category: 'ITEMS', amount: -2144.8467966573808 }, + { category: 'TAXES', amount: 2144.8467966573808, baseCategory: 'ITEMS' }, { category: 'PAYMENT', amount: 0, @@ -115,6 +116,7 @@ export const SimplePosition = { isTaxable: false, isNetPrice: false, rate: 0.077, + baseCategory: 'ITEM', meta: { adapter: 'shop.unchained.pricing.product-swiss-tax', }, @@ -214,9 +216,14 @@ export const DiscountedOrder = { category: 'ITEMS', amount: 100000, }, + { + category: 'ITEMS', + amount: -7149.489322191272, + }, { category: 'TAXES', amount: 7149.489322191272, + baseCategory: 'ITEMS', }, { category: 'PAYMENT', @@ -231,9 +238,16 @@ export const DiscountedOrder = { amount: -10000, discountId: 'discounted-order-discount', }, + { + category: 'DISCOUNTS', + amount: 714.9489322191266, + discountId: 'discounted-order-discount', + }, { category: 'TAXES', amount: -714.9489322191266, + baseCategory: 'DISCOUNTS', + discountId: 'discounted-order-discount', }, ], }; @@ -304,6 +318,7 @@ export const DiscountedPosition = { category: 'TAX', amount: 8579.387186629523, rate: 0.077, + baseCategory: 'ITEM', meta: { adapter: 'shop.unchained.pricing.product-swiss-tax', }, @@ -321,6 +336,7 @@ export const DiscountedPosition = { category: 'TAX', amount: -4289.6935933147615, rate: 0.077, + baseCategory: 'DISCOUNT', meta: { adapter: 'shop.unchained.pricing.product-swiss-tax', },