From 5890d3b31302b7d202659c4f9e1056cf42e270c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Mati=C4=87?= Date: Thu, 7 Sep 2023 13:29:48 +0200 Subject: [PATCH] fix(medusa-plugin-brightpearl): Inventory sync for OOS items in brightpearl (#4966) --- .../src/services/brightpearl.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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,