diff --git a/packages/core/src/service/helpers/order-calculator/order-calculator.spec.ts b/packages/core/src/service/helpers/order-calculator/order-calculator.spec.ts index 145fd21d63..461cc6404c 100644 --- a/packages/core/src/service/helpers/order-calculator/order-calculator.spec.ts +++ b/packages/core/src/service/helpers/order-calculator/order-calculator.spec.ts @@ -25,6 +25,7 @@ import { MockTaxRateService, taxCategoryReduced, taxCategoryStandard, + taxCategoryZero, } from '../../../testing/order-test-utils'; import { WorkerService } from '../../../worker/worker.service'; import { ShippingMethodService } from '../../services/shipping-method.service'; @@ -590,6 +591,27 @@ describe('OrderCalculator', () => { expect(order.totalWithTax).toBe(50); assertOrderTotalsAddUp(order); }); + + it('prices include tax at 0%', async () => { + const ctx = createRequestContext({ pricesIncludeTax: true }); + const order = createOrder({ + ctx, + lines: [ + { + listPrice: 100, + taxCategory: taxCategoryZero, + quantity: 1, + }, + ], + }); + await orderCalculator.applyPriceAdjustments(ctx, order, [promotion]); + + expect(order.subTotal).toBe(50); + expect(order.discounts.length).toBe(1); + expect(order.discounts[0].description).toBe('50% off order'); + expect(order.totalWithTax).toBe(50); + assertOrderTotalsAddUp(order); + }); }); }); diff --git a/packages/core/src/service/helpers/order-calculator/order-calculator.ts b/packages/core/src/service/helpers/order-calculator/order-calculator.ts index f464cc62da..7e7c63596b 100644 --- a/packages/core/src/service/helpers/order-calculator/order-calculator.ts +++ b/packages/core/src/service/helpers/order-calculator/order-calculator.ts @@ -276,7 +276,7 @@ export class OrderCalculator { const adjustment = await promotion.apply(ctx, { order }); if (adjustment && adjustment.amount !== 0) { const amount = adjustment.amount; - const weights = order.lines.map(l => l.proratedLinePrice * l.taxRate); + const weights = order.lines.map(l => l.proratedLinePrice * Math.max(l.taxRate, 1)); const distribution = prorate(weights, amount); order.lines.forEach((line, i) => { const shareOfAmount = distribution[i]; diff --git a/packages/core/src/testing/order-test-utils.ts b/packages/core/src/testing/order-test-utils.ts index af2883e64c..7cbd80ff37 100644 --- a/packages/core/src/testing/order-test-utils.ts +++ b/packages/core/src/testing/order-test-utils.ts @@ -63,6 +63,10 @@ export const taxCategoryReduced = new TaxCategory({ id: 'taxCategoryReduced', name: 'Reduced Tax', }); +export const taxCategoryZero = new TaxCategory({ + id: 'taxCategoryZero', + name: 'Zero Tax', +}); export const zoneDefault = new Zone({ id: 'zoneDefault', name: 'Default Zone', @@ -91,6 +95,14 @@ export const taxRateDefaultReduced = new TaxRate({ zone: zoneDefault, category: taxCategoryReduced, }); +export const taxRateDefaultZero = new TaxRate({ + id: 'taxRateDefaultZero', + name: 'Default Zero Tax', + value: 0, + enabled: true, + zone: zoneDefault, + category: taxCategoryZero, +}); export const taxRateOtherStandard = new TaxRate({ id: 'taxRateOtherStandard', name: 'Other Standard', @@ -112,6 +124,7 @@ export class MockTaxRateService { private activeTaxRates = [ taxRateDefaultStandard, taxRateDefaultReduced, + taxRateDefaultZero, taxRateOtherStandard, taxRateOtherReduced, ];