diff --git a/ChangeLog b/ChangeLog index 8a64ec49e1a..5b6ca396de7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,7 +17,8 @@ For users: - Fix: bug #28055 : Unable to modify the date of a cloned command. - Fix: bug #27891. - Fix: Change of numbering module was not effective. - +- Fix: Change error management when adding already used supplier ref + for a product. ***** ChangeLog for 2.7 compared to 2.6 ***** diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 7211eabedf8..018cd326f14 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -111,7 +111,7 @@ class Product extends CommonObject //! Id du fournisseur var $product_fourn_id; - + //! Product ID already linked to a reference supplier var $product_id_already_linked; @@ -1672,16 +1672,16 @@ class Product extends CommonObject } /** - * \brief Lie un fournisseur au produit/service - * \param user Utilisateur qui fait le lien - * \param id_fourn Id du fournisseur - * \param ref_fourn Reference chez le fournisseur - * \return int < 0 if KO, 0 if link already exists, > 0 if OK + * \brief Add a supplier reference for the product + * \param user User that make link + * \param id_fourn Supplier id + * \param ref_fourn Supplier ref + * \return int < 0 if KO, 0 if link already exists for this product, > 0 if OK */ function add_fournisseur($user, $id_fourn, $ref_fourn) { global $conf; - + $sql = "SELECT rowid, fk_product"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur"; $sql.= " WHERE fk_soc = ".$id_fourn; @@ -1693,10 +1693,9 @@ class Product extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); - $nb = count($obj); - - // The reference supplier does not exist, it creates for this product. - if (!$nb) + + // The reference supplier does not exist, we create it for this product. + if (! $obj) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur ("; $sql.= "datec"; @@ -1727,19 +1726,19 @@ class Product extends CommonObject return -1; } } - // If the reference supplier is already linked to this product + // If the supplier ref already exists for this product else if ($obj->fk_product == $this->id) { $this->product_fourn_id = $obj->rowid; - + return 0; } - // If the reference provider is not linked to this product + // If the supplier ref already exists but for another product else { $this->product_id_already_linked = $obj->fk_product; - - return 2; + + return -3; } } else @@ -1757,7 +1756,7 @@ class Product extends CommonObject function list_suppliers() { global $conf; - + $list = array(); $sql = "SELECT fk_soc"; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 818f0e27400..e419c443ee1 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -110,22 +110,22 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc if (! $error) { $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]); - if ($ret < 0) + if ($ret == -3) + { + $error++; + + $product->fetch($product->product_id_already_linked); + $productLink = $product->getNomUrl(1,'supplier'); + + $mesg='