Skip to content

Commit

Permalink
fix(cart): Tax rate data type (medusajs#10626)
Browse files Browse the repository at this point in the history
* fix(cart): tax rate data type

* update test
  • Loading branch information
carlos-r-l-rodrigues authored Dec 16, 2024
1 parent 612eb78 commit 95baacf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-mugs-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/cart": patch
---

fix: Cart tax rate data type
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
const taxLines = await service.setLineItemTaxLines(createdCart.id, [
{
item_id: itemOne.id,
rate: 20,
rate: 20.753,
code: "TX",
},
])
Expand All @@ -1988,7 +1988,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
expect.arrayContaining([
expect.objectContaining({
item_id: itemOne.id,
rate: 20,
rate: 20.753,
code: "TX",
}),
])
Expand All @@ -1997,7 +1997,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
await service.setLineItemTaxLines(createdCart.id, [
{
item_id: itemOne.id,
rate: 25,
rate: 25.14789,
code: "TX-2",
},
])
Expand All @@ -2013,7 +2013,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
tax_lines: expect.arrayContaining([
expect.objectContaining({
item_id: itemOne.id,
rate: 25,
rate: 25.14789,
code: "TX-2",
}),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,12 @@
},
"rate": {
"name": "rate",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "integer"
"mappedType": "float"
},
"provider_id": {
"name": "provider_id",
Expand Down Expand Up @@ -1537,12 +1537,12 @@
},
"rate": {
"name": "rate",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "integer"
"mappedType": "float"
},
"provider_id": {
"name": "provider_id",
Expand Down
13 changes: 0 additions & 13 deletions packages/modules/cart/src/migrations/Migration20241205095237.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export class Migration20241205095237 extends Migration {
'CREATE INDEX IF NOT EXISTS "IDX_cart_line_item_adjustment_item_id" ON "cart_line_item_adjustment" (item_id) WHERE deleted_at IS NULL;'
)

this.addSql(
'alter table if exists "cart_line_item_tax_line" alter column "rate" type integer using ("rate"::integer);'
)
this.addSql(
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade on delete cascade;'
)
Expand All @@ -70,10 +67,6 @@ export class Migration20241205095237 extends Migration {
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_adjustment_shipping_method_id" ON "cart_shipping_method_adjustment" (shipping_method_id) WHERE deleted_at IS NULL;'
)

this.addSql(
'alter table if exists "cart_shipping_method_tax_line" alter column "rate" type integer using ("rate"::integer);'
)
this.addSql(
'CREATE INDEX IF NOT EXISTS "IDX_cart_shipping_method_tax_line_shipping_method_id" ON "cart_shipping_method_tax_line" (shipping_method_id) WHERE deleted_at IS NULL;'
)
Expand Down Expand Up @@ -112,9 +105,6 @@ export class Migration20241205095237 extends Migration {
'alter table if exists "cart_line_item_adjustment" add constraint "cart_line_item_adjustment_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;'
)

this.addSql(
'alter table if exists "cart_line_item_tax_line" alter column "rate" type numeric using ("rate"::numeric);'
)
this.addSql('drop index if exists "IDX_cart_line_item_tax_line_item_id";')
this.addSql(
'alter table if exists "cart_line_item_tax_line" add constraint "cart_line_item_tax_line_item_id_foreign" foreign key ("item_id") references "cart_line_item" ("id") on update cascade;'
Expand All @@ -129,9 +119,6 @@ export class Migration20241205095237 extends Migration {
'drop index if exists "IDX_cart_shipping_method_adjustment_shipping_method_id";'
)

this.addSql(
'alter table if exists "cart_shipping_method_tax_line" alter column "rate" type numeric using ("rate"::numeric);'
)
this.addSql(
'drop index if exists "IDX_cart_shipping_method_tax_line_shipping_method_id";'
)
Expand Down
13 changes: 13 additions & 0 deletions packages/modules/cart/src/migrations/Migration20241216183049.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Migration } from "@mikro-orm/migrations"

export class Migration20241216183049 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table if exists "cart_line_item_tax_line" alter column "rate" type real using ("rate"::real);'
)

this.addSql(
'alter table if exists "cart_shipping_method_tax_line" alter column "rate" type real using ("rate"::real);'
)
}
}
2 changes: 1 addition & 1 deletion packages/modules/cart/src/models/line-item-tax-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LineItemTaxLine = model
id: model.id({ prefix: "calitxl" }).primaryKey(),
description: model.text().nullable(),
code: model.text(),
rate: model.number(),
rate: model.float(),
provider_id: model.text().nullable(),
metadata: model.json().nullable(),
tax_rate_id: model.text().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ShippingMethodTaxLine = model
id: model.id({ prefix: "casmtxl" }).primaryKey(),
description: model.text().nullable(),
code: model.text(),
rate: model.number(),
rate: model.float(),
provider_id: model.text().nullable(),
tax_rate_id: model.text().nullable(),
metadata: model.json().nullable(),
Expand Down

0 comments on commit 95baacf

Please sign in to comment.