From 95baacfd00f54de028226731b016917caacde5af Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:09:05 -0300 Subject: [PATCH] fix(cart): Tax rate data type (#10626) * fix(cart): tax rate data type * update test --- .changeset/famous-mugs-grow.md | 5 +++++ .../__tests__/services/cart-module/index.spec.ts | 8 ++++---- .../cart/src/migrations/.snapshot-medusa-cart.json | 8 ++++---- .../cart/src/migrations/Migration20241205095237.ts | 13 ------------- .../cart/src/migrations/Migration20241216183049.ts | 13 +++++++++++++ .../modules/cart/src/models/line-item-tax-line.ts | 2 +- .../cart/src/models/shipping-method-tax-line.ts | 2 +- 7 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 .changeset/famous-mugs-grow.md create mode 100644 packages/modules/cart/src/migrations/Migration20241216183049.ts diff --git a/.changeset/famous-mugs-grow.md b/.changeset/famous-mugs-grow.md new file mode 100644 index 0000000000000..8a2935ba5f370 --- /dev/null +++ b/.changeset/famous-mugs-grow.md @@ -0,0 +1,5 @@ +--- +"@medusajs/cart": patch +--- + +fix: Cart tax rate data type diff --git a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts index 23d05ee4d7adc..5d276268af8d6 100644 --- a/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts +++ b/packages/modules/cart/integration-tests/__tests__/services/cart-module/index.spec.ts @@ -1979,7 +1979,7 @@ moduleIntegrationTestRunner({ const taxLines = await service.setLineItemTaxLines(createdCart.id, [ { item_id: itemOne.id, - rate: 20, + rate: 20.753, code: "TX", }, ]) @@ -1988,7 +1988,7 @@ moduleIntegrationTestRunner({ expect.arrayContaining([ expect.objectContaining({ item_id: itemOne.id, - rate: 20, + rate: 20.753, code: "TX", }), ]) @@ -1997,7 +1997,7 @@ moduleIntegrationTestRunner({ await service.setLineItemTaxLines(createdCart.id, [ { item_id: itemOne.id, - rate: 25, + rate: 25.14789, code: "TX-2", }, ]) @@ -2013,7 +2013,7 @@ moduleIntegrationTestRunner({ tax_lines: expect.arrayContaining([ expect.objectContaining({ item_id: itemOne.id, - rate: 25, + rate: 25.14789, code: "TX-2", }), ]), diff --git a/packages/modules/cart/src/migrations/.snapshot-medusa-cart.json b/packages/modules/cart/src/migrations/.snapshot-medusa-cart.json index af920bf4f77a9..1b02c64962622 100644 --- a/packages/modules/cart/src/migrations/.snapshot-medusa-cart.json +++ b/packages/modules/cart/src/migrations/.snapshot-medusa-cart.json @@ -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", @@ -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", diff --git a/packages/modules/cart/src/migrations/Migration20241205095237.ts b/packages/modules/cart/src/migrations/Migration20241205095237.ts index 2cf70fdfee223..e09b7106306b2 100644 --- a/packages/modules/cart/src/migrations/Migration20241205095237.ts +++ b/packages/modules/cart/src/migrations/Migration20241205095237.ts @@ -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;' ) @@ -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;' ) @@ -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;' @@ -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";' ) diff --git a/packages/modules/cart/src/migrations/Migration20241216183049.ts b/packages/modules/cart/src/migrations/Migration20241216183049.ts new file mode 100644 index 0000000000000..c5ca53f06ffd3 --- /dev/null +++ b/packages/modules/cart/src/migrations/Migration20241216183049.ts @@ -0,0 +1,13 @@ +import { Migration } from "@mikro-orm/migrations" + +export class Migration20241216183049 extends Migration { + async up(): Promise { + 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);' + ) + } +} diff --git a/packages/modules/cart/src/models/line-item-tax-line.ts b/packages/modules/cart/src/models/line-item-tax-line.ts index bc6e0f9911339..73f5b790c6c6e 100644 --- a/packages/modules/cart/src/models/line-item-tax-line.ts +++ b/packages/modules/cart/src/models/line-item-tax-line.ts @@ -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(), diff --git a/packages/modules/cart/src/models/shipping-method-tax-line.ts b/packages/modules/cart/src/models/shipping-method-tax-line.ts index 80c1aa53c57dd..544956aa569fa 100644 --- a/packages/modules/cart/src/models/shipping-method-tax-line.ts +++ b/packages/modules/cart/src/models/shipping-method-tax-line.ts @@ -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(),