User guide
Define the tax rates used by Sales, then assign the appropriate rate to a product or variant. Inspect the stored tax details when reviewing how a recorded price was calculated.
The Sales module owns tax definitions so every downstream surface (catalog, orders, quotes, invoices) reuses a single source of truth. Tax rates are tenant + organization scoped and stored as sales_tax_rates, which are administered from Sales → Configuration → Tax classes in the backend UI. Each tax class captures:
The REST API mirrors this behaviour:
POST /api/catalog/products accepts taxRateId for the product default.POST /api/catalog/variants accepts taxRateId per variant. When omitted, the product value is used.POST /api/catalog/prices accepts either taxRateId (preferred) or taxRate (raw percentage). Only submit a raw percentage if you are synchronizing historical rates; otherwise use the id so scope validation kicks in.Every price row persists:
unitPriceNet – amount excluding tax.unitPriceGross – amount including tax.taxRate – the resolved percentage (copied from the tax class at the moment the price is created/updated).taxAmount – the tax delta between gross and net (precision 4).The admin UI and product APIs expose all four components so storefronts can choose the appropriate value to display or to pass into downstream ERP systems.
All price commands, importers, and backend forms call the DI token taxCalculationService. The default implementation (in packages/core/src/modules/sales/services/taxCalculationService.ts) runs this flow:
taxRateId, ensuring it belongs to the same org/tenant as the price row.taxRateId is omitted, fall back to the explicit taxRate or default to zero.taxAmount.The Event Bus publishes:
sales.tax.calculate.before – receives { input, setInput(next), setResult(result) }. Call setInput() to swap the tax class based on geography or customer metadata. Call setResult() to short-circuit the default math (e.g., when you use an external tax engine such as Avalara).sales.tax.calculate.after – receives { input, result, setResult(next) }. Use it to post-process rounding, add recoverable VAT breakdowns, or log telemetry.Example module hook:
import { createRequestContainer } from '@/lib/di/container'
const container = await createRequestContainer()
const eventBus = container.resolve('eventBus')
eventBus?.on('sales.tax.calculate.before', ({ input, setInput }) => {
if (!input.taxRateId && input.organizationId === 'org-brazil') {
setInput({ taxRateId: 'default-brazil' })
}
})
eventBus?.on('sales.tax.calculate.after', ({ result, setResult }) => {
if (result) {
const rounded = Math.ceil(result.taxAmount * 100) / 100
setResult({ ...result, taxAmount: rounded })
}
})
Because this is a DI service, you can also replace it entirely by registering your own implementation in a module di.ts (e.g., plug in a headless tax SaaS) as long as you keep the same TaxCalculationService interface.
Price kinds determine whether backend inputs and frontend displays treat values as tax-inclusive (including-tax) or tax-exclusive (excluding-tax). Best practices:
tax_amount column on catalog_product_prices. If you upgraded from earlier commits, run yarn db:migrate to apply Migration20251117173713.sales.tax.calculate.* events during integration tests to assert your overrides are firing. The Sales module exposes salesCalculationService for order totals – use that service for document totals so tax logic continues to be centralized.taxRateId belongs to another organization/tenant. Query /api/sales/tax-rates scoped to the current org to fetch valid ids.net and gross are accepted. Ensure price kinds declare the intended display mode and that API callers send either unitPriceNet or unitPriceGross.