Skip to content
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

CRM-21562 fix mis-saving when using Euro thousand separator #11412

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Dec 15, 2017

Overview

When we have a thousand separator of ',' then the line items (and amount passed to the payment processor) is massively incorrect. Test demonstrates this. Fix is removal of a line of 'misfix' from https://issues.civicrm.org/jira/browse/CRM-10974 - but will require more testing.

In testing I changed multiple tests to work with both separator types & found several places that were not working very well

Before

Line item of 10,0000000 with comma separator of ',' mis-converted to 100000000 when saving the line item

After

Line item correctly calculated - I tested using a text field with the amount being 2650.50 & tried it with both European & Anglo versions of the separators. The numbers still appeared correctly & I saw no repeat of CRM-10974 and CRM-21350 also appeared fixed by the change

Technical Details

The line_item format function calls 'cleanMoney' on a non-localised currency string, treating it as localised. This causes it to wipe out the legitimate decimal point. This is an inappropriate place (too deep) to be dealing with localised strings of code and in fact they are not. The passed in value of $amount_override has only recently started to be used & may not even be in the release version, but, if passed in it should be localised. I have some doubts about the logic of that param -but they are outside the scope of this



@monishdeb
Copy link
Member

monishdeb commented Dec 15, 2017

I tested the patch in my local keeping thousand and decimal separator as '.' and ',' respectively. And tested it for Sale Tax, partial payment, payment using payment processor on Contribution and Event Registration page. Works fine for me.

However, I found a minor issue in 'Record Payment' form, which is not related though. Irrespective of the separator setting the default amount always formatted and set to 10000.00 which later throws a form rule error.

@@ -333,6 +333,11 @@ public static function getLineItems($entityId, $entity = 'participant', $isQuick
* this is
* lineItem array)
* @param string $amount_override
* Amount override must be in format 1000.00 - ie no thousand separator & if
* a decimal point is used it should be a decimal
Copy link
Member

@monishdeb monishdeb Dec 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further investigation I have ensured that in codebase the $amount_override carry the value from $params['partial_payment_total'] which is always in 1000.00 format as formatted by CRM_Utils_Rule::cleanMoney($params['partial_payment_total']) or DB amount value used

These are two important points where partial_payment_total parameter is assigned:
https://github.com/civicrm/civicrm-core/blob/master/CRM/Contribute/BAO/Contribution.php#L3191
https://github.com/civicrm/civicrm-core/blob/master/CRM/Event/Form/Participant.php#L1431L1442

@mlutfy
Copy link
Member

mlutfy commented Dec 17, 2017

@magnolia61 Did you test this patch?

@eileenmcnaughton eileenmcnaughton changed the base branch from master to 4.7.29-rc December 17, 2017 20:29
@eileenmcnaughton eileenmcnaughton changed the title CRM-21562 unit test to demonstrate mis-saving when using thousand separator CRM-21562 fix mis-saving when using Euro thousand separator Dec 18, 2017
@magnolia61
Copy link
Contributor

magnolia61 commented Dec 18, 2017

I tested this patch against decimal delimiter . and thousands , and vice versa.
Both with contribution pages and event registrations and complex price sets.
All works like a charm!

@monishdeb
Copy link
Member

@eileenmcnaughton there are two related test failures and this will fix those :

diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php
index 9e7995a..3286849 100644
--- a/CRM/Contribute/BAO/Contribution/Utils.php
+++ b/CRM/Contribute/BAO/Contribution/Utils.php
@@ -500,7 +500,9 @@ LIMIT 1
   public static function calculateTaxAmount($amount, $taxRate, $ugWeDoNotKnowIfItNeedsCleaning_Help = FALSE) {
     $taxAmount = array();
     if ($ugWeDoNotKnowIfItNeedsCleaning_Help) {
-      Civi::log()->warning('Deprecated function, make sure money is in usable format before calling this.', array('civi.tag' => 'deprecated'));
+      if (CIVICRM_UF !== 'UnitTests') {
+        Civi::log()->warning('Deprecated function, make sure money is in usable format before calling this.', array('civi.tag' => 'deprecated'));
+      }
       $amount = CRM_Utils_Rule::cleanMoney($amount);
     }
     // There can not be any rounding at this stage - as this is prior to quantity multiplication

@eileenmcnaughton
Copy link
Contributor Author

@monishdeb I put that there so the unit tests would fail & we could repair any places which were tested (since we can do that with some confidence)

CRM-21562 Additional thousand separator fix on sales tax

CRM-21562 additional fixes for money formatting, found by adding deprecated
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb @colemanw @mlutfy I think this is good to merge now

@eileenmcnaughton
Copy link
Contributor Author

I'm going to merge this based on @monishdeb review & @magnolia61 testing. I feel like this needs to be merged ASAP since it is the main driver for the Wed release & we really have it core for a couple of days before it goes out.

@eileenmcnaughton eileenmcnaughton merged commit d94349d into civicrm:4.7.29-rc Dec 18, 2017
@monishdeb
Copy link
Member

Cool, agree with the last change made for fixing test failure.

sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21562 fix mis-saving when using Euro thousand separator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants