diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 8b8777ef2f4..47219049a91 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2016 Ferran Marcet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2474,7 +2475,7 @@ class Commande extends CommonOrder */ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $fk_unit=null) { - global $conf, $mysoc; + global $conf, $mysoc, $langs; dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -2529,6 +2530,26 @@ class Commande extends CommonOrder $line = new OrderLine($this->db); $line->fetch($rowid); + if (!empty($line->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($line->fk_product); + $product_type=$product->type; + + if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER) && $product_type == 0 && $product->stock_reel < $qty) + { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + dol_syslog(get_class($this)."::addline error=Product ".$product->ref.": ".$this->error, LOG_ERR); + $this->db->rollback(); + unset($_POST['productid']); + unset($_POST['tva_tx']); + unset($_POST['price_ht']); + unset($_POST['qty']); + unset($_POST['buying_price']); + return self::STOCK_NOT_ENOUGH_FOR_ORDER; + } + } + $staticline = clone $line; $line->oldline = $staticline; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 333f71806c6..dc62189be87 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -14,6 +14,7 @@ * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Cedric Gross * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Ferran Marcet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2365,6 +2366,19 @@ class Facture extends CommonInvoice $line = new FactureLigne($this->db); $line->fetch($rowid); + if (!empty($line->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($line->fk_product); + $product_type=$product->type; + + if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } + } + $staticline = clone $line; $line->oldline = $staticline; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index af919f3ff7d..1312973be9a 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2267,10 +2267,10 @@ class Form $form.= $opt; $i++; } - $form.= ''; - - $this->db->free($result); } + + $form.= ''; + $this->db->free($result); return $form; } else diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 7dcf66d28ec..3237e178738 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -832,13 +832,19 @@ class Expedition extends CommonObject return -1; } - if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) // FIXME Check is done for stock of product, it must be done for stock of product into warehouse if $entrepot_id defined + if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { $product=new Product($this->db); $result=$product->fetch($fk_product); + if ($entrepot_id > 0) { + $product->load_stock(); + $product_stock = $product->stock_warehouse[$entrepot_id]->real; + } + else + $product_stock = $product->stock_reel; $product_type=$product->type; - if ($product_type == 0 && $product->stock_reel < $qty) + if ($product_type == 0 && $product_stock < $qty) { $this->error=$langs->trans('ErrorStockIsNotEnough'); $this->db->rollback();