fix(inventory): Minor fixes to upserting inventory items (#3883)
* fix(inventory): Minor fixes to upserting inventory item levels * Create sour-jobs-decide.md * fix(inventory): Minor fixes to upserting inventory item levels
This commit is contained in:
1 parent
5fdccf5e32
commit
966ddd2f16
3 files changed
+23
-18
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/admin-ui": patch
|
||||||
|
"@medusajs/admin": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(inventory): Minor fixes to upserting inventory items
|
||||||
+3
-1
@@ -57,6 +57,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
delete data.ean
|
delete data.ean
|
||||||
delete data.barcode
|
delete data.barcode
|
||||||
delete data.upc
|
delete data.upc
|
||||||
|
delete data.allow_backorder
|
||||||
|
|
||||||
return removeNullish({
|
return removeNullish({
|
||||||
...updateDimensions,
|
...updateDimensions,
|
||||||
@@ -78,7 +79,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
|
|
||||||
let inventoryItemId: string | undefined = itemId
|
let inventoryItemId: string | undefined = itemId
|
||||||
|
|
||||||
const { ean, barcode, upc } = data
|
const { ean, barcode, upc, allow_backorder } = data
|
||||||
const upsertPayload = createUpdateInventoryItemPayload(data)
|
const upsertPayload = createUpdateInventoryItemPayload(data)
|
||||||
let shouldInvalidateCache = false
|
let shouldInvalidateCache = false
|
||||||
|
|
||||||
@@ -170,6 +171,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => {
|
|||||||
ean,
|
ean,
|
||||||
barcode,
|
barcode,
|
||||||
upc,
|
upc,
|
||||||
|
allow_backorder,
|
||||||
}),
|
}),
|
||||||
() => {
|
() => {
|
||||||
refetch()
|
refetch()
|
||||||
|
|||||||
+13
-17
@@ -2,7 +2,6 @@ import { IInventoryService, InventoryItemDTO } from "@medusajs/types"
|
|||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { EntityManager } from "typeorm"
|
import { EntityManager } from "typeorm"
|
||||||
import { ulid } from "ulid"
|
import { ulid } from "ulid"
|
||||||
import { ProductVariant } from "../../../../../models"
|
|
||||||
import {
|
import {
|
||||||
ProductVariantInventoryService,
|
ProductVariantInventoryService,
|
||||||
ProductVariantService,
|
ProductVariantService,
|
||||||
@@ -74,19 +73,17 @@ export const createInventoryItemTransaction = async (
|
|||||||
|
|
||||||
const productVariantServiceTx = productVariantService.withTransaction(manager)
|
const productVariantServiceTx = productVariantService.withTransaction(manager)
|
||||||
|
|
||||||
const variant = await productVariantServiceTx.retrieve(variantId)
|
|
||||||
|
|
||||||
async function createInventoryItem(input: CreateInventoryItemInput) {
|
async function createInventoryItem(input: CreateInventoryItemInput) {
|
||||||
return await inventoryService!.createInventoryItem({
|
return await inventoryService!.createInventoryItem({
|
||||||
sku: variant.sku,
|
sku: input.sku,
|
||||||
origin_country: variant.origin_country,
|
origin_country: input.origin_country,
|
||||||
hs_code: variant.hs_code,
|
hs_code: input.hs_code,
|
||||||
mid_code: variant.mid_code,
|
mid_code: input.mid_code,
|
||||||
material: variant.material,
|
material: input.material,
|
||||||
weight: variant.weight,
|
weight: input.weight,
|
||||||
length: variant.length,
|
length: input.length,
|
||||||
height: variant.height,
|
height: input.height,
|
||||||
width: variant.width,
|
width: input.width,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,10 +93,9 @@ export const createInventoryItemTransaction = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function attachInventoryItem(
|
async function attachInventoryItem(inventoryItem: InventoryItemDTO) {
|
||||||
variant: ProductVariant,
|
const variant = await productVariantServiceTx.retrieve(variantId)
|
||||||
inventoryItem: InventoryItemDTO
|
|
||||||
) {
|
|
||||||
if (!variant.manage_inventory) {
|
if (!variant.manage_inventory) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -136,7 +132,7 @@ export const createInventoryItemTransaction = async (
|
|||||||
) => {
|
) => {
|
||||||
const { [actions.createInventoryItem]: inventoryItem } = invoke
|
const { [actions.createInventoryItem]: inventoryItem } = invoke
|
||||||
|
|
||||||
return await attachInventoryItem(variant, inventoryItem)
|
return await attachInventoryItem(inventoryItem)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user