Skip to content

Commit

Permalink
Merge branch '21.0' of git@github.com:Dolibarr/dolibarr.git into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 7, 2025
2 parents c3f0605 + 43e054d commit badb236
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);

$notify = new Notify($this->db);
$notify->send($action, $object);
$resultSend = $notify->send($action, $object);
if ($resultSend < 0) {
$this->errors = array_merge($this->errors, $notify->errors);
return $resultSend;
}

return 1;
}
Expand Down
32 changes: 25 additions & 7 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3571,7 +3571,7 @@ public function load_stats_commande($socid = 0, $filtrestatut = '', $forVirtualS
$sql .= " AND c.fk_soc = ".((int) $socid);
}
if ($filtrestatut != '') {
$sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")";
$sql .= " AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).")";
}

$result = $this->db->query($sql);
Expand Down Expand Up @@ -3604,7 +3604,7 @@ public function load_stats_commande($socid = 0, $filtrestatut = '', $forVirtualS
}

// If stock decrease is on invoice validation, the theoretical stock continue to
// count the orders to ship in theoretical stock when some are already removed by invoice validation.
// count the orders lines in theoretical stock when some are already removed by invoice validation.
if ($forVirtualStock && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
if (getDolGlobalString('DECREASE_ONLY_UNINVOICEDPRODUCTS')) {
// If option DECREASE_ONLY_UNINVOICEDPRODUCTS is on, we make a compensation but only if order not yet invoice.
Expand Down Expand Up @@ -6296,22 +6296,40 @@ public function load_virtual_stock($includedraftpoforvirtual = null, $dateofvirt

$this->stock_theorique = $this->stock_reel + $stock_inproduction;

// $weBillOrderOrShipmentReception is set to 'order' or 'shipmentreception'. it will be used to know how to make virtual stock
// calculation when we have a stock increase or decrease on billing. Do we have to count orders to bill or shipment/reception to bill ?
$weBillOrderOrShipmentReception = getDolGlobalString('STOCK_DO_WE_BILL_ORDER_OR_SHIPMENTECEPTION_FOR_VIRTUALSTOCK', 'order');

// Stock decrease mode
if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
$this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER')) {
$this->stock_theorique += 0;
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
if (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER_INCLUDE_DRAFT')) { // By default, draft means "does not exist", so we do not include them by default, except if option is on
$tmpnewprod = dol_clone($this, 1);
$result = $tmpnewprod->load_stats_commande(0, '0', 1); // Get qty in draft orders
$this->stock_theorique += $tmpnewprod->stats_commande['qty'];
}
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_BILL') && $weBillOrderOrShipmentReception == 'order') {
$this->stock_theorique -= $stock_commande_client;
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_BILL') && $weBillOrderOrShipmentReception == 'shipmentreception') {
$this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
}

// Stock Increase mode
if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) { // This option is similar to STOCK_CALCULATE_ON_RECEPTION_CLOSE but when module Reception is not enabled
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) { // Warning: stock change "on approval", not on validation !
if (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER_INCLUDE_DRAFT')) { // By default, draft means "does not exist", so we do not include them by default, except if option is on
$tmpnewprod = dol_clone($this, 1);
$result = $tmpnewprod->load_stats_commande_fournisseur(0, '0', 1); // Get qty in draft orders
$this->stock_theorique += $this->stats_commande_fournisseur['qty'];
}
$this->stock_theorique -= $stock_reception_fournisseur;
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL')) {
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $weBillOrderOrShipmentReception == 'order') {
$this->stock_theorique += $stock_commande_fournisseur;
} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') && $weBillOrderOrShipmentReception == 'shipmentreception') {
$this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/stock/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@

$variants = $object->hasVariants();

$object->load_stock();
$object->load_stock(); // This include the load_virtual_stock()

$title = $langs->trans('ProductServiceCard');
$helpurl = '';
Expand Down

0 comments on commit badb236

Please sign in to comment.