Skip to content

Commit

Permalink
MC-41122: Inventory reservation compensation does not handle partial …
Browse files Browse the repository at this point in the history
…shippements
  • Loading branch information
yelahin-serhiy committed Mar 11, 2021
1 parent e5f5ee7 commit f24eccc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ public function execute(int $bunchSize = 50, int $page = 1): array
->join(
['item' => $orderItemTableName],
'item.order_id = main_table.entity_id',
['item.sku', 'item.qty_ordered']
[
'item.sku',
'item.is_virtual',
'item.qty_ordered',
'item.qty_canceled',
'item.qty_invoiced',
'item.qty_refunded',
'item.qty_shipped'
]
)
->where('main_table.entity_id IN (?)', $entityIds)
->where('item.product_type IN (?)', $this->allowedProductTypesForSourceItemManagement->execute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function execute(Collector $collector, int $bunchSize = 50, int $page = 1

$reservation = $this->reservationBuilder
->setSku($data['sku'])
->setQuantity((float)$data['qty_ordered'])
->setQuantity($this->calculateReservationQty($data))
->setStockId($stockId)
->setMetadata($this->serializer->serialize(
[
Expand All @@ -86,4 +86,20 @@ public function execute(Collector $collector, int $bunchSize = 50, int $page = 1
$collector->addOrderData($data);
}
}

/**
* Return reservation qty amount
*
* @param array $data
* @return float
*/
private function calculateReservationQty(array $data): float
{
$qty = $data['qty_ordered'];
$qty -= $data['qty_canceled'];
$qty -= $data['qty_refunded'];
$qty -= $data['is_virtual'] ? $data['qty_invoiced'] : $data['qty_shipped'];

return (float)$qty;
}
}

0 comments on commit f24eccc

Please sign in to comment.