diff --git a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js index e85cf50b0c..f6081fb50b 100644 --- a/packages/medusa-plugin-brightpearl/src/services/brightpearl.js +++ b/packages/medusa-plugin-brightpearl/src/services/brightpearl.js @@ -302,7 +302,7 @@ class BrightpearlService extends BaseService { .get(sku) ?.get(location.id) - if (!inventoryLevel || !warehouseData) { + if (!inventoryLevel) { return } @@ -342,19 +342,21 @@ class BrightpearlService extends BaseService { async adjustMedusaLocationLevel_(location, inventoryLevel, warehouseData) { 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( inventoryLevel.inventory_item_id, inventoryLevel.location_id, - { stocked_quantity: warehouseData.inStock }, + { stocked_quantity: bpinStock }, { transactionManager: manager } ) } const externallyReservedQuantityAdjustment = - warehouseData.inStock - - warehouseData.onHand - + bpinStock - + bpOnHand - inventoryLevel.reserved_quantity if (externallyReservedQuantityAdjustment === 0) { @@ -461,10 +463,6 @@ class BrightpearlService extends BaseService { const warehouseData = productAvailability.warehouses[`${location.metadata.bp_id}`] - if (!warehouseData) { - return - } - await this.adjustMedusaLocationLevel_( location, inventoryLevel,