fix: Tax region + rates clean up (#9279)

What
- Require `code` on Tax Rates
- Update dashboard to account for non-nullable code on Tax Rates

- Include `automatic_taxes` in API Route response

Closes CC-524 CC-525
This commit is contained in:
Oli Juhl
2024-09-29 10:25:33 +00:00
committed by GitHub
parent 0efbcd2344
commit 1b4372ae71
23 changed files with 121 additions and 45 deletions
@@ -72,6 +72,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -90,6 +91,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -99,6 +101,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -125,6 +128,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -135,6 +139,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -161,6 +166,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -171,6 +177,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -181,6 +188,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -215,6 +223,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -224,6 +233,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
.catch((e) => e)
@@ -240,6 +250,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
@@ -250,6 +261,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST",
},
})
.catch((e) => e)
@@ -265,6 +277,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST-CODE",
},
})
@@ -301,7 +314,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
tax_region_id: region.id,
rate: 2,
name: "Test Rate",
code: null,
code: "TEST-CODE",
is_default: true,
}),
])
@@ -313,6 +326,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
tax_region_id: region.id,
rate: 2,
name: "Test Rate",
code: "TEST-CODE",
is_default: true,
}),
expect.objectContaining({
@@ -332,6 +346,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST-CODE",
},
})
@@ -413,6 +428,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
const region = await service.createTaxRegions({
country_code: "US",
default_tax_rate: {
code: "TEST",
name: "Test Rate",
rate: 0.2,
},
@@ -424,6 +440,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
province_code: "CA",
parent_id: region.id,
default_tax_rate: {
code: "TEST",
name: "CA Rate",
rate: 8.25,
},
@@ -472,6 +489,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
{
country_code: "US",
default_tax_rate: {
code: "TEST",
name: "Test Rate",
rate: 0.2,
},
@@ -482,6 +500,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
tax_region_id: region.id,
name: "Shipping Rate",
rate: 8.23,
code: "TEST-CODE",
})
await service.createTaxRateRules([
@@ -1036,6 +1055,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
default_tax_rate: {
name: "Test Rate",
rate: 0.2,
code: "TEST-CODE",
},
})
@@ -1045,6 +1065,7 @@ moduleIntegrationTestRunner<ITaxModuleService>({
name: "Shipping Rate",
rate: 8.23,
is_default: true,
code: "TEST-CODE-2",
})
).rejects.toThrowError(
/Tax rate with tax_region_id: .*?, already exists./
@@ -27,11 +27,11 @@ export const setupTaxStructure = async (service: ITaxModuleService) => {
const [us, dk, de, ca] = await service.createTaxRegions([
{
country_code: "US",
default_tax_rate: { name: "US Default Rate", rate: 2 },
default_tax_rate: { name: "US Default Rate", rate: 2, code: "US" },
},
{
country_code: "DK",
default_tax_rate: { name: "Denmark Default Rate", rate: 25 },
default_tax_rate: { name: "Denmark Default Rate", rate: 25, code: "DK" },
},
{
country_code: "DE",
@@ -43,7 +43,7 @@ export const setupTaxStructure = async (service: ITaxModuleService) => {
},
{
country_code: "CA",
default_tax_rate: { name: "Canada Default Rate", rate: 5 },
default_tax_rate: { name: "Canada Default Rate", rate: 5, code: "CA" },
},
])
@@ -246,7 +246,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"nullable": false,
"mappedType": "float"
},
"code": {
@@ -255,7 +255,7 @@
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": true,
"nullable": false,
"mappedType": "text"
},
"name": {
@@ -0,0 +1,18 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20240924114005 extends Migration {
async up(): Promise<void> {
this.addSql(
`UPDATE "tax_rate" SET code = 'default' WHERE code IS NULL;`
)
this.addSql(
`ALTER TABLE IF EXISTS "tax_rate" ALTER COLUMN "code" SET NOT NULL;`
)
}
async down(): Promise<void> {
this.addSql(
`ALTER TABLE IF EXISTS "tax_rate" ALTER COLUMN "code" DROP NOT NULL;`
)
}
}
+2 -2
View File
@@ -61,8 +61,8 @@ export default class TaxRate {
rate: number | null = null
@Searchable()
@Property({ columnType: "text", nullable: true })
code: string | null = null
@Property({ columnType: "text" })
code: string
@Searchable()
@Property({ columnType: "text" })