feat(tax): introduce tax override data models (#6422)

**What**
- Adds Tax rules to allow overrides of tax rates for certain products, product types or shipping options.

**Punted to future PR**
- Currently, the creation methods only support bulk operations. A later PR will include support for singular operations, too.
- It should be possible to add products, types, and shipping options to a tax rate after creating it. Add, remove, update will come in a later PR.
This commit is contained in:
Sebastian Rindom
2024-02-20 16:50:19 +00:00
committed by GitHub
parent 43ed6a990d
commit 137cc0ebf8
7 changed files with 197 additions and 6 deletions
+1
View File
@@ -1,2 +1,3 @@
export { default as TaxRate } from "./tax-rate"
export { default as TaxRegion } from "./tax-region"
export { default as TaxRateRule } from "./tax-rate-rule"
+55
View File
@@ -0,0 +1,55 @@
import {
Cascade,
Entity,
ManyToOne,
PrimaryKey,
PrimaryKeyProp,
Property,
} from "@mikro-orm/core"
import TaxRate from "./tax-rate"
const TABLE_NAME = "tax_rate_rule"
const taxRateIdIndexName = "IDX_tax_rate_rule_tax_rate_id"
@Entity({ tableName: TABLE_NAME })
export default class TaxRateRule {
@PrimaryKey({ columnType: "text" })
tax_rate_id!: string
@PrimaryKey({ columnType: "text" })
reference_id!: string;
[PrimaryKeyProp]?: ["tax_rate_id", "reference_id"]
@Property({ columnType: "text" })
reference: string
@ManyToOne(() => TaxRate, {
fieldName: "tax_rate_id",
index: taxRateIdIndexName,
cascade: [Cascade.REMOVE, Cascade.PERSIST],
})
tax_rate: TaxRate
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
created_at: Date
@Property({
onCreate: () => new Date(),
onUpdate: () => new Date(),
columnType: "timestamptz",
defaultRaw: "now()",
})
updated_at: Date
@Property({ columnType: "text", nullable: true })
created_by: string | null = null
}