From ef94452f77fc7eca3ac58caea35bd76168dd1af5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Apr 2026 01:01:37 +0200 Subject: [PATCH 1/5] Doc --- htdocs/product/class/product.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f6bcc80633b..a36a9b931a4 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1492,8 +1492,9 @@ class Product extends CommonObject if ($result >= 0) { // $this->oldcopy should have been set by the caller of update (here properties were already modified) - if (is_null($this->oldcopy) || (is_object($this->oldcopy) && $this->oldcopy->isEmpty())) { - $this->oldcopy = dol_clone($this, 1); // 1 to clone with methods to avoid fatal error with $this->oldcopy->hasbatch() + // Note that this->oldcopy must be object and not stdClass, if not the method hasbatch() will not work. + if (is_null($this->oldcopy) || (is_object($this->oldcopy) && empty($this->oldcopy->id))) { + $this->oldcopy = dol_clone($this, 1); // 1 to clone with methods to avoid fatal error with $this->oldcopy->hasbatch() } // Test if batch management is activated on existing product // If yes, we create missing entries into product_batch @@ -6859,9 +6860,9 @@ class Product extends CommonObject } /** - * Return if the object has a sell-by or eat-by date. + * Return if the object has a batch management. * - * @return boolean True if the object has a sell-by or eat-by date, false otherwise. + * @return boolean True if the object has a batch management, false otherwise. */ public function hasbatch() { From b45717ea4258b5afe0d87b24a45af825ad8ec85c Mon Sep 17 00:00:00 2001 From: Dylan Bourdere Date: Wed, 8 Apr 2026 01:46:53 +0200 Subject: [PATCH 2/5] Fix clone on price (#37777) * fix price * Update price.php * Fix comment typo in price.php --------- Co-authored-by: Laurent Destailleur --- htdocs/product/price.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 95e3450a82f..cb706689841 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -288,7 +288,7 @@ if (empty($reshook)) { if (($action == 'update_price' || $action == 'update_level_price') && !$cancel && $permissiontoadd) { $error = 0; $pricestoupdate = array(); - $object->oldcopy = dol_clone($object, 2); + $object->oldcopy = dol_clone($object, 1); // when calling ->update later we need to call method on ->oldcopy so we clone using param 1 $psq = GETPOSTINT('psqflag'); From efa50e58b233c0eed9a2f8b2ecd4865e386b60b9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Apr 2026 21:27:27 +0200 Subject: [PATCH 3/5] Fix bind sql - credit Chris Oakley --- htdocs/expedition/class/expedition.class.php | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 4896d1c0890..f10f7637b3a 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -483,21 +483,21 @@ class Expedition extends CommonObject $sql .= ", ".($this->date_delivery > 0 ? "'".$this->db->idate($this->date_delivery)."'" : "null"); $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : "null"); $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null"); - $sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null"); + $sql .= ", ".($this->fk_delivery_address > 0 ? ((int) $this->fk_delivery_address) : "null"); $sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null"); $sql .= ", '".$this->db->escape($this->tracking_number)."'"; - $sql .= ", ".(is_numeric($this->weight) ? $this->weight : 'NULL'); - $sql .= ", ".(is_numeric($this->sizeS) ? $this->sizeS : 'NULL'); // TODO Should use this->trueDepth - $sql .= ", ".(is_numeric($this->sizeW) ? $this->sizeW : 'NULL'); // TODO Should use this->trueWidth - $sql .= ", ".(is_numeric($this->sizeH) ? $this->sizeH : 'NULL'); // TODO Should use this->trueHeight + $sql .= ", ".(is_numeric($this->weight) ? (float) $this->weight : 'NULL'); + $sql .= ", ".(is_numeric($this->sizeS) ? (float) $this->sizeS : 'NULL'); // TODO Should use this->trueDepth + $sql .= ", ".(is_numeric($this->sizeW) ? (float) $this->sizeW : 'NULL'); // TODO Should use this->trueWidth + $sql .= ", ".(is_numeric($this->sizeH) ? (float) $this->sizeH : 'NULL'); // TODO Should use this->trueHeight $sql .= ", ".($this->weight_units != '' ? (int) $this->weight_units : 'NULL'); $sql .= ", ".($this->size_units != '' ? (int) $this->size_units : 'NULL'); $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); $sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null"); $sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null"); - $sql .= ", ".(int) $this->fk_incoterms; + $sql .= ", ".((int) $this->fk_incoterms); $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql .= ", ".($this->signed_status); + $sql .= ", ".((int) $this->signed_status); $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -1327,6 +1327,7 @@ class Expedition extends CommonObject $this->line->element_type = $element_type; $this->line->fk_product = $fk_product; $this->line->description = $description; + $this->line->desc = $description; $this->line->fk_parent = $fk_parent; $this->line->qty = (float) $qty; $this->line->fk_unit = $fk_unit; @@ -1614,24 +1615,24 @@ class Expedition extends CommonObject $sql .= " ref = ".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; $sql .= " ref_ext = ".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; $sql .= " ref_customer = ".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").","; - $sql .= " fk_soc = ".(isset($this->socid) ? $this->socid : "null").","; + $sql .= " fk_soc = ".(isset($this->socid) ? ((int) $this->socid) : "null").","; $sql .= " date_creation = ".(dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').","; - $sql .= " fk_user_author = ".(isset($this->fk_user_author) ? $this->fk_user_author : "null").","; + $sql .= " fk_user_author = ".(isset($this->fk_user_author) ? ((int) $this->fk_user_author) : "null").","; $sql .= " date_valid = ".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').","; - $sql .= " fk_user_valid = ".(isset($this->fk_user_valid) ? $this->fk_user_valid : "null").","; + $sql .= " fk_user_valid = ".(isset($this->fk_user_valid) ? ((int) $this->fk_user_valid) : "null").","; $sql .= " date_expedition = ".(dol_strlen($this->date_shipping) != 0 ? "'".$this->db->idate($this->date_shipping)."'" : 'null').","; $sql .= " date_delivery = ".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').","; - $sql .= " fk_address = ".(isset($this->fk_delivery_address) ? $this->fk_delivery_address : "null").","; - $sql .= " fk_shipping_method = ".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id : "null").","; + $sql .= " fk_address = ".(isset($this->fk_delivery_address) ? ((int) $this->fk_delivery_address) : "null").","; + $sql .= " fk_shipping_method = ".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? ((int) $this->shipping_method_id) : "null").","; $sql .= " tracking_number = ".(isset($this->tracking_number) ? "'".$this->db->escape($this->tracking_number)."'" : "null").","; - $sql .= " fk_statut = ".(isset($this->status) ? $this->status : "null").","; - $sql .= " fk_projet = ".(isset($this->fk_project) ? $this->fk_project : "null").","; - $sql .= " height = ".(($this->trueHeight != '') ? $this->trueHeight : "null").","; - $sql .= " width = ".(($this->trueWidth != '') ? $this->trueWidth : "null").","; - $sql .= " size_units = ".(isset($this->size_units) ? $this->size_units : "null").","; - $sql .= " size = ".(($this->trueDepth != '') ? $this->trueDepth : "null").","; - $sql .= " weight_units = ".(isset($this->weight_units) ? $this->weight_units : "null").","; - $sql .= " weight = ".(($this->trueWeight != '') ? $this->trueWeight : "null").","; + $sql .= " fk_statut = ".(isset($this->status) ? ((int) $this->status) : "null").","; + $sql .= " fk_projet = ".(isset($this->fk_project) ? ((int) $this->fk_project) : "null").","; + $sql .= " height = ".(($this->trueHeight != '') ? ((float) $this->trueHeight) : "null").","; + $sql .= " width = ".(($this->trueWidth != '') ? ((float) $this->trueWidth) : "null").","; + $sql .= " size_units = ".(isset($this->size_units) ? ((int) $this->size_units) : "null").","; + $sql .= " size = ".(($this->trueDepth != '') ? ((float) $this->trueDepth) : "null").","; + $sql .= " weight_units = ".(isset($this->weight_units) ? ((int) $this->weight_units) : "null").","; + $sql .= " weight = ".(($this->trueWeight != '') ? ((float) $this->trueWeight) : "null").","; $sql .= " note_private = ".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; $sql .= " note_public = ".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; $sql .= " model_pdf = ".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; From 1a1dcc176c8967f83af5f0ca5decb3156b32f956 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 8 Apr 2026 21:39:41 +0200 Subject: [PATCH 4/5] Add a protection for int var fk_... --- htdocs/api/class/api.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 68d93a24c61..790c00a1772 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -126,6 +126,12 @@ class DolibarrApi // Others will use 'alphanohtml' } + // In case of a field with unknown type (legacy code), we use its name to have a chance to sanitize it + if (preg_match('/^fk_/i', $field)) { + // We accept only integer + return sanitizeVal($value, 'int'); + } + if (in_array($field, array('note', 'note_private', 'note_public', 'desc', 'description'))) { return sanitizeVal($value, 'restricthtml'); } else { From 815a86475363220170e0add85d8c361da54d23da Mon Sep 17 00:00:00 2001 From: Zakaria Boushaba <48571684+Boushabazakaria@users.noreply.github.com> Date: Wed, 8 Apr 2026 20:43:26 +0100 Subject: [PATCH 5/5] fix(facture): do not mark deposit as paid when DEPOSIT_AS_CREDIT_AVAILABLE_EVEN_UNPAID is set and no payment received (#37778) Co-authored-by: Zakaria Boushaba --- htdocs/compta/facture/card.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 2f231ec3131..f3535de1d66 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1137,14 +1137,23 @@ if (empty($reshook)) { } if (empty($error)) { - // Set invoice as paid - $result = $object->setPaid($user); // We can close the invoice. Even if we got an excess received, it is now into discounts. - if ($result >= 0) { - $object->fetch($object->id); // Reload properties + // Set invoice as paid, unless it's a deposit converted to credit without any payment received + // (option DEPOSIT_AS_CREDIT_AVAILABLE_EVEN_UNPAID allows creating the discount/credit even if the deposit + // has not been paid yet; in that case we must NOT mark it as paid since no payment was actually received) + $skipSetPaid = ($object->type == Facture::TYPE_DEPOSIT && getDolGlobalInt('DEPOSIT_AS_CREDIT_AVAILABLE_EVEN_UNPAID') && price2num($object->getSommePaiement(), 'MT') == 0); + + if ($skipSetPaid) { + $object->fetch($object->id); // Reload properties $db->commit(); } else { - setEventMessages($object->error, $object->errors, 'errors'); - $db->rollback(); + $result = $object->setPaid($user); // We can close the invoice. Even if we got an excess received, it is now into discounts. + if ($result >= 0) { + $object->fetch($object->id); // Reload properties + $db->commit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $db->rollback(); + } } } else { setEventMessages($discount->error, $discount->errors, 'errors');