Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-trees-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Removing the line items should remove the tax lines as well
Original file line number Diff line number Diff line change
@@ -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`
)
}
}
9 changes: 5 additions & 4 deletions packages/medusa/src/models/line-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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[]

Expand Down
1 change: 1 addition & 0 deletions packages/medusa/src/services/line-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down