@@ -3131,7 +3131,7 @@ class Product extends CommonObject
* @param double $nbpiece nb of units
* @param int $movement 0 = add, 1 = remove
* @param string $label Label of stock movement
* @param double $price Price to use for stock eval
* @param double $price Unit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed.
'warehouse_ref'=>array('name'=>'warehouse_ref','type'=>'xsd:string'),// Used only for create or update to set which warehouse to use for stock correction if stock_real differs from database
$newobject->load_stock();// This overwrite ->stock_reel
$getstockreal=$newobject->stock_reel;
if($savstockreal!=$getstockreal)
{
$warehouse=newEntrepot($this->db);
$warehouse->fetch(0,$product['warehouse_ref']);
if($warehouse->id>0)
{
if(($savstockreal-$getstockreal)>0)
{
$result=$newobject->correct_stock($fuser,$warehouse->id,($savstockreal-$getstockreal),0,'Correction from external call (Web Service)',0,'WS'.dol_print_date($now,'dayhourlog'));
}
if(($savstockreal-$getstockreal)>0)
{
$result=$newobject->correct_stock($fuser,$warehouse->id,($savstockreal-$getstockreal),1,'Correction from external call (Web Service)',0,'WS'.dol_print_date($now,'dayhourlog'));
}
if($result<=0)
{
$error++;
$newobject->error='You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
}
}
else
{
$error++;
$newobject->error='You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
}
}
}
}
if(!$error)
{
$db->commit();
...
...
@@ -691,6 +733,46 @@ function updateProductOrService($authentication,$product)
{
$error++;
}
else
{
// Update stock if stock count is provided and differs from database after creation or update
$newobject->load_stock();// This overwrite ->stock_reel
$getstockreal=$newobject->stock_reel;
if($savstockreal!=$getstockreal)
{
$warehouse=newEntrepot($this->db);
$warehouse->fetch(0,$product['warehouse_ref']);
if($warehouse->id>0)
{
if(($savstockreal-$getstockreal)>0)
{
$result=$newobject->correct_stock($fuser,$warehouse->id,($savstockreal-$getstockreal),0,'Correction from external call (Web Service)',0,'WS'.dol_print_date($now,'dayhourlog'));
}
if(($savstockreal-$getstockreal)>0)
{
$result=$newobject->correct_stock($fuser,$warehouse->id,($savstockreal-$getstockreal),1,'Correction from external call (Web Service)',0,'WS'.dol_print_date($now,'dayhourlog'));
}
if($result<=0)
{
$error++;
$newobject->error='You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error;
}
}
else
{
$error++;
$newobject->error='You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.';
}
}
}
}
if(!$error)
{
if($newobject->price_base_type=='HT')
...
...
@@ -717,7 +799,7 @@ function updateProductOrService($authentication,$product)