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(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,
|
||||
|
||||
Reference in New Issue
Block a user