diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 47efd560c4a..dd784b53419 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -4511,7 +4511,7 @@ if ($action == 'create') {
$file = GETPOST('file', 'alpha');
$formconfirm = $form->formconfirm(
- $_SERVER["PHP_SELF"].'?facid='.$object->id.'&file='.$file,
+ $_SERVER["PHP_SELF"].'?facid='.$object->id.'&file='.urlencode($file),
$langs->trans('DeleteFileHeader'),
$langs->trans('DeleteFileText')."
".$file,
'remove_file',
diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php
index 48e4a1defa2..bb3f6ae561e 100644
--- a/htdocs/core/modules/import/import_csv.modules.php
+++ b/htdocs/core/modules/import/import_csv.modules.php
@@ -965,7 +965,7 @@ class ImportCsv extends ModeleImports
foreach ($data as $key => $val) {
$set[] = $key." = ".$val;
}
- $sqlstart .= " SET ".implode(', ', $set);
+ $sqlstart .= " SET ".implode(', ', $set).", import_key = '".$this->db->escape($importid)."'";
if (empty($keyfield)) {
$keyfield = 'rowid';
diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php
index 740603b836e..5e9ca592a0c 100644
--- a/htdocs/core/modules/import/import_xlsx.modules.php
+++ b/htdocs/core/modules/import/import_xlsx.modules.php
@@ -1006,7 +1006,7 @@ class ImportXlsx extends ModeleImports
foreach ($data as $key => $val) {
$set[] = $key." = ".$val;
}
- $sqlstart .= " SET " . implode(', ', $set);
+ $sqlstart .= " SET " . implode(', ', $set) . ", import_key = '" . $this->db->escape($importid) . "'";
if (empty($keyfield)) {
$keyfield = 'rowid';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index feb1dde19ce..28d9e7a1ce8 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -3535,6 +3535,8 @@ class Product extends CommonObject
// 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";
@@ -3546,6 +3548,7 @@ class Product extends CommonObject
$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') && !$forVirtualStock) {
$sql .= " AND m.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
}
@@ -3558,6 +3561,9 @@ class Product extends CommonObject
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 (0))";
+ }
if (!empty($warehouseid)) {
$sql.= " AND m.fk_warehouse = ".((int) $warehouseid);
}