// Stock : add state management on orders + bugs fix

This commit is contained in:
dSevere
2011-10-31 16:52:40 +00:00
parent c4070782f1
commit 48c76d5889
4 changed files with 91 additions and 5 deletions
@@ -0,0 +1,27 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9197 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<a href="{$href}">
<img src="../img/admin/cog.gif" alt="{$action}" title="{$action}" /></a>
+27 -2
View File
@@ -182,7 +182,12 @@ class SupplierOrderCore extends ObjectModel
{
$this->calculatePrices();
return parent::update($null_values);
$return = parent::update($null_values);
if ($return)
$this->addHistory();
return $return;
}
/**
@@ -192,7 +197,12 @@ class SupplierOrderCore extends ObjectModel
{
$this->calculatePrices();
return parent::add($autodate, $null_values);
$return = parent::add($autodate, $null_values);
if ($return)
$this->addHistory();
return $return;
}
/**
@@ -301,4 +311,19 @@ class SupplierOrderCore extends ObjectModel
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query) == 1);
}
/**
* Add order history
*
* @return bool
*/
protected function addHistory()
{
$history = new SupplierOrderHistory();
$history->id_supplier_order = $this->id;
$history->id_state = $this->id_supplier_order_state;
$history->id_employee = $this->id_employee;
$history->save();
}
}
+1 -1
View File
@@ -228,7 +228,7 @@ class SupplierOrderDetailCore extends ObjectModel
// calcul tax value
$this->tax_value = $this->price_with_discount_te * ((float)$this->tax_rate / 100);
$this->price_ti = $this->price_with_discount_te - $this->tax_value;
$this->price_ti = $this->price_with_discount_te + $this->tax_value;
// define default values for order discount fields
$this->tax_value_with_order_discount = $this->tax_value;
+36 -2
View File
@@ -109,12 +109,13 @@ class SupplierOrderStateCore extends ObjectModel
/**
* Gets the list of supplier order states
*
* @param int $id_state_referrer The state refferer id used to know what state is available after the current state refferer
* @param int $id_lang The language id
* @return array
*/
public static function getSupplierOrderStates($id_lang = 0)
public static function getSupplierOrderStates($id_state_referrer = null, $id_lang = null)
{
if ($id_lang == 0)
if ($id_lang == null)
$id_lang = Context::getContext()->language->id;
$query = new DbQuery();
@@ -122,6 +123,39 @@ class SupplierOrderStateCore extends ObjectModel
$query->from('supplier_order_state s');
$query->leftjoin('supplier_order_state_lang sl ON (s.id_supplier_order_state = sl.id_supplier_order_state AND sl.id_lang='.(int)$id_lang.')');
if (!is_null($id_state_referrer))
{
$is_receipt_state = false;
$is_editable = false;
$is_delivery_note = false;
$is_pending_receipt = false;
//check current state to see what state is available
$state = new SupplierOrderState((int)$id_state_referrer);
if (Validate::isLoadedObject($state))
{
$is_receipt_state = $state->receipt_state;
$is_editable = $state->editable;
$is_delivery_note = $state->delivery_note;
$is_pending_receipt = $state->pending_receipt;
}
$query->where('s.id_supplier_order_state <> '.$id_state_referrer);
//check first if the order is editable
if ($is_editable)
$query->where(' s.editable = 0');
//check if the delivery note is available
else if ($is_delivery_note)
$query->where(' s.delivery_note = 0 AND s.editable = 0');
//check if the state correspond to a pending receipt state
else if ($is_pending_receipt)
$query->where(' s.receipt_state = 1 OR (s.receipt_state = 0 AND s.pending_receipt = 0)) AND s.delivery_note = 0 AND s.editable = 0');
//check if the state correspond to a receipt state
else if ($is_receipt_state)
$query->where(' s.receipt_state = 1 OR (s.receipt_state = 0 AND s.pending_receipt = 0 AND s.delivery_note = 0 AND s.editable = 0)');
}
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
}