feat(dashboard,core-flows,types,order): change order accepts price updates (#9476)
* chore: change order can accept price updates * chore: add changes to transformed order * chore: fix transform * chore: transform raw unit price
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
"revoked": "Revoked",
|
"revoked": "Revoked",
|
||||||
"new": "New",
|
"new": "New",
|
||||||
"modified": "Modified",
|
"modified": "Modified",
|
||||||
|
"added": "Added",
|
||||||
"removed": "Removed",
|
"removed": "Removed",
|
||||||
"admin": "Admin",
|
"admin": "Admin",
|
||||||
"store": "Store",
|
"store": "Store",
|
||||||
|
|||||||
@@ -155,6 +155,9 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
|||||||
let quantity: BigNumberInput =
|
let quantity: BigNumberInput =
|
||||||
itemAction.raw_quantity ?? itemAction.quantity
|
itemAction.raw_quantity ?? itemAction.quantity
|
||||||
|
|
||||||
|
let unit_price: BigNumberInput =
|
||||||
|
itemAction.raw_unit_price ?? itemAction.unit_price
|
||||||
|
|
||||||
const updateAction = itemAction.actions!.find(
|
const updateAction = itemAction.actions!.find(
|
||||||
(a) => a.action === ChangeActionType.ITEM_UPDATE
|
(a) => a.action === ChangeActionType.ITEM_UPDATE
|
||||||
)
|
)
|
||||||
@@ -169,6 +172,7 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
|
|||||||
id: ordItem.id,
|
id: ordItem.id,
|
||||||
variant_id: ordItem.variant_id,
|
variant_id: ordItem.variant_id,
|
||||||
quantity,
|
quantity,
|
||||||
|
unit_price,
|
||||||
})
|
})
|
||||||
allVariants.push(ordItem.variant)
|
allVariants.push(ordItem.variant)
|
||||||
})
|
})
|
||||||
|
|||||||
+1
@@ -84,6 +84,7 @@ export const orderEditUpdateItemQuantityWorkflow = createWorkflow(
|
|||||||
details: {
|
details: {
|
||||||
reference_id: item.id,
|
reference_id: item.id,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
|
unit_price: item.unit_price,
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export const updateOrderEditAddItemWorkflow = createWorkflow(
|
|||||||
id: input.action_id,
|
id: input.action_id,
|
||||||
details: {
|
details: {
|
||||||
quantity: data.quantity ?? originalAction.details?.quantity,
|
quantity: data.quantity ?? originalAction.details?.quantity,
|
||||||
|
unit_price: data.unit_price ?? originalAction.details?.unit_price,
|
||||||
},
|
},
|
||||||
internal_note: data.internal_note,
|
internal_note: data.internal_note,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface NewItem {
|
|||||||
interface ExistingItem {
|
interface ExistingItem {
|
||||||
id: string
|
id: string
|
||||||
quantity: BigNumberInput
|
quantity: BigNumberInput
|
||||||
|
unit_price?: BigNumberInput
|
||||||
internal_note?: string | null
|
internal_note?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,7 @@ export interface UpdateOrderEditAddNewItemWorkflowInput {
|
|||||||
action_id: string
|
action_id: string
|
||||||
data: {
|
data: {
|
||||||
quantity?: BigNumberInput
|
quantity?: BigNumberInput
|
||||||
|
unit_price?: BigNumberInput
|
||||||
internal_note?: string | null
|
internal_note?: string | null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { DmlEntity, toMikroOrmEntities } from "../dml"
|
|
||||||
import { CustomTsMigrationGenerator } from "../dal"
|
|
||||||
import type {
|
import type {
|
||||||
AnyEntity,
|
AnyEntity,
|
||||||
EntityClass,
|
EntityClass,
|
||||||
|
EntityClassGroup,
|
||||||
EntitySchema,
|
EntitySchema,
|
||||||
MikroORMOptions,
|
MikroORMOptions,
|
||||||
EntityClassGroup,
|
|
||||||
} from "@mikro-orm/core"
|
} from "@mikro-orm/core"
|
||||||
import { kebabCase } from "../common"
|
import { kebabCase } from "../common"
|
||||||
|
import { CustomTsMigrationGenerator } from "../dal"
|
||||||
|
import { DmlEntity, toMikroOrmEntities } from "../dml"
|
||||||
|
|
||||||
type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {
|
type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {
|
||||||
entities: (
|
entities: (
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export type AdminPostOrderEditsAddItemsReqSchemaType = z.infer<
|
|||||||
|
|
||||||
export const AdminPostOrderEditsItemsActionReqSchema = z.object({
|
export const AdminPostOrderEditsItemsActionReqSchema = z.object({
|
||||||
quantity: z.number().optional(),
|
quantity: z.number().optional(),
|
||||||
|
unit_price: z.number().optional(),
|
||||||
internal_note: z.string().nullish().optional(),
|
internal_note: z.string().nullish().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ export type AdminPostOrderEditsItemsActionReqSchemaType = z.infer<
|
|||||||
|
|
||||||
export const AdminPostOrderEditsUpdateItemQuantityReqSchema = z.object({
|
export const AdminPostOrderEditsUpdateItemQuantityReqSchema = z.object({
|
||||||
quantity: z.number(),
|
quantity: z.number(),
|
||||||
|
unit_price: z.number().optional(),
|
||||||
internal_note: z.string().nullish().optional(),
|
internal_note: z.string().nullish().optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -790,6 +790,24 @@
|
|||||||
"nullable": false,
|
"nullable": false,
|
||||||
"mappedType": "text"
|
"mappedType": "text"
|
||||||
},
|
},
|
||||||
|
"unit_price": {
|
||||||
|
"name": "unit_price",
|
||||||
|
"type": "numeric",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": true,
|
||||||
|
"mappedType": "decimal"
|
||||||
|
},
|
||||||
|
"raw_unit_price": {
|
||||||
|
"name": "raw_unit_price",
|
||||||
|
"type": "jsonb",
|
||||||
|
"unsigned": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"primary": false,
|
||||||
|
"nullable": true,
|
||||||
|
"mappedType": "json"
|
||||||
|
},
|
||||||
"quantity": {
|
"quantity": {
|
||||||
"name": "quantity",
|
"name": "quantity",
|
||||||
"type": "numeric",
|
"type": "numeric",
|
||||||
@@ -815,7 +833,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_fulfilled_quantity": {
|
"raw_fulfilled_quantity": {
|
||||||
@@ -834,7 +851,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_delivered_quantity": {
|
"raw_delivered_quantity": {
|
||||||
@@ -853,7 +869,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_shipped_quantity": {
|
"raw_shipped_quantity": {
|
||||||
@@ -872,7 +887,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_return_requested_quantity": {
|
"raw_return_requested_quantity": {
|
||||||
@@ -891,7 +905,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_return_received_quantity": {
|
"raw_return_received_quantity": {
|
||||||
@@ -910,7 +923,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_return_dismissed_quantity": {
|
"raw_return_dismissed_quantity": {
|
||||||
@@ -929,7 +941,6 @@
|
|||||||
"autoincrement": false,
|
"autoincrement": false,
|
||||||
"primary": false,
|
"primary": false,
|
||||||
"nullable": false,
|
"nullable": false,
|
||||||
"default": "0",
|
|
||||||
"mappedType": "decimal"
|
"mappedType": "decimal"
|
||||||
},
|
},
|
||||||
"raw_written_off_quantity": {
|
"raw_written_off_quantity": {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Migration } from "@mikro-orm/migrations"
|
||||||
|
|
||||||
|
export class Migration20240930122627 extends Migration {
|
||||||
|
async up(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "order_item" add column if not exists "unit_price" numeric null, add column if not exists "raw_unit_price" jsonb null;'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "order_item" drop column if exists "unit_price";'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "order_item" drop column if exists "raw_unit_price";'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,12 @@ export default class OrderItem {
|
|||||||
})
|
})
|
||||||
item: Rel<OrderLineItem>
|
item: Rel<OrderLineItem>
|
||||||
|
|
||||||
|
@MikroOrmBigNumberProperty({ nullable: true })
|
||||||
|
unit_price: BigNumber | number | null = null
|
||||||
|
|
||||||
|
@Property({ columnType: "jsonb", nullable: true })
|
||||||
|
raw_unit_price: BigNumberRawValue | null = null
|
||||||
|
|
||||||
@MikroOrmBigNumberProperty()
|
@MikroOrmBigNumberProperty()
|
||||||
quantity: BigNumber | number
|
quantity: BigNumber | number
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
CreateOrderChangeDTO,
|
CreateOrderChangeDTO,
|
||||||
CreateOrderItemDTO,
|
CreateOrderItemDTO,
|
||||||
UpdateReturnReasonDTO,
|
|
||||||
CreateOrderLineItemDTO,
|
CreateOrderLineItemDTO,
|
||||||
CreateOrderLineItemTaxLineDTO,
|
CreateOrderLineItemTaxLineDTO,
|
||||||
CreateOrderShippingMethodDTO,
|
CreateOrderShippingMethodDTO,
|
||||||
@@ -73,6 +72,7 @@ import {
|
|||||||
UpdateOrderLineItemDTO,
|
UpdateOrderLineItemDTO,
|
||||||
UpdateOrderLineItemTaxLineDTO,
|
UpdateOrderLineItemTaxLineDTO,
|
||||||
UpdateOrderShippingMethodTaxLineDTO,
|
UpdateOrderShippingMethodTaxLineDTO,
|
||||||
|
UpdateReturnReasonDTO,
|
||||||
} from "@types"
|
} from "@types"
|
||||||
import { joinerConfig } from "../joiner-config"
|
import { joinerConfig } from "../joiner-config"
|
||||||
import {
|
import {
|
||||||
@@ -1991,7 +1991,10 @@ export default class OrderModuleService<
|
|||||||
for (const item of calculated.order.items) {
|
for (const item of calculated.order.items) {
|
||||||
const isExistingItem = item.id === item.detail?.item_id
|
const isExistingItem = item.id === item.detail?.item_id
|
||||||
if (!isExistingItem) {
|
if (!isExistingItem) {
|
||||||
addedItems[item.id] = item
|
addedItems[item.id] = {
|
||||||
|
...item,
|
||||||
|
unit_price: item.detail?.unit_price ?? item.unit_price,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2021,11 +2024,14 @@ export default class OrderModuleService<
|
|||||||
delete item.actions
|
delete item.actions
|
||||||
|
|
||||||
const newItem = itemsToUpsert.find((d) => d.item_id === item.id)!
|
const newItem = itemsToUpsert.find((d) => d.item_id === item.id)!
|
||||||
|
const unitPrice = newItem?.unit_price ?? item.unit_price
|
||||||
|
|
||||||
calculated.order.items[idx] = {
|
calculated.order.items[idx] = {
|
||||||
...lineItem,
|
...lineItem,
|
||||||
actions,
|
actions,
|
||||||
quantity: newItem.quantity,
|
quantity: newItem.quantity,
|
||||||
|
unit_price: unitPrice,
|
||||||
|
raw_unit_price: new BigNumber(unitPrice),
|
||||||
detail: {
|
detail: {
|
||||||
...newItem,
|
...newItem,
|
||||||
...item,
|
...item,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export type VirtualOrder = {
|
|||||||
exchange_id?: string
|
exchange_id?: string
|
||||||
|
|
||||||
item_id?: string
|
item_id?: string
|
||||||
|
unit_price?: BigNumberInput
|
||||||
quantity: BigNumberInput
|
quantity: BigNumberInput
|
||||||
shipped_quantity: BigNumberInput
|
shipped_quantity: BigNumberInput
|
||||||
fulfilled_quantity: BigNumberInput
|
fulfilled_quantity: BigNumberInput
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_UPDATE, {
|
|||||||
(item) => item.id === action.details.reference_id
|
(item) => item.id === action.details.reference_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const unitPrice = action.details.unit_price
|
||||||
const existing = currentOrder.items[existingIndex]
|
const existing = currentOrder.items[existingIndex]
|
||||||
|
|
||||||
existing.detail.quantity ??= 0
|
existing.detail.quantity ??= 0
|
||||||
@@ -26,6 +27,13 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_UPDATE, {
|
|||||||
existing.quantity = quant
|
existing.quantity = quant
|
||||||
existing.detail.quantity = quant
|
existing.detail.quantity = quant
|
||||||
|
|
||||||
|
if (unitPrice) {
|
||||||
|
const unitPriceBN = new BigNumber(unitPrice)
|
||||||
|
|
||||||
|
existing.unit_price = unitPriceBN
|
||||||
|
existing.detail.unit_price = unitPriceBN
|
||||||
|
}
|
||||||
|
|
||||||
setActionReference(existing, action, options)
|
setActionReference(existing, action, options)
|
||||||
|
|
||||||
return MathBN.mult(existing.unit_price, quantityDiff)
|
return MathBN.mult(existing.unit_price, quantityDiff)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export function applyChangesToOrder(
|
|||||||
order_id: order.id,
|
order_id: order.id,
|
||||||
version,
|
version,
|
||||||
quantity: orderItem.quantity,
|
quantity: orderItem.quantity,
|
||||||
|
unit_price: item.unit_price ?? orderItem.unit_price,
|
||||||
fulfilled_quantity: orderItem.fulfilled_quantity ?? 0,
|
fulfilled_quantity: orderItem.fulfilled_quantity ?? 0,
|
||||||
delivered_quantity: orderItem.delivered_quantity ?? 0,
|
delivered_quantity: orderItem.delivered_quantity ?? 0,
|
||||||
shipped_quantity: orderItem.shipped_quantity ?? 0,
|
shipped_quantity: orderItem.shipped_quantity ?? 0,
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ export function formatOrder<T = any>(
|
|||||||
...orderItem.item,
|
...orderItem.item,
|
||||||
quantity: detail.quantity,
|
quantity: detail.quantity,
|
||||||
raw_quantity: detail.raw_quantity,
|
raw_quantity: detail.raw_quantity,
|
||||||
|
unit_price: detail.unit_price ?? orderItem.item.unit_price,
|
||||||
|
raw_unit_price: detail.raw_unit_price ?? orderItem.item.raw_unit_price,
|
||||||
detail,
|
detail,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -247,6 +249,11 @@ export function mapRepositoryToOrderModel(config, isRelatedEntity = false) {
|
|||||||
delete conf.where.items.item.quantity
|
delete conf.where.items.item.quantity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (original.unit_price) {
|
||||||
|
conf.where.items.unit_price = original.unit_price
|
||||||
|
delete conf.where.items.item.unit_price
|
||||||
|
}
|
||||||
|
|
||||||
if (original.detail) {
|
if (original.detail) {
|
||||||
conf.where.items = {
|
conf.where.items = {
|
||||||
...original.detail,
|
...original.detail,
|
||||||
|
|||||||
Reference in New Issue
Block a user