fix(medusa-plugin-brightpearl): Inventory sync for OOS items in brightpearl (#4966)
This commit is contained in:
@@ -302,7 +302,7 @@ class BrightpearlService extends BaseService {
|
|||||||
.get(sku)
|
.get(sku)
|
||||||
?.get(location.id)
|
?.get(location.id)
|
||||||
|
|
||||||
if (!inventoryLevel || !warehouseData) {
|
if (!inventoryLevel) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,19 +342,21 @@ class BrightpearlService extends BaseService {
|
|||||||
|
|
||||||
async adjustMedusaLocationLevel_(location, inventoryLevel, warehouseData) {
|
async adjustMedusaLocationLevel_(location, inventoryLevel, warehouseData) {
|
||||||
const manager = this.transactionManager_ ?? this.manager_
|
const manager = this.transactionManager_ ?? this.manager_
|
||||||
|
const bpOnHand = warehouseData?.onHand || 0
|
||||||
|
const bpinStock = warehouseData?.inStock || 0
|
||||||
|
|
||||||
if (inventoryLevel.stocked_quantity !== warehouseData.inStock) {
|
if (inventoryLevel.stocked_quantity !== bpinStock) {
|
||||||
await this.inventoryService_.updateInventoryLevel(
|
await this.inventoryService_.updateInventoryLevel(
|
||||||
inventoryLevel.inventory_item_id,
|
inventoryLevel.inventory_item_id,
|
||||||
inventoryLevel.location_id,
|
inventoryLevel.location_id,
|
||||||
{ stocked_quantity: warehouseData.inStock },
|
{ stocked_quantity: bpinStock },
|
||||||
{ transactionManager: manager }
|
{ transactionManager: manager }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const externallyReservedQuantityAdjustment =
|
const externallyReservedQuantityAdjustment =
|
||||||
warehouseData.inStock -
|
bpinStock -
|
||||||
warehouseData.onHand -
|
bpOnHand -
|
||||||
inventoryLevel.reserved_quantity
|
inventoryLevel.reserved_quantity
|
||||||
|
|
||||||
if (externallyReservedQuantityAdjustment === 0) {
|
if (externallyReservedQuantityAdjustment === 0) {
|
||||||
@@ -461,10 +463,6 @@ class BrightpearlService extends BaseService {
|
|||||||
const warehouseData =
|
const warehouseData =
|
||||||
productAvailability.warehouses[`${location.metadata.bp_id}`]
|
productAvailability.warehouses[`${location.metadata.bp_id}`]
|
||||||
|
|
||||||
if (!warehouseData) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.adjustMedusaLocationLevel_(
|
await this.adjustMedusaLocationLevel_(
|
||||||
location,
|
location,
|
||||||
inventoryLevel,
|
inventoryLevel,
|
||||||
|
|||||||
Reference in New Issue
Block a user