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:
Laurent Destailleur 2020-11-16 19:43:45 +01:00
parent 217aa9c420
commit 4ae121d870
2 changed files with 42 additions and 32 deletions

View File

@ -954,33 +954,36 @@ class Expedition extends CommonObject
{
$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");
$this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine");
return -1;
}
if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT)
{
// Check 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);
$product->fetch($fk_product);
// Check must be done for stock of product into warehouse if $entrepot_id defined
if ($entrepot_id > 0) {
$product->load_stock('warehouseopen');
$product_stock = $product->stock_warehouse[$entrepot_id]->real;
}
else
} else {
$product_stock = $product->stock_reel;
}
$product_type = $product->type;
if ($product_type == 0 && $product_stock < $qty)
{
$langs->load("errors");
$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
$this->db->rollback();
return -3;
if ($product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$isavirtualproduct = ($product->hasFatherOrChild(1) > 0);
// The product is qualified for a check of quantity (must be enough in stock to be added into shipment).
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.
if ($product_stock < $qty) {
$langs->load("errors");
$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref);
$this->db->rollback();
return -3;
}
}
}
}
}

View File

@ -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 .= " FROM ".MAIN_DB_PREFIX."product_association as pa";
$sql .= " WHERE pa.fk_product_fils = ".$this->id." OR pa.fk_product_pere = ".$this->id;
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) { $nb = $obj->nb;
}
}
else
{
return -1;
}
$sql = "SELECT COUNT(pa.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa";
if ($mode == 0) {
$sql .= " WHERE pa.fk_product_fils = ".$this->id." OR pa.fk_product_pere = ".$this->id;
} elseif ($mode == -1) {
$sql .= " WHERE pa.fk_product_fils = ".$this->id; // We are a child, so we found lines that link to parents (can have several parents)
} 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)
}
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;
}
/**