, as decimal separator, and [space] as thousand separators leads to api errors
Steps to reproduce
- At Administer --> Localisation --> Languages, Currencies and Location: set , as a decimal separator
- At Administer --> Localisation --> Languages, Currencies and Location: Set space as thousand separator (So that 1234.56 is displayed as 1 234,56)
- Go to api 3 explorer (Support --> Developers --> Api explorer v3)
- Create a contribution with total_amount = 250.00 (keep the dot and the two zero's).
Expected result
Contribution created with a total amount of € 250,00
Actual result
Api error: total_amount is not a valid amount: 250.00
Caused by
This is caused by the statement in https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/Rule.php#L603 This statement expects at least . in either decimal separator or thousand separator.
if ($config->monetaryDecimalPoint &&
$config->monetaryDecimalPoint != '.' &&
// CRM-7122 also check for Thousands Separator in config settings
$config->monetaryThousandSeparator != '.' &&
substr_count($value, '.')
) {
return FALSE;
}
Analyses
Below an analyses of the contribution.create api with different localization settings and inputs.
Currency | Decimal sep. | Thousand sep. | Contribution.create total_amount | Raw Value | Display as | 5.13 | 5.20 |
---|---|---|---|---|---|---|---|
$ | . | , | 1,234,567.89 | 1234567.89 | $ 1,234,567.89 | OK | OK |
$ | . | , | 1234567.89 | 1234567.89 | $ 1,234,567.89 | OK | OK |
$ | . | [space] | 1 234 567.89 | 1234567.89 | $ 1 234 567.89 | OK | OK |
$ | . | [space] | 1234567.89 | 1234567.89 | $ 1 234 567.89 | Fail | Fail |
€ | . | , | 1,234,567.89 | 1234567.89 | € 1,234,567.89 | OK | OK |
€ | . | , | 1234567.89 | 1234567.89 | € 1,234,567.89 | OK | OK |
€ | , | . | 1.234.567,89 | 1234567.89 | € 1.234.567,89 | OK | OK |
€ | , | . | 1234567.89 | 1234567.89 | € 1.234.567,89 | OK | OK |
€ | , | [space] | 1 234 567,89 | 1234567.89 | € 1 234 567,89 | OK | OK |
€ | , | [space] | 1234567.89 | 1234567.89 | € 1 234 567,89 | Fail | Fail |
NOK | . | , | 1,234,567.89 | 1234567.89 | NOK 1,234,567.89 | OK | OK |
NOK | . | , | 1234567.89 | 1234567.89 | NOK 1,234,567.89 | OK | OK |
NOK | , | . | 1.234.567,89 | 1234567.89 | NOK 1.234.567,89 | OK | OK |
NOK | , | . | 1234567.89 | 1234567.89 | NOK 1.234.567,89 | OK | OK |
NOK | , | [space] | 1 234 567,89 | 1234567.89 | NOK 1 234 567,89 | OK | OK |
NOK | , | [space] | 1234567.89 | 1234567.89 | NOK 1 234 567,89 | Fail | Fail |
See also
This bug is introduced by https://issues.civicrm.org/jira/browse/CRM-7122
Question before fixing this
What exactly is this if statement checking for?