feat(cart): Item tax lines + shipping method tax lines (#6136)
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user