Skip to content

Commit

Permalink
FIX DA024318 : backport PR 27668
Browse files Browse the repository at this point in the history
  • Loading branch information
x committed Feb 12, 2024
1 parent f8992d8 commit 3eb8c45
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
1 change: 1 addition & 0 deletions ChangeLogTechPap.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- FIX : DA024318 - Backport PR 27668 : gestion de la donnée "stock virtuel par entrepôt" sur l'écran de réapprovisionnement - *12/02/2024*
- FIX : DA024269 - Multilangs ne fonctionne pas avec les pdfs propal et facture [Ce dev devrait être ajouté au standard en v17, ainsi, il sera à supprimer lors de la MDV : PR 27159] - *19/12/2023*
- FIX : DA023477 - Liens hypertext ne fonctionnent pas [Ce dev a été ajouté au standard en develop (pour V19), ainsi, il sera à supprimer lors de la MDV] - v17 - *18/07/2023*
- FIX : DA023556 - Date de création non-fonctionnelle pour les numéros de lot/série [Ce dev a été ajouté au standard en develop (pour V19), ainsi, il sera à supprimer lors de la MDV] - v17 - *18/07/2023*
Expand Down
90 changes: 71 additions & 19 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3350,9 +3350,10 @@ public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtual
* @param string $filtrestatut Id statut pour filtrer sur un statut
* @param int $forVirtualStock Ignore rights filter for virtual stock calculation.
* @param int $dateofvirtualstock Date of virtual stock
* @param int $warehouseid Filter by a warehouse (BACKPORT STANDARD PR27668)
* @return integer Array of stats in $this->stats_mrptoproduce (nb=nb of order, qty=qty ordered), <0 if ko or >0 if ok
*/
public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null)
public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null, $warehouseid = 0)
{
// phpcs:enable
global $conf, $user, $hookmanager, $action;
Expand Down Expand Up @@ -3380,16 +3381,27 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt
if (!empty($dateofvirtualstock)) {
$sql .= " AND m.date_valid <= '".$this->db->idate($dateofvirtualstock)."'"; // better date to code ? end of production ?
}
/** DEB : BACKPORT STANDARD PR27668 **/
if (!empty($warehouseid)) {
$sql.= " AND m.fk_warehouse = ".((int) $warehouseid);
}
/** FIN : BACKPORT STANDARD PR27668 **/
$sql .= " GROUP BY role";

$this->stats_mrptoconsume['customers'] = 0;
$this->stats_mrptoconsume['nb'] = 0;
$this->stats_mrptoconsume['rows'] = 0;
$this->stats_mrptoconsume['qty'] = 0;
$this->stats_mrptoproduce['customers'] = 0;
$this->stats_mrptoproduce['nb'] = 0;
$this->stats_mrptoproduce['rows'] = 0;
$this->stats_mrptoproduce['qty'] = 0;
/** DEB : BACKPORT STANDARD PR27668 **/
if ($warehouseid) {
$this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] = 0;
} else {
$this->stats_mrptoconsume['customers'] = 0;
$this->stats_mrptoconsume['nb'] = 0;
$this->stats_mrptoconsume['rows'] = 0;
$this->stats_mrptoconsume['qty'] = 0;
$this->stats_mrptoproduce['customers'] = 0;
$this->stats_mrptoproduce['nb'] = 0;
$this->stats_mrptoproduce['rows'] = 0;
$this->stats_mrptoproduce['qty'] = 0;
}
/** FIN : BACKPORT STANDARD PR27668 **/

$result = $this->db->query($sql);
if ($result) {
Expand All @@ -3407,26 +3419,46 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt
$this->stats_mrptoconsume['qty'] -= ($obj->qty ? $obj->qty : 0);
}
if ($obj->role == 'toproduce') {
$this->stats_mrptoproduce['customers'] += $obj->nb_customers;
$this->stats_mrptoproduce['nb'] += $obj->nb;
$this->stats_mrptoproduce['rows'] += $obj->nb_rows;
$this->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0);
/** DEB : BACKPORT STANDARD PR27668 **/
if ($warehouseid) {
$this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0);
} else {
$this->stats_mrptoproduce['customers'] += $obj->nb_customers;
$this->stats_mrptoproduce['nb'] += $obj->nb;
$this->stats_mrptoproduce['rows'] += $obj->nb_rows;
$this->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0);
}
/** FIN : BACKPORT STANDARD PR27668 **/
}
if ($obj->role == 'produced') {
//$this->stats_mrptoproduce['customers'] += $obj->nb_customers;
//$this->stats_mrptoproduce['nb'] += $obj->nb;
//$this->stats_mrptoproduce['rows'] += $obj->nb_rows;
$this->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0);
/** DEB : BACKPORT STANDARD PR27668 **/
if ($warehouseid) {
$this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0);
} else {
$this->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0);
}
/** FIN : BACKPORT STANDARD PR27668 **/
}
}

// Clean data
if ($this->stats_mrptoconsume['qty'] < 0) {
$this->stats_mrptoconsume['qty'] = 0;
}
if ($this->stats_mrptoproduce['qty'] < 0) {
$this->stats_mrptoproduce['qty'] = 0;
/** DEB : BACKPORT STANDARD PR27668 **/
if ($warehouseid) {
if ($this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] < 0) {
$this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] = 0;
}
} else {
if ($this->stats_mrptoconsume['qty'] < 0) {
$this->stats_mrptoconsume['qty'] = 0;
}
if ($this->stats_mrptoproduce['qty'] < 0) {
$this->stats_mrptoproduce['qty'] = 0;
}
}
/** FIN : BACKPORT STANDARD PR27668 **/

$parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock);
$reshook = $hookmanager->executeHooks('loadStatsInProduction', $parameters, $this, $action);
Expand Down Expand Up @@ -5650,6 +5682,26 @@ public function load_virtual_stock($includedraftpoforvirtual = null, $dateofvirt
$this->stock_theorique = $hookmanager->resArray['stock_theorique'];
}

/** DEB : BACKPORT STANDARD PR27668 **/
//Virtual Stock by Warehouse
if (!empty($this->stock_warehouse) && getDolGlobalString('STOCK_ALLOW_VIRTUAL_STOCK_PER_WAREHOUSE')) {
foreach ($this->stock_warehouse as $warehouseid => $stockwarehouse) {
if (isModEnabled('mrp')) {
$result = $this->load_stats_inproduction(0, '1,2', 1, $dateofvirtualstock, $warehouseid);
if ($result < 0) {
dol_print_error($this->db, $this->error);
}
}

if ($this->fk_default_warehouse == $warehouseid) {
$this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] + $this->stats_commande_fournisseur['qty'] - ($this->stats_commande['qty'] + $this->stats_mrptoconsume['qty']);
} else {
$this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'];
}
}
}
/** FIN : BACKPORT STANDARD PR27668 **/

return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion htdocs/product/stock/replenish.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,11 @@
if ($usevirtualstock) {
// If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock.
$stock = $prod->stock_theorique;
//TODO $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->;
/** DEB : BACKPORT STANDARD PR27668 **/
if (getDolGlobalString('STOCK_ALLOW_VIRTUAL_STOCK_PER_WAREHOUSE')) {
$stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->virtual;
}
/** FIN : BACKPORT STANDARD PR27668 **/
} else {
$stock = $prod->stock_reel;
$stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->real;
Expand Down

0 comments on commit 3eb8c45

Please sign in to comment.