FIX add product qty in shipment already sent only if reel stock was decremented

This commit is contained in:
VESSILLER 2019-11-14 09:52:13 +01:00
parent 95a6d7f8f5
commit 851cf4f3f3
3 changed files with 24 additions and 8 deletions

View File

@ -92,7 +92,7 @@ $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$extrafields->fetch_name_optionals_label($object->table_element_line);
$extrafields->fetch_name_optionals_label(OrderLine::$table_element);
//$extrafields->fetch_name_optionals_label(OrderLine::$table_element);
// Load object. Make an object->fetch
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once

View File

@ -2684,12 +2684,13 @@ class Product extends CommonObject
/**
* Charge tableau des stats expedition client pour le produit/service
*
* @param int $socid Id societe pour filtrer sur une societe
* @param string $filtrestatut Id statut pour filtrer sur un statut
* @param int $forVirtualStock Ignore rights filter for virtual stock calculation.
* @return array Tableau des stats
* @param int $socid Id societe pour filtrer sur une societe
* @param string $filtrestatut Id statut pour filtrer sur un statut
* @param int $forVirtualStock Ignore rights filter for virtual stock calculation.
* @param string $filterShipmentStatus [=''] Ids shipment status separated by comma
* @return int <0 if KO, >0 if OK (Tableau des stats)
*/
public function load_stats_sending($socid = 0, $filtrestatut = '', $forVirtualStock = 0)
public function load_stats_sending($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $filterShipmentStatus = '')
{
// phpcs:enable
global $conf,$user;
@ -2719,6 +2720,7 @@ class Product extends CommonObject
if ($filtrestatut <> '') {
$sql.= " AND c.fk_statut in (".$filtrestatut.")";
}
if (!empty($filterShipmentStatus)) $sql.= " AND e.fk_statut IN (" . $filterShipmentStatus . ")";
$result = $this->db->query($sql);
if ($result ) {
@ -4680,7 +4682,14 @@ class Product extends CommonObject
}
if (!empty($conf->expedition->enabled))
{
$result = $this->load_stats_sending(0, '1,2', 1);
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
$filterShipmentStatus = '';
if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
$filterShipmentStatus = Expedition::STATUS_VALIDATED . ',' . Expedition::STATUS_CLOSED;
} elseif (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
$filterShipmentStatus = Expedition::STATUS_CLOSED;
}
$result = $this->load_stats_sending(0, '1,2', 1, $filterShipmentStatus);
if ($result < 0) dol_print_error($this->db, $this->error);
$stock_sending_client = $this->stats_expedition['qty'];
}

View File

@ -661,8 +661,15 @@ if ($id > 0 || $ref)
// Number of product from customer order already sent (partial shipping)
if (!empty($conf->expedition->enabled)) {
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
$filterShipmentStatus = '';
if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
$filterShipmentStatus = Expedition::STATUS_VALIDATED . ',' . Expedition::STATUS_CLOSED;
} elseif (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
$filterShipmentStatus = Expedition::STATUS_CLOSED;
}
if ($found) $helpondiff .= '<br>'; else $found = 1;
$result = $object->load_stats_sending(0, '2', 1);
$result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus);
$helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty'];
}