fix(medusa): Removing the line items should remove the tax lines as well (#4595)

Fixes https://github.com/medusajs/medusa/issues/4531
This commit is contained in:
Adrien de Peretti
2023-07-25 10:41:01 +02:00
committed by GitHub
parent f174bb6fa1
commit ae33f4825f
4 changed files with 48 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Removing the line items should remove the tax lines as well

View File

@@ -0,0 +1,37 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class lineItemTaxAdjustmentOnCascadeDelete1680857773272
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" DROP CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad"`
)
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" ADD CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" DROP CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2"`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" ADD CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" DROP CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad"`
)
await queryRunner.query(
`ALTER TABLE "line_item_tax_line" ADD CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" DROP CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2"`
)
await queryRunner.query(
`ALTER TABLE "line_item_adjustment" ADD CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2" FOREIGN KEY ("item_id") REFERENCES "line_item"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`
)
}
}

View File

@@ -10,8 +10,7 @@ import {
} from "typeorm"
import { BaseEntity } from "../interfaces"
import TaxInclusivePricingFeatureFlag
from "../loaders/feature-flags/tax-inclusive-pricing"
import TaxInclusivePricingFeatureFlag from "../loaders/feature-flags/tax-inclusive-pricing"
import { generateEntityId } from "../utils"
import { DbAwareColumn } from "../utils/db-aware-column"
import { FeatureFlagColumn } from "../utils/feature-flag-decorators"
@@ -70,11 +69,13 @@ export class LineItem extends BaseEntity {
@JoinColumn({ name: "claim_order_id" })
claim_order: ClaimOrder
@OneToMany(() => LineItemTaxLine, (tl) => tl.item, { cascade: ["insert"] })
@OneToMany(() => LineItemTaxLine, (tl) => tl.item, {
cascade: ["insert", "remove"],
})
tax_lines: LineItemTaxLine[]
@OneToMany(() => LineItemAdjustment, (lia) => lia.item, {
cascade: ["insert"],
cascade: ["insert", "remove"],
})
adjustments: LineItemAdjustment[]

View File

@@ -477,6 +477,7 @@ class LineItemService extends TransactionBaseService {
}
/**
* @deprecated no the cascade on the entity takes care of it
* Deletes a line item with the tax lines.
* @param id - the id of the line item to delete
* @return the result of the delete operation