From 32853c481eb749492b1d365ef2b70a5c096a15f2 Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 24 Oct 2011 12:58:24 +0000 Subject: [PATCH] // Fixed StockCover // Removed id_stock_mvt_reason from StockManager::transferBetweenWarehouses() // It is now allowed to transfer stock within one warehouse if and only if it only changes, for a given quantity, its usable state --- classes/stock/StockManager.php | 8 ++++---- classes/stock/StockManagerInterface.php | 3 +-- controllers/admin/AdminStockCoverController.php | 5 +++-- controllers/admin/AdminStockManagementController.php | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/classes/stock/StockManager.php b/classes/stock/StockManager.php index 82ae4192d..6a0efa2b8 100644 --- a/classes/stock/StockManager.php +++ b/classes/stock/StockManager.php @@ -444,7 +444,6 @@ class StockManagerCore implements StockManagerInterface public function transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, - $id_stock_mvt_reason, $id_warehouse_from, $id_warehouse_to, $usable_from = true, @@ -454,7 +453,7 @@ class StockManagerCore implements StockManagerInterface if ($this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($id_warehouse_from), $usable_from) < $quantity) return false; - if ($id_warehouse_from == $id_warehouse_to) + if ($id_warehouse_from == $id_warehouse_to && $usable_from == $usable_to) return false; // Checks if the given warehouses are available @@ -469,7 +468,7 @@ class StockManagerCore implements StockManagerInterface $id_product_attribute, $warehouse_from, $quantity, - $id_stock_mvt_reason, + Configuration::get('PS_STOCK_MVT_TRANSFER_FROM'), $usable_from); if (!count($stocks)) return false; @@ -493,7 +492,7 @@ class StockManagerCore implements StockManagerInterface $id_product_attribute, $warehouse_to, $stock['quantity'], - $id_stock_mvt_reason, + Configuration::get('PS_STOCK_MVT_TRANSFER_TO'), $price, $usable_to)) return false; @@ -522,6 +521,7 @@ class StockManagerCore implements StockManagerInterface LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = s.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product`) WHERE sm.`sign` = -1 + AND sm.`id_stock_mvt_reason` != '.Configuration::get('PS_STOCK_MVT_TRANSFER_FROM').' AND TO_DAYS(NOW()) - TO_DAYS(sm.`date_add`) <= '.(int)$coverage.' AND s.`id_product` = '.(int)$id_product.' AND s.`id_product_attribute` = '.(int)$id_product_attribute. diff --git a/classes/stock/StockManagerInterface.php b/classes/stock/StockManagerInterface.php index edb50069e..8b97a1a52 100644 --- a/classes/stock/StockManagerInterface.php +++ b/classes/stock/StockManagerInterface.php @@ -101,14 +101,13 @@ interface StockManagerInterface * @param int $id_product * @param int $id_product_attribute * @param int $quantity - * @param int $id_stock_movement_reason * @param int $warehouse_from * @param int $warehouse_to * @param bool $usable_from true by default * @param bool $usable_to true by default * @return bool */ - public function transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, $id_stock_movement_reason, $warehouse_from, $warehouse_to, $usable_from = true, $usable_to = true); + public function transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, $warehouse_from, $warehouse_to, $usable_from = true, $usable_to = true); /** * For a given product, returns the time left before being out of stock. diff --git a/controllers/admin/AdminStockCoverController.php b/controllers/admin/AdminStockCoverController.php index 1d943ecff..6f29f5296 100644 --- a/controllers/admin/AdminStockCoverController.php +++ b/controllers/admin/AdminStockCoverController.php @@ -146,9 +146,10 @@ class AdminStockCoverControllerCore extends AdminController $this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, s.physical_quantity as stock'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product) - LEFT JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product AND s.id_product_attribute = 0)'; + INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)'; + $this->where = 'AND s.id_product_attribute = 0'; if ($this->getCurrentCoverageWarehouse() != -1) - $this->_where = 'AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse(); + $this->_where .= 'AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse(); $this->context->smarty->assign('stock_cover_periods', $this->stock_cover_periods); $this->context->smarty->assign('stock_cover_cur_period', $this->getCurrentCoveragePeriod()); diff --git a/controllers/admin/AdminStockManagementController.php b/controllers/admin/AdminStockManagementController.php index dcf11a94a..0cc995e47 100644 --- a/controllers/admin/AdminStockManagementController.php +++ b/controllers/admin/AdminStockManagementController.php @@ -650,7 +650,6 @@ class AdminStockManagementControllerCore extends AdminController $id_product, $id_product_attribute, $quantity, - 1, //@TOTO specify new default movement for transfer $id_warehouse_from, $id_warehouse_to, $usable_from,