Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2018-03-11 00:16:21 +01:00
commit 06689bb79f
2 changed files with 20 additions and 14 deletions

View File

@ -1081,32 +1081,43 @@ class Expedition extends CommonObject
/** /**
* Delete shipment. * Delete shipment.
* Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element)
* *
* @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO
*/ */
function delete() function delete()
{ {
global $conf, $langs, $user; global $conf, $langs, $user;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($conf->productbatch->enabled)
{
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';
}
$error=0; $error=0;
$this->error=''; $this->error='';
$this->db->begin();
// Add a protection to refuse deleting if shipment has at least one delivery // Add a protection to refuse deleting if shipment has at least one delivery
$this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment
if (count($this->linkedObjectsIds) > 0) if (count($this->linkedObjectsIds) > 0)
{ {
$this->error='ErrorThereIsSomeDeliveries'; $this->error='ErrorThereIsSomeDeliveries';
return -1; $error++;
}
if (! $error)
{
if (! $notrigger)
{
// Call trigger
$result=$this->call_trigger('SHIPPING_DELETE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
} }
$this->db->begin();
// Stock control // Stock control
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
{ {
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
@ -1203,11 +1214,6 @@ class Expedition extends CommonObject
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// Call trigger
$result=$this->call_trigger('SHIPPING_DELETE',$user);
if ($result < 0) { $error++; }
// End call triggers
if (! empty($this->origin) && $this->origin_id > 0) if (! empty($this->origin) && $this->origin_id > 0)
{ {
$this->fetch_origin(); $this->fetch_origin();

View File

@ -200,7 +200,7 @@ class CodingSqlTest extends PHPUnit_Framework_TestCase
else else
{ {
// Test for non key files only // Test for non key files only
$result=(strpos($filecontent,'KEY ') && strpos($filecontent,'PRIMARY KEY ') == 0); $result=(strpos($filecontent,'KEY ') && strpos($filecontent,'PRIMARY KEY') == 0);
print __METHOD__." Result for checking we don't have ' KEY ' instead of a sql file to create index = ".$result."\n"; print __METHOD__." Result for checking we don't have ' KEY ' instead of a sql file to create index = ".$result."\n";
$this->assertTrue($result===false, 'Found KEY into '.$file.'. Bad.'); $this->assertTrue($result===false, 'Found KEY into '.$file.'. Bad.');