Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Count of virtual stock at Services and MoLine with disabled stock change #28580

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix the count of virtual stock
  • Loading branch information
christian.humpel committed Mar 2, 2024
commit a8f894392e15b3d6cc529b4079c2aea956ee1737
6 changes: 6 additions & 0 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,8 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt
// phpcs:enable
global $conf, $user, $hookmanager, $action;

$serviceStockIsEnabled = isModEnabled("service") && getDolGlobalString('STOCK_SUPPORTS_SERVICES');

$sql = "SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,";
$sql .= " COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role";
$sql .= " FROM ".$this->db->prefix()."mrp_production as mp";
Expand All @@ -3480,6 +3482,7 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt
$sql .= " WHERE m.rowid = mp.fk_mo";
$sql .= " AND m.entity IN (".getEntity($forVirtualStock && getDolGlobalString('STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ? 'stock' : 'mrp').")";
$sql .= " AND mp.fk_product = ".((int) $this->id);
$sql .= " AND mp.disable_stock_change IN (0)";
if (!$user->hasRight('societe', 'client', 'voir') && !$socid && !$forVirtualStock) {
$sql .= " AND m.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
Expand All @@ -3492,6 +3495,9 @@ 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 ?
}
if (!$serviceStockIsEnabled) {
$sql .= "AND EXISTS (SELECT p.rowid FROM ".$this->db->prefix()."product AS p WHERE p.rowid = ".((int) $this->id)." AND p.fk_product_type IN (".$this::TYPE_PRODUCT."))";
}
$sql .= " GROUP BY role";

$this->stats_mrptoconsume['customers'] = 0;
Expand Down
Loading