Project/Lead: default opportunity probability is 100x too high when changing the opportunity status
Bug
On the project/lead card, changing the Opportunity status fills the probability field with a value that is 100 times too high (e.g. 10000 instead of 100 for status WON). The "Previous value" hint shown next to the field is wrong in the same way (7500 % instead of 75 %).
This only happens in languages where SeparatorThousand is . — currently da_DK, ca_ES, de_DE, de_AT, el_GR, es_CL, es_CO, es_EC, es_ES, hr_HR, gl_ES, lo_LA, tr_TR. In en_US the value happens to survive, which is why this is not visible in the default language.
The wrong value is not only cosmetic: it is submitted on save, and llx_projet.opp_percent is double(5,2) (max 999.99), so the value gets truncated or rejected depending on sql_mode.
Cause
htdocs/projet/card.php runs the percent values through price2numjs():
jQuery("#opp_percent").val(price2numjs(defaultpercent));
jQuery("#oldopppercent").text(' - PreviousValue: '+price2numjs(oldpercent)+' %');But both values are raw DB values that are already in universal numeric format:
defaultpercentis thedefaultpercentattribute written byFormProjets::selectOpportunityStatus()(htdocs/core/class/html.formprojet.class.php) straight fromllx_c_lead_status.percent, column typedouble(5,2)→ the string"100.00".oldpercentis$object->opp_percentfromllx_projet.opp_percent, alsodouble(5,2)→ the string"75.00".
price2numjs() (htdocs/core/js/lib_head.js.php) expects a localized number and strips the thousand separator first:
amount = amount.replace(thousand, ''); // "." in de_DE
amount = amount.replace(dec, '.'); // "," in de_DESo "100.00" becomes "10000" and "75.00" becomes "7500".
The same raw value is also assigned unconverted in two places (creation form and the oldpercent branch), which puts 100.00 / 75.00 into the field instead of 100 / 75.
Dolibarr Version
23.0.4 (code is identical in develop)
Environment PHP
8.1
Environment Database
MySQL 8.4.9
Steps to reproduce the behavior and expected behavior
- Enable the Projects module with opportunities (
PROJECT_USE_OPPORTUNITIES). - Set the user language to German (
de_DE) or any other language listed above. - Open a lead whose current opportunity status has a probability of 75 % and click Modify.
- Change Opportunity status to Won (probability 100 % in the dictionary).
Expected: the probability field shows 100, the hint next to it shows - Previous value: 75 %.
Actual: the probability field shows 10000, the hint shows - Previous value: 7500 %.
Source: Dolibarr/dolibarr