Add support for tax inclusivity to region and store (#7808)
This also includes rework of the currency model for the Store module. This change is breaking as existing stores won't have any supported currencies set, so users would need to go to the store settings again and choose the supported currencies there.
This commit is contained in:
81
packages/modules/store/src/models/currency.ts
Normal file
81
packages/modules/store/src/models/currency.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
DALUtils,
|
||||
Searchable,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
} from "@mikro-orm/core"
|
||||
import Store from "./store"
|
||||
|
||||
const StoreCurrencyDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "store_currency",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export default class StoreCurrency {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
currency_code: string
|
||||
|
||||
@Property({ columnType: "boolean", default: false })
|
||||
is_default?: boolean
|
||||
|
||||
@ManyToOne(() => Store, {
|
||||
columnType: "text",
|
||||
fieldName: "store_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
store_id: string | null
|
||||
|
||||
@ManyToOne(() => Store, {
|
||||
persist: false,
|
||||
nullable: true,
|
||||
})
|
||||
store: Store | null
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@StoreCurrencyDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
onCreate() {
|
||||
this.id = generateEntityId(this.id, "stocur")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit() {
|
||||
this.id = generateEntityId(this.id, "stocur")
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
export { default as Store } from "./store"
|
||||
export { default as StoreCurrency } from "./currency"
|
||||
|
||||
@@ -15,7 +15,11 @@ import {
|
||||
Property,
|
||||
Filter,
|
||||
OptionalProps,
|
||||
OneToMany,
|
||||
Collection,
|
||||
Cascade,
|
||||
} from "@mikro-orm/core"
|
||||
import StoreCurrency from "./currency"
|
||||
|
||||
type StoreOptionalProps = DAL.SoftDeletableEntityDateColumns
|
||||
|
||||
@@ -37,11 +41,10 @@ export default class Store {
|
||||
@Property({ columnType: "text", default: "Medusa Store" })
|
||||
name: string
|
||||
|
||||
@Property({ type: "array", default: "{}" })
|
||||
supported_currency_codes: string[] = []
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
default_currency_code: string | null = null
|
||||
@OneToMany(() => StoreCurrency, (o) => o.store, {
|
||||
cascade: [Cascade.PERSIST, "soft-remove"] as any,
|
||||
})
|
||||
supported_currencies = new Collection<StoreCurrency>(this)
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
default_sales_channel_id: string | null = null
|
||||
|
||||
Reference in New Issue
Block a user