feat(tax): add tax provider support (#6492)

**What**
- Adds Tax Provider model
- Adds loader to get Tax Provider from module options
- Adds System Tax provider which forwards tax rates as is
This commit is contained in:
Sebastian Rindom
2024-02-26 19:29:26 +00:00
committed by GitHub
parent ce39b9b66e
commit 63aea44e06
13 changed files with 254 additions and 38 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ export interface TaxRateDTO {
/**
* The ID of the user that created the Tax Rate.
*/
created_by: string
created_by: string | null
}
export interface FilterableTaxRateProps
@@ -138,7 +138,7 @@ export interface TaxCalculationContext {
}
interface TaxLineDTO {
rate_id: string
rate_id?: string
rate: number | null
code: string | null
name: string
+1
View File
@@ -1,3 +1,4 @@
export * from "./common"
export * from "./mutations"
export * from "./service"
export * from "./provider"
+48
View File
@@ -0,0 +1,48 @@
import {
ItemTaxLineDTO,
ShippingTaxLineDTO,
TaxCalculationContext,
TaxRateDTO,
TaxableItemDTO,
TaxableShippingDTO,
} from "./common"
/**
* A shipping method and the tax rates configured to apply to the
* shipping method.
*/
export type ShippingTaxCalculationLine = {
/**
* The shipping method to calculate taxes for.
*/
shipping_line: TaxableShippingDTO
/**
* The rates applicable on the shipping method.
*/
rates: TaxRateDTO[]
}
/**
* A line item and the tax rates configured to apply to the
* product contained in the line item.
*/
export type ItemTaxCalculationLine = {
/**
* The line item to calculate taxes for.
*/
line_item: TaxableItemDTO
/**
* The rates applicable on the item.
*/
rates: TaxRateDTO[]
}
export interface ITaxProvider {
getIdentifier(): string
getTaxLines(
itemLines: ItemTaxCalculationLine[],
shippingLines: ShippingTaxCalculationLine[],
context: TaxCalculationContext
): Promise<(ItemTaxLineDTO | ShippingTaxLineDTO)[]>
}
+1 -1
View File
@@ -95,7 +95,7 @@ export interface ITaxModuleService extends IModuleService {
): Promise<TaxRateRuleDTO[]>
getTaxLines(
item: (TaxableItemDTO | TaxableShippingDTO)[],
items: (TaxableItemDTO | TaxableShippingDTO)[],
calculationContext: TaxCalculationContext,
sharedContext?: Context
): Promise<(ItemTaxLineDTO | ShippingTaxLineDTO)[]>