FIX Can't create shipment for virtual product. Add
STOCK_EXCLUDE_VIRTUAL_PRODUCTS as a quick hack to solve this.
This commit is contained in:
parent
217aa9c420
commit
4ae121d870
@ -954,33 +954,36 @@ class Expedition extends CommonObject
|
|||||||
{
|
{
|
||||||
$fk_product = $orderline->fk_product;
|
$fk_product = $orderline->fk_product;
|
||||||
|
|
||||||
if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS))
|
if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) {
|
||||||
{
|
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
|
$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
|
if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
|
||||||
{
|
|
||||||
// Check must be done for stock of product into warehouse if $entrepot_id defined
|
|
||||||
$product = new Product($this->db);
|
$product = new Product($this->db);
|
||||||
$result = $product->fetch($fk_product);
|
$product->fetch($fk_product);
|
||||||
|
|
||||||
|
// Check must be done for stock of product into warehouse if $entrepot_id defined
|
||||||
if ($entrepot_id > 0) {
|
if ($entrepot_id > 0) {
|
||||||
$product->load_stock('warehouseopen');
|
$product->load_stock('warehouseopen');
|
||||||
$product_stock = $product->stock_warehouse[$entrepot_id]->real;
|
$product_stock = $product->stock_warehouse[$entrepot_id]->real;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
$product_stock = $product->stock_reel;
|
$product_stock = $product->stock_reel;
|
||||||
|
}
|
||||||
|
|
||||||
$product_type = $product->type;
|
$product_type = $product->type;
|
||||||
if ($product_type == 0 && $product_stock < $qty)
|
if ($product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||||
{
|
$isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
|
||||||
$langs->load("errors");
|
// The product is qualified for a check of quantity (must be enough in stock to be added into shipment).
|
||||||
$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
|
if (!$isavirtualproduct || empty($conf->global->PRODUIT_SOUSPRODUITS) || ($isavirtualproduct && empty($conf->global->STOCK_EXCLUDE_VIRTUAL_PRODUCTS))) { // If STOCK_EXCLUDE_VIRTUAL_PRODUCTS is set, we do not manage stock for kits/virtual products.
|
||||||
$this->db->rollback();
|
if ($product_stock < $qty) {
|
||||||
return -3;
|
$langs->load("errors");
|
||||||
|
$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
|
||||||
|
$this->db->rollback();
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4208,29 +4208,36 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all parent products for current product (first level only)
|
* Count all parent and children products for current product (first level only)
|
||||||
*
|
*
|
||||||
* @return int Nb of father + child
|
* @param int $mode 0=Both parent and child, -1=Parents only, 1=Children only
|
||||||
|
* @return int Nb of father + child
|
||||||
|
* @see getFather(), get_sousproduits_arbo()
|
||||||
*/
|
*/
|
||||||
public function hasFatherOrChild()
|
public function hasFatherOrChild($mode = 0)
|
||||||
{
|
{
|
||||||
$nb = 0;
|
$nb = 0;
|
||||||
|
|
||||||
$sql = "SELECT COUNT(pa.rowid) as nb";
|
$sql = "SELECT COUNT(pa.rowid) as nb";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa";
|
||||||
$sql .= " WHERE pa.fk_product_fils = ".$this->id." OR pa.fk_product_pere = ".$this->id;
|
if ($mode == 0) {
|
||||||
$resql = $this->db->query($sql);
|
$sql .= " WHERE pa.fk_product_fils = ".$this->id." OR pa.fk_product_pere = ".$this->id;
|
||||||
if ($resql) {
|
} elseif ($mode == -1) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$sql .= " WHERE pa.fk_product_fils = ".$this->id; // We are a child, so we found lines that link to parents (can have several parents)
|
||||||
if ($obj) { $nb = $obj->nb;
|
} elseif ($mode == 1) {
|
||||||
}
|
$sql .= " WHERE pa.fk_product_pere = ".$this->id; // We are a parent, so we found lines that link to children (can have several children)
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $nb;
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql) {
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
if ($obj) { $nb = $obj->nb;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user