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

feat(cart): Item tax lines + shipping method tax lines #6136

Merged
merged 16 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions packages/cart/src/models/line-item-tax-line.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { generateEntityId } from "@medusajs/utils"
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
import {
BeforeCreate,
Entity,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
import LineItem from "./line-item"
import TaxLine from "./tax-line"

@Entity({ tableName: "cart_line_item_tax_line" })
export default class LineItemTaxLine extends TaxLine {
@ManyToOne(() => LineItem, {
joinColumn: "line_item",
fieldName: "line_item_id",
onDelete: "cascade",
nullable: true,
index: "IDX_tax_line_item_id",
})
line_item: LineItem
item: LineItem | null

@Property({ columnType: "text" })
item_id: string

@BeforeCreate()
onCreate() {
Expand Down
12 changes: 4 additions & 8 deletions packages/cart/src/models/line-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,14 @@ export default class LineItem {
@Check({ expression: "unit_price >= 0" }) // TODO: Validate that numeric types work with the expression
unit_price: number

@OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.line_item, {
@OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.item, {
cascade: [Cascade.REMOVE],
})
tax_lines = new Collection<LineItemTaxLine>(this)

@OneToMany(
() => LineItemAdjustment,
(adjustment) => adjustment.item,
{
cascade: [Cascade.REMOVE],
}
)
@OneToMany(() => LineItemAdjustment, (adjustment) => adjustment.item, {
cascade: [Cascade.REMOVE],
})
adjustments = new Collection<LineItemAdjustment>(this)

/** COMPUTED PROPERTIES - START */
Expand Down
18 changes: 14 additions & 4 deletions packages/cart/src/models/shipping-method-tax-line.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { generateEntityId } from "@medusajs/utils"
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
import {
BeforeCreate,
Entity,
ManyToOne,
OnInit,
Property,
} from "@mikro-orm/core"
import ShippingMethod from "./shipping-method"
import TaxLine from "./tax-line"

@Entity({ tableName: "cart_shipping_method_tax_line" })
export default class ShippingMethodTaxLine extends TaxLine {
@ManyToOne(() => ShippingMethod, {
joinColumn: "shipping_method",
fieldName: "shipping_method_id",
onDelete: "cascade",
nullable: true,
index: "IDX_tax_line_shipping_method_id",
})
shipping_method: ShippingMethod
shipping_method: ShippingMethod | null

@Property({ columnType: "text" })
shipping_method_id: string

@BeforeCreate()
onCreate() {
Expand Down
4 changes: 2 additions & 2 deletions packages/cart/src/models/tax-line.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrimaryKey, Property } from "@mikro-orm/core"

/**
/**
* As per the Mikro ORM docs, superclasses should use the abstract class definition
* Source: https://mikro-orm.io/docs/inheritance-mapping
*/
Expand All @@ -17,7 +17,7 @@ export default abstract class TaxLine {
@Property({ columnType: "text" })
code: string

@Property({ columnType: "numeric" })
@Property({ columnType: "numeric", serializer: Number })
rate: number

@Property({ columnType: "text", nullable: true })
Expand Down
Loading
Loading