// Warehouse: it is not possible to delete a warehouse of it has pending supply orders.
This commit is contained in:
@@ -39,6 +39,10 @@
|
||||
<td>{l s='Name:'}</td>
|
||||
<td>{$warehouse->name}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Manager:'}</td>
|
||||
<td>{$employee->lastname} {$employee->firstname}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Country:'}</td>
|
||||
<td>{if $address->country != ''}{$address->country}{else}{l s='N/D'}{/if}</td>
|
||||
@@ -52,8 +56,8 @@
|
||||
<td>{$warehouse->management_type}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Manager:'}</td>
|
||||
<td>{$employee->lastname} {$employee->firstname}</td>
|
||||
<td>{l s='Valuation currency:'}</td>
|
||||
<td>{$currency->name} ({$currency->sign})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{l s='Products:'}</td>
|
||||
|
||||
@@ -174,9 +174,9 @@ class StockMvtCore extends ObjectModel
|
||||
$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)round($this->last_wa, 6);
|
||||
$fields['current_wa'] = (float)round($this->current_wa, 6);
|
||||
$fields['price_te'] = (float)round($this->price_te, 6);
|
||||
$fields['last_wa'] = (float)Tools::ps_round($this->last_wa, 6);
|
||||
$fields['current_wa'] = (float)Tools::ps_round($this->current_wa, 6);
|
||||
$fields['price_te'] = (float)Tools::ps_round($this->price_te, 6);
|
||||
$fields['referer'] = (int)$this->referer;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Historizes
|
||||
* Historizes the order : its id, its state, and the employee responsible for the current action
|
||||
*/
|
||||
protected function addHistory()
|
||||
{
|
||||
@@ -381,7 +381,7 @@ class SupplyOrderCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all products ordered
|
||||
* Removes all products from the order
|
||||
*/
|
||||
public function resetProducts()
|
||||
{
|
||||
@@ -390,4 +390,27 @@ class SupplyOrderCore extends ObjectModel
|
||||
foreach ($products as $p)
|
||||
$p->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given $id_warehouse, tells if it has pending supply orders
|
||||
*
|
||||
* @param int $id_warehouse
|
||||
* @return bool
|
||||
*/
|
||||
public static function warehouseHasPendingOrders($id_warehouse)
|
||||
{
|
||||
if (!$id_warehouse)
|
||||
return false;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('COUNT(so.id_supply_order) as supply_orders');
|
||||
$query->from('supply_order so');
|
||||
$query->leftJoin('supply_order_state sos ON (so.id_supply_order_state = sos.id_supply_order_state)');
|
||||
$query->where('sos.enclosed != 1');
|
||||
$query->where('so.id_warehouse = '.(int)$id_warehouse);
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||
return ($res > 0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class AdminStockMvtControllerCore extends AdminController
|
||||
'visibility' => Shop::CONTEXT_ALL
|
||||
),
|
||||
'PS_STOCK_MVT_SUPPLY_ORDER' => array(
|
||||
'title' => $this->l('Default reason when incrementing stock when a supplier order is received:'),
|
||||
'title' => $this->l('Default reason when incrementing stock when a supply order is received:'),
|
||||
'cast' => 'intval',
|
||||
'type' => 'select',
|
||||
'list' => $reasons_inc,
|
||||
|
||||
@@ -440,6 +440,8 @@ class AdminWarehousesControllerCore extends AdminController
|
||||
return;
|
||||
else if ($obj->getQuantitiesOfProducts() > 0)
|
||||
$this->_errors[] = $this->l('It is not possible to delete a Warehosue when there are products in it.');
|
||||
else if (SupplyOrder::warehouseHasPendingOrders($obj->id))
|
||||
$this->_errors[] = $this->l('It is not possible to delete a Warehouse if it has pending supply orders.');
|
||||
else
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user