OrderTaxCalculationStrategy
OrderTaxCalculationStrategy
Defines how order-level tax totals and the tax summary are calculated.
The default implementation (DefaultOrderTaxCalculationStrategy) rounds tax at the individual line level and then sums. This is the standard Vendure behaviour.
An alternative implementation (OrderLevelTaxCalculationStrategy) groups net subtotals by tax rate and rounds once per group, which eliminates per-line rounding accumulation errors. This approach is required by certain jurisdictions and ERP systems.
This is configured via the taxOptions.orderTaxCalculationStrategy property of
your VendureConfig.
- Extends:
InjectableStrategy
calculateOrderTotals
(order: Order) => OrderTotalsResultCalculates the order totals (subTotal, subTotalWithTax, shipping, shippingWithTax) for the given Order. This is called frequently during promotion application, so it should be as cheap as possible - avoid building tax summary data here.
The Order's lines and surcharges relations must be loaded.
shippingLines may be empty/unloaded, in which case shipping is treated as zero.
calculateTaxSummary
(order: Order) => OrderTaxSummary[]Calculates the full tax summary for the given Order. This is called once
when the taxSummary getter is accessed on the Order entity.
This method must be synchronous, as it is called from the taxSummary getter
on the Order entity.
The Order's lines, surcharges, and shippingLines relations must be loaded.
DefaultOrderTaxCalculationStrategy
The default OrderTaxCalculationStrategy. Tax is rounded at the individual line level and then summed. This matches the standard Vendure behaviour prior to the introduction of this strategy.
- Implements:
OrderTaxCalculationStrategy
calculateOrderTotals
(order: Order) => OrderTotalsResultcalculateTaxSummary
(order: Order) => OrderTaxSummary[]OrderLevelTaxCalculationStrategy
An OrderTaxCalculationStrategy that groups net subtotals by tax rate and rounds once per group. This eliminates per-line rounding accumulation errors present in the DefaultOrderTaxCalculationStrategy.
This approach is required by certain jurisdictions and ERP systems that expect tax to be calculated on the subtotal per tax rate rather than per line.
Note that when using this strategy, the taxTotal in the tax summary may differ
by ±1 minor unit from the sum of individual line-level proratedLineTax values.
This is expected and is the intended behaviour.
Example
- Implements:
OrderTaxCalculationStrategy
calculateOrderTotals
(order: Order) => OrderTotalsResultcalculateTaxSummary
(order: Order) => OrderTaxSummary[]OrderTotalsResult
The result of an OrderTaxCalculationStrategy's calculateOrderTotals method.