diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 522016edfd9..c84c1aba64b 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1104,7 +1104,7 @@ class Commande extends CommonOrder } $product_type=$type; - if ($fk_product) + if (!empty($fk_product)) { $product=new Product($this->db); $result=$product->fetch($fk_product); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9e51dfc29ed..09fbc867bc4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2067,7 +2067,7 @@ class Facture extends CommonInvoice } $product_type=$type; - if ($fk_product) + if (!empty($fk_product)) { $product=new Product($this->db); $result=$product->fetch($fk_product); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 914ec871951..5ac1ba15a77 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -710,12 +710,33 @@ class Expedition extends CommonObject */ function addline($entrepot_id, $id, $qty) { + global $conf, $langs; + $num = count($this->lines); $line = new ExpeditionLigne($this->db); $line->entrepot_id = $entrepot_id; $line->origin_line_id = $id; $line->qty = $qty; + + if($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { + $orderline = new OrderLine($this->db); + $orderline->fetch($id); + $fk_product = $orderline->fk_product; + + if (!empty($orderline->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($fk_product); + $product_type=$product->type; + + if($product_type == 0 && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } + } + } $this->lines[$num] = $line; } diff --git a/htdocs/langs/en_US/deliveries.lang b/htdocs/langs/en_US/deliveries.lang index c440bea0163..fc4ff2436d4 100644 --- a/htdocs/langs/en_US/deliveries.lang +++ b/htdocs/langs/en_US/deliveries.lang @@ -22,4 +22,5 @@ ToAndDate=To___________________________________ on ____/_____/__________ GoodStatusDeclaration=Have received the goods above in good condition, Deliverer=Deliverer : Sender=Sender -Recipient=Recipient \ No newline at end of file +Recipient=Recipient +ErrorStockIsNotEnough=There's not enough stock \ No newline at end of file