/** * @param \Praxigento\Odoo\Data\Odoo\Inventory\Product\Warehouse\Lot[] $lots * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem */ public function processLots($lots, $stockItem) { $qtyTotal = 0; $stockItemId = $stockItem->getItemId(); foreach ($lots as $lot) { $qtyTotal += $this->_subLot->processLot($stockItemId, $lot); } /* update stock item qty */ $stockItem->setQty($qtyTotal); $isInStock = $qtyTotal > 0; $stockItem->setIsInStock($isInStock); $this->_mageRepoStockItem->save($stockItem); /* cleanup extra lots */ $this->_subLot->cleanupLots($stockItemId, $lots); }
public function test_cleanupLots() { /** === Test Data === */ $STOCK_ITEM_ID = 32; $LOT_ID_O1 = 41; $LOT_ID_M1 = 21; $LOT_ID_M2 = 22; $LOTS = []; $LOTS_EXIST = [[Quantity::ATTR_LOT_REF => $LOT_ID_M1], [Quantity::ATTR_LOT_REF => $LOT_ID_M2]]; /** === Setup Mocks === */ // $lotsExist = $this->_repoWarehouseEntityQuantity->get($where); $this->mRepoWrhsEntityQty->shouldReceive('get')->once()->andReturn($LOTS_EXIST); // $lotIdOdoo = $lot->getId(); $mLot = new \Praxigento\Odoo\Data\Odoo\Inventory\Product\Warehouse\Lot(); $LOTS[] = $mLot; $mLot->setIdOdoo($LOT_ID_O1); // $lotIdMage = $this->_repoAggLot->getMageIdByOdooId($lotIdOdoo); $this->mRepoAggLot->shouldReceive('getMageIdByOdooId')->once()->andReturn($LOT_ID_M1); // $this->_repoWarehouseEntityQuantity->deleteById($pk); $this->mRepoWrhsEntityQty->shouldReceive('deleteById')->once(); /** === Call and asserts === */ $this->obj->cleanupLots($STOCK_ITEM_ID, $LOTS); }