FIX Protection when database has a corrupted product id
This commit is contained in:
parent
7380fa32ec
commit
d204cfe6c6
@ -109,7 +109,7 @@ class MouvementStock extends CommonObject
|
||||
* @param string $batch batch number
|
||||
* @param boolean $skip_batch If set to true, stock movement is done without impacting batch record
|
||||
* @param int $id_product_batch Id product_batch (when skip_batch is false and we already know which record of product_batch to use)
|
||||
* @return int <0 if KO, 0 if fk_product is null, >0 if OK
|
||||
* @return int <0 if KO, 0 if fk_product is null or product id does not exists, >0 if OK
|
||||
*/
|
||||
public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '', $eatby = '', $sellby = '', $batch = '', $skip_batch = false, $id_product_batch = 0)
|
||||
{
|
||||
@ -155,13 +155,15 @@ class MouvementStock extends CommonObject
|
||||
|
||||
$product = new Product($this->db);
|
||||
$result=$product->fetch($fk_product);
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$this->error = $product->error;
|
||||
$this->errors = $product->errors;
|
||||
dol_print_error('', "Failed to fetch product");
|
||||
return -1;
|
||||
}
|
||||
if ($product->id <= 0) { // Can happen if database is corrupted
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user