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:
committed by
GitHub
parent
f174bb6fa1
commit
ae33f4825f
5
.changeset/eight-trees-begin.md
Normal file
5
.changeset/eight-trees-begin.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(medusa): Removing the line items should remove the tax lines as well
|
||||
@@ -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`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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[]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user