fix(medusa-plugin-brightpearl): Inventory sync for OOS items in brightpearl (#4966)

This commit is contained in:
Josip Matić
2023-09-07 13:29:48 +02:00
committed by GitHub
parent c7b149a7bc
commit 5890d3b313

View File

@@ -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,