// Stock : updated Stock & StockMvt & StockMvtReason

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9329 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone committed 2011-10-13 16:06:09 +00:00
1 parent cf8cb50631
commit ae43d7f86b
3 files changed
+168 -73

No files matched your search

+33 -19
View File
@@ -20,25 +20,47 @@
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA * @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 1.4 $ * @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
/** /**
* Represents the products kept in warehouses
*
* @since 1.5.0 * @since 1.5.0
*/ */
class StockCore extends ObjectModel class StockCore extends ObjectModel
{ {
public $id_warehouse;
public $id_product; public $id_product;
public $id_product_attribute; public $id_product_attribute;
public $id_group_shop; public $physical_quantity;
public $id_shop; public $usable_quantity;
public $quantity; public $price_te;
public $id_currency;
protected $fieldsRequired = array(
'id_warehouse',
'id_product',
'id_product_attribute',
'physical_quantity',
'usable_quantity',
'price_te',
'id_currency'
);
protected $fieldsRequired = array('id_shop', 'id_group_shop', 'id_product', 'id_product_attribute');
protected $fieldsSize = array(); protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsValidate = array(
'id_warehouse' => 'isUnsignedId',
'id_product' => 'isUnsignedId',
'id_product_attribute' => 'isUnsignedId',
'physical_quantity' => 'isUnsignedInt',
'usable_quantity' => 'isInt',
'price_te' => 'isPrice',
'id_currency' => 'isUnsignedInt'
);
protected $table = 'stock'; protected $table = 'stock';
protected $identifier = 'id_stock'; protected $identifier = 'id_stock';
@@ -46,21 +68,13 @@ class StockCore extends ObjectModel
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
$fields['id_warehouse'] = (int)$this->id_warehouse;
$fields['id_product'] = (int)$this->id_product; $fields['id_product'] = (int)$this->id_product;
$fields['id_product_attribute'] = (int)$this->id_product_attribute; $fields['id_product_attribute'] = (int)$this->id_product_attribute;
$fields['id_group_shop'] = (int)$this->id_group_shop; $fields['physical_quantity'] = (int)$this->physical_quantity;
$fields['id_shop'] = (int)$this->id_shop; $fields['usable_quantity'] = (int)$this->usable_quantity;
$fields['quantity'] = (int)$this->quantity; $fields['price_te'] = (float)$this->price_te;
$fields['id_currency'] = (int)$this->id_currency;
return $fields; return $fields;
} }
public static function getStockId($id_product, $id_product_attribute, $shopID)
{
$sql = 'SELECT id_stock
FROM '._DB_PREFIX_.'stock
WHERE id_product = '.(int)$id_product.'
AND id_product_attribute = '.(int)$id_product_attribute.'
AND id_shop = '.(int)$shopID;
return (int)Db::getInstance()->getValue($sql);
}
} }
+103 -34
View File
@@ -20,73 +20,142 @@
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA * @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7307 $ * @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
class StockMvtCore extends ObjectModel class StockMvtCore extends ObjectModel
{ {
public $id; public $id;
public $date_add;
public $id_employee;
/** /**
* @since 1.5.0 id_stock replace old id_product and id_product_attribute fields in this table * @since 1.5.0
* @var int * @var int
*/ */
public $id_stock; public $id_stock;
public $id_order = NULL; /**
public $id_employee = NULL; * @since 1.5.0
public $quantity; * @var int
public $id_stock_mvt_reason; */
public $physical_quantity;
public $date_add; public $id_stock_mvt_reason;
public $date_upd; public $id_order = null;
protected $table = 'stock_mvt'; /**
protected $identifier = 'id_stock_mvt'; * @since 1.5.0
* @var int
*/
public $sign;
protected $fieldsRequired = array('id_stock', 'id_stock_mvt_reason', 'quantity'); /**
protected $fieldsValidate = array( * @since 1.5.0
'id_stock' => 'isUnsignedId', * @var int Will be used when supplier order are implemented
'id_order' => 'isUnsignedId', */
'id_employee' => 'isUnsignedId', public $id_supplier_order = null;
'quantity' => 'isInt',
'id_stock_mvt_reason' => 'isUnsignedId',
);
protected $webserviceParameters = array( /**
* @since 1.5.0
* @var float Last value of the weighted-average method
*/
public $last_wa = null;
/**
* @since 1.5.0
* @var float Current value of the weighted-average method
*/
public $current_wa = null;
/**
* @since 1.5.0
* @var float
*/
public $price_te;
/**
* @since 1.5.0
* @var int Refers to an other id_stock_mvt : used for LIFO/FIFO implementation in StockManager
*/
public $referer;
/**
* @deprecated since 1.5.0
* @deprecated stock movement will not be updated anymore
*/
public $date_upd;
/**
* @deprecated since 1.5.0
* @see physical_quantity
* @var int
*/
public $quantity;
protected $table = 'stock_mvt';
protected $identifier = 'id_stock_mvt';
protected $fieldsRequired = array(
'date_add',
'id_employee',
'id_stock',
'physical_quantity',
'id_stock_mvt_reason',
'sign',
'price_te'
);
protected $fieldsValidate = array(
'date_add' => 'isDate',
'id_employee' => 'isUnsignedId',
'id_stock' => 'isUnsignedId',
'physical_quantity' => 'isUnsignedInt',
'id_stock_mvt_reason' => 'isUnsignedId',
'id_order' => 'isUnsignedId',
'sign' => 'isInt',
'last_wa' => 'isPrice',
'current_wa' => 'isPrice',
'price_te' => 'isPrice',
'referer' => 'isUnsignedId'
);
protected $webserviceParameters = array(
'objectsNodeName' => 'stock_movements', 'objectsNodeName' => 'stock_movements',
'objectNodeName' => 'stock_movement', 'objectNodeName' => 'stock_movement',
'fields' => array( 'fields' => array(
'id_product' => array('xlink_resource'=> 'products'),
'id_product_attribute' => array('xlink_resource'=> 'product_option_values'),
'id_order' => array('xlink_resource'=> 'orders'),
'id_employee' => array('xlink_resource'=> 'employees'), 'id_employee' => array('xlink_resource'=> 'employees'),
'id_stock' => array('xlink_resource'=> 'stock'),
'id_stock_mvt_reason' => array('xlink_resource'=> 'stock_movement_reasons'), 'id_stock_mvt_reason' => array('xlink_resource'=> 'stock_movement_reasons'),
'id_order' => array('xlink_resource'=> 'orders')
), ),
); );
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
$fields['id_stock'] = (int)$this->id_stock;
$fields['id_order'] = (int)$this->id_order;
$fields['id_employee'] = (int)$this->id_employee;
$fields['id_stock_mvt_reason'] = (int)$this->id_stock_mvt_reason;
$fields['quantity'] = (int)$this->quantity;
$fields['date_add'] = pSQL($this->date_add); $fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd); $fields['id_employee'] = (int)$this->id_employee;
$fields['id_stock'] = (int)$this->id_stock;
$fields['physical_quantity'] = (int)$this->physical_quantity;
$fields['id_stock_mvt_reason'] = (int)$this->id_stock_mvt_reason;
$fields['id_order'] = (int)$this->id_order;
$fields['sign'] = (int)$this->sign;
$fields['last_wa'] = (float)$this->last_wa;
$fields['current_wa'] = (float)$this->current_wa;
$fields['price_te'] = (float)$this->price_te;
$fields['referer'] = (int)$this->referer;
return $fields; return $fields;
} }
/** /**
* Add missing stock movement (compare the quantity of a products with all movements : if there is a difference, create a stock movement to correct it) * @deprecated since 1.5.0
*
* @param int $id_employee
*/ */
public static function addMissingMvt($id_employee) public static function addMissingMvt($id_employee)
{ {
Tools::displayAsDeprecated();
// Search missing stock movement on products without attributes // Search missing stock movement on products without attributes
$sql = 'SELECT s.id_stock, (stock.quantity - SUM(IFNULL(sm.quantity, 0))) AS qty $sql = 'SELECT s.id_stock, (stock.quantity - SUM(IFNULL(sm.quantity, 0))) AS qty
FROM '._DB_PREFIX_.'product p FROM '._DB_PREFIX_.'product p
@@ -119,7 +188,7 @@ class StockMvtCore extends ObjectModel
// Add missing stock movements // Add missing stock movements
$products = array_merge($products_without_attributes, $products_with_attributes); $products = array_merge($products_without_attributes, $products_with_attributes);
if ($products) if ($products)
foreach ($products AS $product) foreach ($products as $product)
{ {
$mvt = new StockMvt(); $mvt = new StockMvt();
$mvt->id_stock = $product['id_stock']; $mvt->id_stock = $product['id_stock'];
+32 -20
View File
@@ -20,30 +20,26 @@
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA * @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7307 $ * @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
class StockMvtReasonCore extends ObjectModel class StockMvtReasonCore extends ObjectModel
{ {
public $id; public $id;
public $name; public $name;
public $sign;
public $date_add;
public $date_upd;
protected $table = 'stock_mvt_reason';
protected $identifier = 'id_stock_mvt_reason';
public $sign; protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 255);
protected $fieldsValidateLang = array('name' => 'isGenericName');
public $date_add; protected $webserviceParameters = array(
public $date_upd;
protected $table = 'stock_mvt_reason';
protected $identifier = 'id_stock_mvt_reason';
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 255);
protected $fieldsValidateLang = array('name' => 'isGenericName');
protected $webserviceParameters = array(
'objectsNodeName' => 'stock_movement_reasons', 'objectsNodeName' => 'stock_movement_reasons',
'objectNodeName' => 'stock_movement_reason', 'objectNodeName' => 'stock_movement_reason',
); );
@@ -65,9 +61,25 @@ class StockMvtReasonCore extends ObjectModel
public static function getStockMvtReasons($id_lang) public static function getStockMvtReasons($id_lang)
{ {
$sql = 'SELECT smrl.name, smr.id_stock_mvt_reason, smr.sign $query = new DbQuery();
FROM '._DB_PREFIX_.'stock_mvt_reason smr $query->select('smrl.name, smr.id_stock_mvt_reason, smr.sign');
LEFT JOIN '._DB_PREFIX_.'stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')'; $query->from('stock_mvt_reason smr');
return Db::getInstance()->executeS($sql); $query->leftjoin('stock_mvt_reason_lang smrl ON (smr.id_stock_mvt_reason = smrl.id_stock_mvt_reason AND smrl.id_lang='.(int)$id_lang.')');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
/**
* @since 1.5.0
*
* @param int $id_stock_mvt_reason
* @return bool
*/
public static function exists($id_stock_mvt_reason)
{
$query = new DbQuery();
$query->select('smr.id_stock_mvt_reason');
$query->from('stock_mvt_reason smr');
$query->where('smr.id_stock_mvt_reason = '.(int)$id_stock_mvt_reason);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
} }
} }