FIX Can't delete a line of minimal stock per warehouse

This commit is contained in:
Laurent Destailleur 2018-12-16 19:23:53 +01:00
parent 20d24f2feb
commit 003c463ee4

View File

@ -157,13 +157,12 @@ class ProductStockEntrepot extends CommonObject
/** /**
* Load object in memory from the database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @param int $fk_product Id product * @param int $fk_product Id product
* @param int $fk_entrepot Id warehouse * @param int $fk_entrepot Id warehouse
* * @return int <0 if KO, 0 if not found, >0 if OK
* @return int <0 if KO, 0 if not found, >0 if OK
*/ */
public function fetch($id, $fk_product, $fk_entrepot) public function fetch($id, $fk_product=0, $fk_entrepot=0)
{ {
if(empty($id) && (empty($fk_product) || empty($fk_entrepot))) return -1; if(empty($id) && (empty($fk_product) || empty($fk_entrepot))) return -1;
@ -171,23 +170,22 @@ class ProductStockEntrepot extends CommonObject
$sql = 'SELECT'; $sql = 'SELECT';
$sql .= ' t.rowid,'; $sql .= ' t.rowid,';
$sql .= " t.tms,"; $sql .= " t.tms,";
$sql .= " t.fk_product,"; $sql .= " t.fk_product,";
$sql .= " t.fk_entrepot,"; $sql .= " t.fk_entrepot,";
$sql .= " t.seuil_stock_alerte,"; $sql .= " t.seuil_stock_alerte,";
$sql .= " t.desiredstock,"; $sql .= " t.desiredstock,";
$sql .= " t.import_key"; $sql .= " t.import_key";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if(!empty($id)) $sql .= ' WHERE t.rowid = ' . $id; if(!empty($id)) $sql .= ' WHERE t.rowid = ' . $id;
else $sql.= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot; else $sql.= ' WHERE t.fk_product = '.$fk_product.' AND t.fk_entrepot = '.$fk_entrepot;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql)
{
$numrows = $this->db->num_rows($resql); $numrows = $this->db->num_rows($resql);
if ($numrows) { if ($numrows)
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -198,8 +196,6 @@ class ProductStockEntrepot extends CommonObject
$this->seuil_stock_alerte = $obj->seuil_stock_alerte; $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
$this->desiredstock = $obj->desiredstock; $this->desiredstock = $obj->desiredstock;
$this->import_key = $obj->import_key; $this->import_key = $obj->import_key;
} }
// Retreive all extrafield // Retreive all extrafield