-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#2003 Civicrm_price_field_value.amount truncation when localisation in play #18297
Conversation
(Standard links)
|
test this please |
CRM/Utils/Money.php
Outdated
@@ -201,7 +201,7 @@ protected static function formatLocaleNumeric($amount) { | |||
* @return string | |||
*/ | |||
protected static function formatLocaleNumericRounded($amount, $numberOfPlaces) { | |||
return self::formatLocaleNumeric(round($amount, $numberOfPlaces)); | |||
return self::formatNumericByFormat($amount, '%!.' . $numberOfPlaces . 'i'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton just thinking it might be worthwhile somewhere having a comment about what this actually looks like i.e. '%!.2i' But this seems to work according to the docs (and here we go again on the money_format)
… apiv4 This implementation has some limitations. I only address one in this PR - removing the rounding - as the focus of the PR is the move. The rounding from all save layers was previously removed but it was reverted when it was eroneously believed to have caused a bug. The bug turned out to be civicrm#18297
… apiv4 This implementation has some limitations. I only address one in this PR - removing the rounding - as the focus of the PR is the move. The rounding from all save layers was previously removed but it was reverted when it was eroneously believed to have caused a bug. The bug turned out to be civicrm#18297
… apiv4 This implementation has some limitations. I only address one in this PR - removing the rounding - as the focus of the PR is the move. The rounding from all save layers was previously removed but it was reverted when it was eroneously believed to have caused a bug. The bug turned out to be civicrm#18297
… apiv4 This implementation has some limitations. I only address one in this PR - removing the rounding - as the focus of the PR is the move. The rounding from all save layers was previously removed but it was reverted when it was eroneously believed to have caused a bug. The bug turned out to be civicrm#18297
@eileenmcnaughton we have tested this PR and our conlcusion is that this fixes one problem but introduces new problems and this PR needs further work. We have tested the following:
We tested the following variations when it came to decimal separator and thousand separator:
We tested the following amounts:
And we tested it on dmaster (without this patch) and an environment with this patch Results
a) This is really strange behaviour, some numbers are suddenly a 0 and it ends with 19 it looks like it does something random with the numbers behind the decimal We discovered a new issue with price fields in dmaster where 12,987654321 is converted into 12,00 and we reported that issue in lab/2003 To prevent we are dealing, with incidents around different scenario's, our advice is that the issue with the money fields and decimal separator (and/or VAT) should be addressed within a broader scope to come up with an overall solution. (We will ask within CiviCooP whether we can address this and take this upon us) |
@jaapjansma did you check what is saved to the db as this patch is primarily about the amount saved I'm happy if the amount displayed stays out of scope |
No I did not check the database and we strongly think that this patch introduces new problems. When you enter 123,456,789.987654321 and it becomes 123,456,789.9800000019 then something is clearly wrong. |
bd913db
to
f0718ab
Compare
@jaapjansma I have updated this so it ONLY fixes what is saved to the db. It still presents the value rounded in the edit screen so you can't tell from the UI whether it has worked or not. Note that the issue you hit is that php deals with floats in strange ways at times - the fix we have selected for this is to use the brickmoney library. This now ships with core but as it relies on the php-intl extension our intent is to give the status checks a few months to get sites updated before actually using it. When you want to dig into this & go deep on floats please use brickmoney |
This fixes the bug that derailed the fix for https://lab.civicrm.org/dev/core/-/issues/1603 On further testing I agree with Jitendra that the price field form was mis-saving the longer values (I only tested with Euro style decimal separators but maybe on both) and it was bad data caused by this that made the merged fix look like a regression. I also observed that the Money functions intended to round only appeared to since it was rounding just fine to 2 places, as tested, but it was still rounding to 2 places when we wanted more. This fixes both the New Price field screen (when options are entered) and the edit options screen
f0718ab
to
09e6f54
Compare
test this please Removing has-test as scope is narrowed |
I note it's impossible to submit 123,456,789.987654321 on membership type form (as min_fee) as it breaks form validation as being too long. |
I took a look at this one and I found that I was able to generate a unit test for the storing in the database #18414 and found that if you included a , in the option amount column when adding a new price field at least according to the unit test the amount would not be saved correctly. My unit test passes with this merged and as this is aimed solely on the storing in the database not on the presentation layer this looks good to me to merge. I would also add that I agree the presentation layer problems are a bug and need to be fixed |
Overview
This fixes the bug that derailed the fix for https://lab.civicrm.org/dev/core/-/issues/1603
On further testing I agree with Jitendra that the price field form was mis-saving the longer values (I only
tested with Euro style decimal separators but maybe on both) and it was bad data caused by this
that made the merged fix look like a regression.
I also observed that the Money functions intended to round only appeared to since it was rounding
just fine to 2 places, as tested, but it was still rounding to 2 places when we wanted more.
This fixes both the New Price field screen (when options are entered) and the edit options screen
Before
This amount string is truncated on save - ie the decimals below don't hit the civicrm_price_field_option_value table
![Screen Shot 2020-08-31 at 5 20 47 PM](https://user-images.githubusercontent.com/336308/91689308-ef075880-ebb7-11ea-912b-cf4998291034.png)
After
Amount is saved correctly into the db - displays rounded to 2 digits (unchanged)
Technical Details
@jaapjansma
Comments