From 6871e041a63bc506b2b5f0b4eec5ed9abab99c04 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Thu, 21 May 2026 22:17:40 +0200 Subject: [PATCH 01/33] FIX #32086 Notifications for Interventions ignores the email template (#38366) When saving an email template using /admin/mails_templates.php and selecting interventions as the type of template, it inserted fichinter in the database. But when looking for templates it tried to find ficheinter - with an extra e. The result was that it did not find anything, and this did not use the template at all. Co-authored-by: Jon Bendtsen --- htdocs/core/class/notify.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 89bf13da263..88b85f4cbef 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -825,26 +825,26 @@ class Notify case 'FICHINTER_ADD_CONTACT': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); break; case 'FICHINTER_VALIDATE': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); break; case 'FICHINTER_MODIFY': $link = ''.$newref.''; $context_info = array_key_exists('signature', $object->context) ? $object->getLibSignedStatus() : ''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionModified", $link, $context_info); break; case 'FICHINTER_CLOSE': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); break; case 'ORDER_SUPPLIER_VALIDATE': @@ -1150,26 +1150,26 @@ class Notify case 'FICHINTER_ADD_CONTACT': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); break; case 'FICHINTER_VALIDATE': $link = ''.$newref.''; $dir_output = $conf->facture->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); break; case 'FICHINTER_MODIFY': $link = ''.$newref.''; $context_info = array_key_exists('signature', $object->context) ? $object->getLibSignedStatus() : ''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionModified", $link, $context_info); break; case 'FICHINTER_CLOSE': $link = ''.$newref.''; $dir_output = $conf->facture->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); break; case 'ORDER_SUPPLIER_CANCEL': From 04a0c8147b6893420483e7922ba45dfa50462f06 Mon Sep 17 00:00:00 2001 From: atm-jonathan <146709163+atm-jonathan@users.noreply.github.com> Date: Thu, 21 May 2026 22:18:34 +0200 Subject: [PATCH 02/33] FIX - API - PUT/DELETE categories on thirdparties/contacts always returns 403 (#38354) * rename resource * only recognises the internal French name * revet params --- htdocs/core/lib/security.lib.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 92e5070bd6a..4fd9c5a37d5 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -886,6 +886,9 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl if ($feature == 'member') { $feature = 'adherent'; } + if ($feature == 'category') { + $feature = 'categorie'; + } if ($feature == 'project') { $feature = 'projet'; } From aef6a55ac192f230e857dda6cd3255541b348d6c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 22 May 2026 14:09:09 +0200 Subject: [PATCH 03/33] FIX API key cannot be cleared/revoked from user card (#38283) * FIX API key cannot be cleared/revoked from user card * Better fix --- htdocs/user/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 499ef4845c4..24630e87cf8 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -440,7 +440,7 @@ if (empty($reshook)) { $object->pass = GETPOST("password", 'none'); // We can keep 'none' for password fields } if ($caneditpasswordandsee || $user->hasRight("api", "apikey", "generate")) { - $object->api_key = (GETPOST("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key; + $object->api_key = (GETPOSTISSET("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key; } if (!empty($user->admin) && $user->id != $id) { // admin flag can only be set/unset by an admin user and not four ourself From b344aa66eba133878e4f33664296b63469e9ff7e Mon Sep 17 00:00:00 2001 From: ThomasNgr-OpenDSI Date: Fri, 22 May 2026 21:41:49 +0200 Subject: [PATCH 04/33] FIX : cost price is not correctly computed when line->qty is < to 0 (#38268) --- htdocs/core/class/html.formmargin.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formmargin.class.php b/htdocs/core/class/html.formmargin.class.php index 02972f39630..1b265fd8bab 100644 --- a/htdocs/core/class/html.formmargin.class.php +++ b/htdocs/core/class/html.formmargin.class.php @@ -98,7 +98,7 @@ class FormMargin } $pv = $line->total_ht; - $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign + $pa_ht = (($pv < 0 && $line->qty > 0) ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign if (($object->element == 'facture' && $object->type == $object::TYPE_SITUATION) || ($object->element == 'facture' && $object->type == $object::TYPE_CREDIT_NOTE && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE && $object->situation_counter > 0)) { $pa = $line->qty * $pa_ht * ($line->situation_percent / 100); From fc530bad9d9ca4692287a56dbee1454a0db26106 Mon Sep 17 00:00:00 2001 From: atm-lucas <121817516+atm-lucasmantegari@users.noreply.github.com> Date: Fri, 22 May 2026 21:52:50 +0200 Subject: [PATCH 05/33] Fix supplier order PDF language not using thirdparty default_lang (#38216) --- htdocs/fourn/commande/card.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index b217c7f7870..d568cc3b30b 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1950,6 +1950,9 @@ if ($action == 'create') { $result = $object->fetch($id, $ref); $object->fetch_thirdparty(); + $soc = new Societe($db); + $soc->fetch($object->socid); + $societe = $object->thirdparty; $author = new User($db); @@ -2794,7 +2797,7 @@ if ($action == 'create') { $delallowed = $usercancreate; $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (!getDolGlobalString('COMMANDE_SUPPLIER_ADDON_PDF') ? '' : $conf->global->COMMANDE_SUPPLIER_ADDON_PDF)); - print $formfile->showdocuments('commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0, '', '', '', $object->thirdparty->default_lang, '', $object); + print $formfile->showdocuments('commande_fournisseur', $objref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 0, 0, '', '', '', $soc->default_lang, '', $object); $somethingshown = $formfile->numoffiles; // Show links to link elements From 88ad132763be45e9620128c1830e41493e1cdd05 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 May 2026 01:06:32 +0200 Subject: [PATCH 06/33] Clean code --- dev/build/makepack-dolibarr.pl | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/build/makepack-dolibarr.pl b/dev/build/makepack-dolibarr.pl index 1cf4d5355c8..fbe83f7f00b 100755 --- a/dev/build/makepack-dolibarr.pl +++ b/dev/build/makepack-dolibarr.pl @@ -243,8 +243,6 @@ if (! -e $SOURCE . "/htdocs/version.inc.php") { $PROJVERSION = $MAJORVERSION . "." . $MINORVERSION; } -print "xx".$PROJVERSION; - ( $MAJOR, $MINOR, $BUILD ) = split( /\./, $PROJVERSION, 3 ); if ( $MINOR eq '' ) { die "Error can't detect version"; } From b1d906d6d386a3d310bae9da4b279b5fbb3db727 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sat, 30 May 2026 21:53:26 +0700 Subject: [PATCH 07/33] Fix #37904 Honour subscription end-of-period setting in mass action (#38515) The "Create subscription" mass action on the members list called Adherent::subscription() with no $datesubend argument, which makes the method fall back to "+1 year" regardless of the MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH or MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR global settings. The single subscription form, the API and the public payment return all pass the value computed from these constants and therefore worked as expected. Compute the same end date from the two constants before the loop and forward it as the ninth argument of the method call. Two other callers already pass a value here, so the method signature stays unchanged. Reported by @Basti-Fantasti. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/adherents/list.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 5c18a3688d1..b672b27f6ee 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -363,11 +363,22 @@ if (empty($reshook)) { $nbcreated = 0; $now = dol_now(); $amount = price2num(GETPOST('amount', 'alpha')); + // Honour MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH and + // MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR the same way as the + // single subscription form (adherents/subscription.php), otherwise + // the mass action falls back to a one-year duration in + // Adherent::subscription() and ignores the global setting. + $datesubend = 0; + if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y"), (int) dol_print_date($now, "%m")); + } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y")); + } $db->begin(); foreach ($toselect as $id) { $res = $tmpmember->fetch($id); if ($res > 0) { - $result = $tmpmember->subscription($now, $amount); + $result = $tmpmember->subscription($now, $amount, 0, '', '', '', '', '', $datesubend); if ($result < 0) { $error++; } else { From b6aaa71a3b8b5b1265ebc2a04796afe41d3a8a62 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sat, 30 May 2026 21:54:11 +0700 Subject: [PATCH 08/33] Fix #37902 Preserve search_show_childproducts checkbox state (#38516) The "show variants" checkbox in the product list lost its state on every filter, sort or pagination submit. An HTML checkbox does not post anything when unchecked, so reading GETPOST() with no companion field made the value default to '' (falsy) as soon as the form was resubmitted, and the variants were hidden again even when the user wanted them. The URL-side propagation also stored the raw "on" string from a checked submit, which is brittle once the value ever comes back as an integer 0/1. Emit a hidden "search_show_childproducts=0" companion before the checkbox so the form always carries the flag, use GETPOSTISSET()/GETPOSTINT() to read it as a strict 0/1, reset it to 0 (not the empty string) when clearing filters, and stop guarding the URL append with a value that has just been confirmed truthy. Same code on 21.0, 22.0, 23.0 and develop; PR targets 21.0. Reported and root cause pinpointed by @daxitsolutions. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/product/list.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index e1eed666587..9d4dbb3f716 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -126,7 +126,14 @@ $type = GETPOST("type", 'alpha'); // Show/hide child product variants $show_childproducts = 0; if (isModEnabled('variants')) { - $show_childproducts = GETPOST('search_show_childproducts'); + // An HTML checkbox does not submit anything when unchecked, so a hidden + // "search_show_childproducts=0" companion field is emitted next to the + // checkbox (see below). GETPOSTISSET() then lets us distinguish a + // resubmission with the checkbox off from a request that does not carry + // the filter at all, and the value is read as a strict 0/1 flag. + if (GETPOSTISSET('search_show_childproducts')) { + $show_childproducts = GETPOSTINT('search_show_childproducts'); + } } $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id; @@ -383,7 +390,7 @@ if (empty($reshook)) { $search_finished = ''; //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type. - $show_childproducts = ''; + $show_childproducts = 0; $search_import_key = ''; $search_accountancy_code_sell = ''; $search_accountancy_code_sell_intra = ''; @@ -829,7 +836,7 @@ if ($fourn_id > 0) { $param .= "&fourn_id=".urlencode((string) ($fourn_id)); } if ($show_childproducts) { - $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); + $param .= "&search_show_childproducts=".urlencode((string) $show_childproducts); } if ($type != '') { $param .= '&type='.urlencode((string) ($type)); @@ -979,7 +986,11 @@ if (isModEnabled('category') && $user->hasRight('categorie', 'read')) { // Show/hide child variant products if (isModEnabled('variants')) { $moreforfilter .= '
'; - $moreforfilter .= ''; + // Companion hidden field ensures search_show_childproducts is always + // posted, even when the checkbox below is unchecked, so the unchecked + // state survives the filter/pagination submit and is parsed as 0/1. + $moreforfilter .= ''; + $moreforfilter .= ''; $moreforfilter .= ' '; $moreforfilter .= '
'; } From 2f3c8f4e40d5676038266a230ebe7f791c6b2ee7 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 03:39:57 +0700 Subject: [PATCH 09/33] Fix #35593 use acceptLocalLinktoMedia in mailing editor (#38525) Since v21 the wysiwyg editor in comm/mailing/card.php was created with $uselocalbrowser=-1, which DolEditor maps to the hidden constant WYSIWYG_ALLOW_UPLOAD_MEDIA_FILES (default 0). The local image browser that was available before v21 disappears for any installation that does not explicitly set that constant. The email templates editor at admin/mails_templates.php solves this with the dedicated helper acceptLocalLinktoMedia() (also gated on MAIN_DISALLOW_MEDIAS_IN_EMAIL_TEMPLATES, plus an IP allowlist for private networks). The two editors are intended to behave the same way (maintainer comment on the issue thread). Mirror that pattern in the mailing page: compute $acceptlocallinktomedia once near the top and pass it as the $uselocalbrowser argument to all five DolEditor instances. The default-deny behavior for installs exposed to the internet is preserved through acceptLocalLinktoMedia()'s own checks, and an existing local install on a private network gets the image browser back without having to set the hidden WYSIWYG_ALLOW_UPLOAD_MEDIA_FILES flag. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/comm/mailing/card.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 741c80cdfdd..36d83f091ed 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -761,6 +761,10 @@ if (empty($reshook)) { $form = new Form($db); $htmlother = new FormOther($db); +// Same check as the email templates editor in admin/mails_templates.php so the +// local media browser is shown consistently in both places. +$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0); + $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing'; llxHeader( '', @@ -894,7 +898,7 @@ if ($action == 'create') { // aaa print '
'; // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); + $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); $doleditor->Create(); print '
'; @@ -1334,7 +1338,7 @@ if ($action == 'create') { // aaa $readonly = 1; // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%', $readonly); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%', $readonly); $doleditor->Create(); } else { print dol_htmlentitiesbr($object->body); @@ -1553,19 +1557,19 @@ if ($action == 'create') { // aaa if ($action == 'edit') { // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); $doleditor->Create(); } if ($action == 'edittxt') { // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, 0, 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 0, 20, '100%'); $doleditor->Create(); } if ($action == 'edithtml') { // HTML source editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, 'ace', 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 'ace', 20, '100%'); $doleditor->Create(0, '', false, 'HTML Source', 'php'); } From 14de35577e0a6aab8765e5ec35d1194395b8a36a Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 03:40:37 +0700 Subject: [PATCH 10/33] Fix #38407 surface trigger error in task addTimeSpent / updateTimeSpent (#38524) When a trigger handler on TASK_TIMESPENT_CREATE or TASK_TIMESPENT_MODIFY fails, Task::addTimeSpent() and Task::updateTimeSpent() returned -1 without ever copying the messages from $this->errors (plural, populated by call_trigger) into $this->error (singular). The REST endpoint POST /api/index.php/tasks/{id}/addtimespent (and the matching PUT for updateTimeSpent) then surfaced 'Error when adding time:' with no detail, which makes the problem impossible to diagnose without server log access. Aggregate the per-handler messages into $this->error using the same foreach pattern already shipped for Propal::closeProposal in #38521. The guard "$ret <= 0 && empty($this->error) && !empty($this->errors)" keeps any pre-existing singular error message untouched and only fills the gap when only the array form has been populated. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/projet/class/task.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 2da892c0445..d27ebe52efb 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1657,6 +1657,16 @@ class Task extends CommonObjectLine $ret = -1; } + // Propagate trigger handler messages from $this->errors (plural array) + // to $this->error (singular string) so callers like the REST API can + // surface a useful message instead of an empty error tail. + if ($ret <= 0 && empty($this->error) && !empty($this->errors)) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + } + if ($ret > 0) { // Recalculate amount of time spent for task and update denormalized field $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; @@ -2097,6 +2107,16 @@ class Task extends CommonObjectLine $ret = -1; } + // Propagate trigger handler messages from $this->errors (plural array) + // to $this->error (singular string) so callers like the REST API can + // surface a useful message instead of an empty error tail. + if ($ret < 0 && empty($this->error) && !empty($this->errors)) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + } + if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || getDolGlobalString('TIMESPENT_ALWAYS_UPDATE_THM'))) { if ($this->timespent_old_duration != $this->timespent_duration) { // Recalculate amount of time spent for task and update denormalized field From 7a690414bb0df03d76b0c976a6dbcee8dc0d352f Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:07:39 +0700 Subject: [PATCH 11/33] Fix #37600 surface trigger error when closing proposal via API (#38521) When the LeaveTrace hook (or any trigger handler on PROPAL_CLOSE_SIGNED / PROPAL_CLOSE_REFUSED) fails, closeProposal() returned -1 without ever copying the messages from $this->errors (plural, populated by call_trigger) into $this->error (singular). The REST endpoint POST /proposals/{id}/close then surfaced 'Error when closing Commercial Proposal:' with no detail, which made the issue impossible to diagnose without server log access (typically seen when mail sending is disabled but the close trigger still runs other handlers). Aggregate the per-handler messages into $this->error using the same foreach pattern already used 10 times in this class (classifyBilled, setCancel, and others). Also guard the oldcopy restoration: when the SQL UPDATE fails before the oldcopy is taken (line 2671 only assigns inside the success path), the previous code dereferenced a null property and turned a recoverable error into a fatal. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/comm/propal/class/propal.class.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 66bcc96ab16..0d7b3470945 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2689,10 +2689,16 @@ class Propal extends CommonObject $this->db->commit(); return 1; } else { - $this->statut = $this->oldcopy->status; - $this->status = $this->oldcopy->status; - $this->date_signature = $this->oldcopy->date_signature; - $this->note_private = $this->oldcopy->note_private; + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + if (!empty($this->oldcopy)) { + $this->statut = $this->oldcopy->status; + $this->status = $this->oldcopy->status; + $this->date_signature = $this->oldcopy->date_signature; + $this->note_private = $this->oldcopy->note_private; + } $this->db->rollback(); return -1; From 59dfe19a467785965c8645f29b53cf6c66eae6f4 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:10:07 +0700 Subject: [PATCH 12/33] Fix #38347 Hide zero local-tax lines on TakePOS receipt (#38520) $mysoc->useLocalTax(N) is a country-wide flag: it returns true as soon as the country has a c_tva row with a non-zero localtaxN_type. For a Spanish company that is "No sujeto a RE" / "No sujeto a IRPF" the flag is therefore still true, and the receipt prints "Total Impuesto 2" and "Total Impuesto 3" lines with 0,00 EUR amounts which simplified invoice regulations do not allow. Mirror the pattern already used by compta/facture/card.php (lines 5125, 5137), compta/facture/card-rec.php, fourn/facture/card-rec.php and compta/facture/prelevement.php: gate the country-level useLocalTax check on $mysoc->localtaxN_assuj == "1" so a non-subject company does not show the zero line, while companies that are genuinely subject still see it even at 0 EUR. A non-zero total_localtax keeps forcing the line regardless of assuj, which covers shipments where the buyer triggers the tax. Same code path on 21.0, 22.0, 23.0 and develop; PR targets 21.0. Reported by @hisie. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/takepos/receipt.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index 8427e5b7b6c..50440fc9d9e 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -299,14 +299,19 @@ if (getDolGlobalString('TAKEPOS_SHOW_DATE_OF_PRINING')) { // Now show local taxes if company uses them -if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?> +// $mysoc->useLocalTax(N) is a country-wide flag (true as soon as the country has a +// matching c_tva row with a localtaxN_type), so on its own it always prints the line +// for Spanish companies even when the company is "No sujeto a RE / IRPF". Mirror the +// pattern used by compta/facture/card.php, card-rec.php and prelevement.php and gate +// the country check on $mysoc->localtaxN_assuj == "1". +if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || price2num($object->total_localtax1, 'MU')) { ?> trans("TotalLT1").''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n"; } ?> -total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?> +localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || price2num($object->total_localtax2, 'MU')) { ?> trans("TotalLT2").''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n"; From c13648e96deab7caa38acf956cea72ad45c8b030 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:11:10 +0700 Subject: [PATCH 13/33] Fix #38482 Show validation error on intervention line update inline (#38519) Updating a line of an intervention with an invalid value (typical case: a mandatory extrafield left empty) made the page bail out with "dol_print_error + exit", which renders the generic Dolibarr error screen and loses the user's edit context. Replace the bail out with a setEventMessages on the same page, matching the pattern already used everywhere else in fichinter/card.php (object->error, object->errors, 'errors'). The caller stays on the intervention card, sees the validation message and can correct the field without losing what was being typed. Reported by @Timoune974 with the patch sketch already in the issue. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/fichinter/card.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index ae0e59426b2..1a91f1eca4b 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -697,8 +697,10 @@ if (empty($reshook)) { $result = $objectline->update($user); if ($result < 0) { - dol_print_error($db); - exit; + // Surface validation errors (e.g. mandatory extrafield left empty) as an + // event message on the same page instead of breaking with a full Dolibarr + // error screen that loses the user's edit context. + setEventMessages($objectline->error, $objectline->errors, 'errors'); } // Define output language From cf68a7d00f6c67c4e1c0ef805b17b441d0191a37 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:16:27 +0700 Subject: [PATCH 14/33] Fix #37909 Fall back to default data root when the value is empty (#38514) isset($dolibarr_main_data_root) returns true even when the value is an empty string. On a fresh install where fileconf.php has set the variable but the field was left blank, install/inc.php kept that empty string, DOL_DATA_ROOT resolved to '', and the lock file path became '/install.lock'. A web server with a restrictive open_basedir then rejected the file_exists() check with "open_basedir restriction in effect. File(/install.lock) is not within the allowed path(s)" and the installer failed. Switch the two isset() guards on $dolibarr_main_data_root to !empty() so an empty value falls back to the default DOL_DOCUMENT_ROOT.'/../documents' path, which sits inside any sensible open_basedir scope. The other isset() guards in the same block default to '' anyway, so they are not affected by the same issue. Reported and analysed by @gregkuhnert. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/install/inc.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 3fd55c11bc4..46756485562 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -214,7 +214,11 @@ if (!defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > } // Clean parameters - $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents'; + // isset() is true on an empty string, which would let DOL_DATA_ROOT + // resolve to '' and the lock file to /install.lock (rejected by a + // restrictive open_basedir). Use !empty() so an empty value falls + // back to the default relative documents path. + $dolibarr_main_data_root = !empty($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents'; $dolibarr_main_url_root = isset($dolibarr_main_url_root) ? trim($dolibarr_main_url_root) : ''; $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) : ''; $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : ''; @@ -266,7 +270,7 @@ if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) { define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : '')); define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir -define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents')); +define('DOL_DATA_ROOT', (!empty($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents')); define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http* $suburi = strstr($uri, '/'); // $suburi contains url without domain From 4d2b73e18e5ddfa2b85cae1c07e534ccfe6ebf85 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:18:06 +0700 Subject: [PATCH 15/33] Fix #37445 Suppress PHP message display in API responses (#38512) API endpoints return JSON or XML. When PHP display_errors is on (the default outside production), any warning or notice raised before the response is written ends up in the response body and breaks the parser on the caller side. The reporter noted that "HTML should never appear before a JSON answer", which is exactly what happens to a development or staging install whose conf.php does not set dolibarr_main_prod. Set display_errors=0 and log_errors=1 at the top of api/index.php so that the messages stay visible in the server log while the response body stays clean. This applies to every API call independently of the production flag handled by filefunc.inc.php. Reported by @gagarine. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/api/index.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 4fc772e67b9..03c3962495e 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -29,6 +29,15 @@ use Luracast\Restler\Format\UploadFormat; +// API endpoints return JSON (or XML). A stray PHP warning or notice in the +// response body corrupts the parser on the caller side. Silence the display +// of PHP messages here while keeping them in the server log so that the +// problem is still observable to the operator (filefunc.inc.php only does +// this when dolibarr_main_prod is set, which leaves development setups +// emitting HTML into every API answer). +@ini_set('display_errors', '0'); +@ini_set('log_errors', '1'); + if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test } From 9d528dd4947f61baa5824cba892cd40f3f455b99 Mon Sep 17 00:00:00 2001 From: w3houde Date: Sun, 31 May 2026 04:19:14 +0700 Subject: [PATCH 16/33] Fix #37571 Accept "0" as a valid chart-of-accounts field value (#38510) The required-field check in accountancy/admin/card.php used the truthy form "!$account_number" and "!$label". PHP coerces the string "0" to false, so the form rejected those values as missing even though they were submitted. Values like "00", "01", "0.0" all worked because their truthy form is true. Compare the input against the empty string explicitly to keep the existing rejection of an actually missing value while accepting the literal "0". Same treatment on the four affected sites: account number and label, in both the add and edit branches. GETPOST returns a string here, so no other tests need to change. The downstream "empty()" tests in accountancy/class/accountingaccount.class.php may still need their own pass (the reporter notes the same false-positive on the SQL path), but they are out of scope for this atomic fix. Reported by @McLaynV with a precise PHP-bool quote. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/accountancy/admin/card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index ca95f8fac4f..60bdd71ad7a 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -78,10 +78,10 @@ if (GETPOST('cancel', 'alpha')) { if ($action == 'add' && $user->hasRight('accounting', 'chartofaccount')) { if (!$cancel) { - if (!$account_number) { + if ((string) $account_number === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors'); $action = 'create'; - } elseif (!$label) { + } elseif ((string) $label === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); $action = 'create'; } else { @@ -133,10 +133,10 @@ if ($action == 'add' && $user->hasRight('accounting', 'chartofaccount')) { } } elseif ($action == 'edit' && $user->hasRight('accounting', 'chartofaccount')) { if (!$cancel) { - if (!$account_number) { + if ((string) $account_number === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors'); $action = 'update'; - } elseif (!$label) { + } elseif ((string) $label === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); $action = 'update'; } else { From 04f3813421004a771d6d63d12bdec5fd383a4036 Mon Sep 17 00:00:00 2001 From: Dolicraft Date: Sun, 31 May 2026 16:11:57 +0700 Subject: [PATCH 17/33] Fix #31135 align project dropdown filter on supplier recurring invoices `htdocs/fourn/facture/card-rec.php` showed an almost-empty project dropdown when classifying or creating a recurring supplier invoice: only closed projects unrelated to the supplier and a few orphan ones appeared. The regular supplier invoice form (`htdocs/fourn/facture/card.php`) does not have that problem because it honours the global PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS toggle and passes $discard_closed=1 to FormProjets::select_projects(); the recurring form passed the thirdparty id unconditionally and $discard_closed=0. Mirror the regular form in both call sites (the create flow around line 1008 and the classify-edit flow around line 1199): use "(!PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS ? socid : -1)" for the socid filter and pass $discard_closed=1. Open projects of any thirdparty are now selectable when the constant is set, closed projects no longer appear in either branch. Signed-off-by: Dolicraft --- htdocs/fourn/facture/card-rec.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index 7160d796ee9..919703ce0c4 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -1005,7 +1005,10 @@ if ($action == 'create') { $projectid = GETPOST('projectid') ? GETPOST('projectid') : $object->fk_project; $langs->load('projects'); print '' . $langs->trans('Project') . ''; - $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, ''); + // Mirror the regular supplier invoice card.php: honour PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS + // (so projects unrelated to this supplier can be picked when the constant is set) and exclude + // closed projects from the dropdown (see issue #31135). + $numprojet = $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->thirdparty->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, ''); print '   thirdparty->id . (!empty($id) ? '&id=' . $id : '')) . '">' . $langs->trans("AddProject") . ''; print ''; } @@ -1196,7 +1199,10 @@ if ($action == 'create') { $morehtmlref .= '
'; $morehtmlref .= ''; $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + // Mirror the regular supplier invoice card.php: honour PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS + // and exclude closed projects so the picker behaves like the one in the non-recurring + // supplier invoice form (see issue #31135). + $morehtmlref .= $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, 'projectid', $maxlength, 0, 1, 1, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
'; } else { From 968fe40f5c4452b11735a3d30d024162652ea48a Mon Sep 17 00:00:00 2001 From: Dolicraft Date: Sun, 31 May 2026 17:28:28 +0700 Subject: [PATCH 18/33] Fix #32343 normalize product accountancy code so API matches GUI The admin product page renders the accountancy code dropdown via FormAccounting::select_account(). For each row in llx_accounting_account it displays the padded label length_accountg(account_number) but the option value is the raw account_number, so picking '606111000 - Wood for resale' submits the form with accountancy_code_sell = '606111'. When the same value is set through the REST API (POST /api/index.php/products with accountancy_code_sell = '606111000') Product::create() only does a trim() and stores the value verbatim. The next GUI render of the product card then cannot match '606111000' against the dropdown option list (which still uses raw '606111' as the value) and falls back to the blank '- - -' option; saving the form silently rewrites the value to whatever was selected, which is exactly the cycle the reporter and @mikygee described. Apply clean_account() (which is rtrim('0')) to the six accountancy code fields right after the existing trim() in Product::create() and Product::update(), and only when the global ACCOUNTING_MANAGE_ZERO constant is off (the same condition that drives length_accountg() in the admin dropdown). Installs that rely on trailing zeros being part of the code (ACCOUNTING_MANAGE_ZERO = 1) keep the previous behaviour; default installs end up with the same stored value whether the row comes in through the form or the API. Signed-off-by: Dolicraft --- htdocs/product/class/product.class.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b95d71e72f0..ddf541c8279 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1026,6 +1026,19 @@ class Product extends CommonObject $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra); $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export); + // Normalize the accountancy codes the way the admin dropdown does it, so an API client that + // sends '606111000' ends up with the same '606111' value the GUI stores (see issue #32343). + // When ACCOUNTING_MANAGE_ZERO is on, trailing zeros are part of the code and must be kept. + if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $this->accountancy_code_buy = clean_account($this->accountancy_code_buy); + $this->accountancy_code_buy_intra = clean_account($this->accountancy_code_buy_intra); + $this->accountancy_code_buy_export = clean_account($this->accountancy_code_buy_export); + $this->accountancy_code_sell = clean_account($this->accountancy_code_sell); + $this->accountancy_code_sell_intra = clean_account($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export = clean_account($this->accountancy_code_sell_export); + } + // Barcode value $this->barcode = trim($this->barcode); $this->mandatory_period = empty($this->mandatory_period) ? 0 : $this->mandatory_period; @@ -1440,6 +1453,19 @@ class Product extends CommonObject $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra); $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export); + // Normalize the accountancy codes the way the admin dropdown does it, so an API client that + // sends '606111000' ends up with the same '606111' value the GUI stores (see issue #32343). + // When ACCOUNTING_MANAGE_ZERO is on, trailing zeros are part of the code and must be kept. + if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $this->accountancy_code_buy = clean_account($this->accountancy_code_buy); + $this->accountancy_code_buy_intra = clean_account($this->accountancy_code_buy_intra); + $this->accountancy_code_buy_export = clean_account($this->accountancy_code_buy_export); + $this->accountancy_code_sell = clean_account($this->accountancy_code_sell); + $this->accountancy_code_sell_intra = clean_account($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export = clean_account($this->accountancy_code_sell_export); + } + $this->db->begin(); From 46290c2b226f5b1bf28d706ac9af396c75bf274c Mon Sep 17 00:00:00 2001 From: Dolicraft Date: Mon, 1 Jun 2026 18:50:48 +0200 Subject: [PATCH 19/33] Fix #38478 prefix bookkeeping card backtopage default with DOL_URL_ROOT When no backtopage POST is provided, the file defaulted to the bare path '/accountancy/bookkeeping/list.php'. On installs served under a subpath (https://host/dolibarr/...) the browser interprets a relative Location starting with / as host-root, so the redirect after the 'Transaction validated' button lands on host/accountancy/... instead of host/dolibarr/accountancy/... and the user gets a 404. Prefix the default with DOL_URL_ROOT, the convention used by every other card.php in the codebase (expedition, holiday, adherents, contact, ...). No effect on installs at host root (DOL_URL_ROOT=''). Reported by @ddiegop with the same fix suggestion. Signed-off-by: Dolicraft --- htdocs/accountancy/bookkeeping/card.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index d4e70169620..8c344f3f923 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -56,7 +56,10 @@ $confirm = GETPOST('confirm', 'alpha'); $type = GETPOST('type', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); if (empty($backtopage)) { - $backtopage = '/accountancy/bookkeeping/list.php'; + // Prefix with DOL_URL_ROOT so the redirect works when Dolibarr is installed + // under a subpath (e.g. https://host/dolibarr/). A bare /accountancy/... + // lands the browser at host root and breaks the redirect (see issue #38478). + $backtopage = DOL_URL_ROOT.'/accountancy/bookkeeping/list.php'; } $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') From c79bbd1508a6dd53b23911d1147864135bd7e523 Mon Sep 17 00:00:00 2001 From: w3houde Date: Tue, 2 Jun 2026 03:58:44 +0700 Subject: [PATCH 20/33] Fix #38035 keep vat_src_code on deposit lines generated from propal/order (#38566) Facture::createDepositFromOrigin buckets origin lines by tva_tx alone in both the MAIN_DEPOSIT_MULTI_TVA branch (line 1796) and the default %tot branch (line 1827), then passes the bare rate to Facture::addline as $txtva. Facture::addline accepts the rate in the 'rate (CODE)' form (line 4268: it preserves whatever is in parentheses), but the bucket key has none, so the generated deposit line is stored with vat_src_code = ''. The same loss cascades into Facture::convertToReduc which then creates DiscountAbsolute rows with no code, and the final invoice's discount line and PDF both render the rate without the dictionary Code (see #38036 for the downstream effect). Bucket by 'tva_tx (vat_src_code)' so addline receives the same form the codebase already uses elsewhere (factureligne fetch at line 2557, addline test at line 4268, c_payment_term key at line 1040). Two origin lines with the same tva_tx but different codes now produce two deposit lines with their respective codes preserved. updateline is also called with the formatted rate so the MAIN_DEPOSIT_MULTI_TVA rebalancing does not wipe the code right after addline set it. $amount_ttc_diff in the %tot branch was reading $amountdeposit[0] unconditionally even when the only key was a non-zero tva rate; switch to ?? 0 to keep the unused value safe. The MULTI_TVA arithmetic now takes the rate from a stripped variant of the bucket key so the percentage maths still works when the key contains a Code in parentheses. Reported by @vincentpoussev. Same bucketing on 22.0, 23.0 and develop; this PR targets 22.0. Signed-off-by: Dolicraft Co-authored-by: Dolicraft --- htdocs/compta/facture/class/facture.class.php | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index b0687548ac6..667a83b31ab 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1785,6 +1785,10 @@ class Facture extends CommonInvoice $amountdeposit = array(); $descriptions = array(); + // Bucket lines by tva_tx + vat_src_code so addline below receives the rate in + // the "tva (CODE)" format that Facture::addline knows how to parse. Bucketing + // on tva_tx alone wipes out the dictionary Code on the generated deposit line + // and on every downstream document derived from it (see issue #38035). if (getDolGlobalString('MAIN_DEPOSIT_MULTI_TVA')) { $amount = $origin->total_ttc * ($origin->deposit_percent / 100); @@ -1793,7 +1797,7 @@ class Facture extends CommonInvoice if (!empty($line->special_code)) { continue; } - $key = $line->tva_tx; + $key = $line->tva_tx . ($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''); if (!array_key_exists($key, $TTotalByTva)) { $TTotalByTva[$key] = 0; $descriptions[$key] = ''; @@ -1806,10 +1810,11 @@ class Facture extends CommonInvoice } foreach ($TTotalByTva as $tva => &$total) { + $tva_rate_only = preg_replace('/\s*\(.*\)/', '', (string) $tva); $coef = $total / $origin->total_ttc; // Calc coef $am = $amount * $coef; $amount_ttc_diff += $am; - $amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline + $amountdeposit[$tva] += $am / (1 + ((float) $tva_rate_only) / 100); // Convert into HT for the addline } } else { $totalamount = 0; @@ -1824,19 +1829,23 @@ class Facture extends CommonInvoice } $totalamount += $lines[$i]->total_ht; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ? - $tva_tx = $lines[$i]->tva_tx; - $amountdeposit[$tva_tx] += ((float) $lines[$i]->total_ht * (float) $origin->deposit_percent) / 100; - $descriptions[$tva_tx] .= '
  • ' . (!empty($lines[$i]->product_ref) ? $lines[$i]->product_ref . ' - ' : ''); - $descriptions[$tva_tx] .= (!empty($lines[$i]->product_label) ? $lines[$i]->product_label . ' - ' : ''); - $descriptions[$tva_tx] .= $langs->trans('Qty') . ' : ' . $lines[$i]->qty; - $descriptions[$tva_tx] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($lines[$i]->total_ht) . '
  • '; + $tva_key = $lines[$i]->tva_tx . ($lines[$i]->vat_src_code ? ' ('.$lines[$i]->vat_src_code.')' : ''); + if (!isset($amountdeposit[$tva_key])) { + $amountdeposit[$tva_key] = 0; + $descriptions[$tva_key] = ''; + } + $amountdeposit[$tva_key] += ((float) $lines[$i]->total_ht * (float) $origin->deposit_percent) / 100; + $descriptions[$tva_key] .= '
  • ' . (!empty($lines[$i]->product_ref) ? $lines[$i]->product_ref . ' - ' : ''); + $descriptions[$tva_key] .= (!empty($lines[$i]->product_label) ? $lines[$i]->product_label . ' - ' : ''); + $descriptions[$tva_key] .= $langs->trans('Qty') . ' : ' . $lines[$i]->qty; + $descriptions[$tva_key] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($lines[$i]->total_ht) . '
  • '; } if ($totalamount == 0) { $amountdeposit[0] = 0; } - $amount_ttc_diff = $amountdeposit[0]; + $amount_ttc_diff = $amountdeposit[0] ?? 0; } foreach ($amountdeposit as $tva => $amount) { @@ -1892,6 +1901,9 @@ class Facture extends CommonInvoice $deposit->fetch_lines(); $subprice_diff = $deposit->lines[0]->subprice - $diff / (1 + $deposit->lines[0]->tva_tx / 100); + // Pass tva_tx in the "rate (CODE)" form so updateline preserves the vat_src_code + // it received from addline; passing the bare rate would wipe the code. + $tva_tx_with_code = $deposit->lines[0]->tva_tx . ($deposit->lines[0]->vat_src_code ? ' ('.$deposit->lines[0]->vat_src_code.')' : ''); $updatelineResult = $deposit->updateline( $deposit->lines[0]->id, $deposit->lines[0]->desc, @@ -1900,7 +1912,7 @@ class Facture extends CommonInvoice $deposit->lines[0]->remise_percent, $deposit->lines[0]->date_start, $deposit->lines[0]->date_end, - $deposit->lines[0]->tva_tx, + $tva_tx_with_code, 0, 0, 'HT', From d7f69adcfc1d5eac05e8f7395166fbba08bbeed6 Mon Sep 17 00:00:00 2001 From: w3houde Date: Tue, 2 Jun 2026 04:02:17 +0700 Subject: [PATCH 21/33] Fix #38497 keep scale=0 of c_units row through CUnits hydration (#38555) CUnits::fetch() and CUnits::fetchAll() both read the scale column with '$obj->scale ? (int) $obj->scale : null', which collapses the legitimate scale of 0 (kg, kilogram, second, ...) into null. selectMeasuringUnits in htdocs/product/class/html.formproduct.class.php then renders that row as '