-
-
Notifications
You must be signed in to change notification settings - Fork 821
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-19966 Unfair Double Taxation and net_amounts. #9948
Conversation
this is the error from jenkins PHP Fatal error: Call to undefined method CRM_Contribute_BAO_Contribution::calculateNetAmount() in /home/jenkins/buildkit/build/core-9948-6uo0t/sites/all/modules/civicrm/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php on line 1036 |
@pradpnayak @JoeMurray this fixes a reproducable bug but you should review for other impacts if you have capacity because the code was introduced in response to https://issues.civicrm.org/jira/browse/CRM-19585 - I'm not sure which of the described issues it relates to |
@@ -5371,22 +5371,6 @@ public static function calculateFinancialItemAmount($params, $amountParams, $con | |||
} | |||
|
|||
/** | |||
* Calculate net amount. |
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.
I agree calculation in this function is incorrect.
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.
Thank you for confirming - I'll strip it out of the phpunit test as well.
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.
OK great, I feel that agreement was a key part of resolving this
@@ -1589,7 +1585,7 @@ protected function submit($submittedValues, $action, $pledgePaymentID) { | |||
} | |||
|
|||
if (!isset($submittedValues['total_amount'])) { | |||
$submittedValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_values); | |||
$submittedValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_values) - CRM_Utils_Array::value('tax_amount', $this->_values); |
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.
Just raising question: how many significant digits do we have here? Are we changing total amount from two decimals to 3 or more by doing math with tax amount?
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.
I'm not sure but we're in the form/Contribution.php so not worried about too many decimals here. I'll make sure I test with some numbers that did previously introduce rounding issues before I fixed that issue earlier this year.
@@ -377,10 +377,6 @@ public function setDefaultValues() { | |||
$defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a'); | |||
} | |||
|
|||
if (isset($defaults['net_amount'])) { |
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.
We should be setting this to correct value rather than deliberately introducing this bug to solve a higher priority one. @pradpnayak please provide suggestion here for correct calculation.
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.
Sorry not sure what you mean by 'introducing this bug'? Removing the incorrect calculation here actually fixes net_amount - as it's calculated later on.
Pradeep will a) provide a draft for correct calculation of net_amount. He'll also look at changing the form validation that complains about netamount and total amount being different when the total amount displayed on form is back-calculated when taxes have been previously added (yuck- this is not reliable for some amounts and taxes). |
We don't need a) as net_amount is already calculated properly; Please put the form validation bits on separate issue/PR; it's not relevant to CRM 19966 |
Pradeep has found that this fix does not work if a call is made through the API. |
@JoeMurray - can you be more specific so I can try and reproduce that? Or is it any call - even simple Create Contribution? And what is not working (net_amount; tax_amount; total_amount)? |
I just confirmed with my 4.6 client [major user of sales taxes] that this issue does NOT affect 4.6 - I'll still commit to adding a PHP Unit test to this PR in 4.7; |
@pradpnayak can you write a unit test for the bit that doesn't work? @KarinG don't let the questions above hold you back from writing a unit test for the part you are trying to fix. Even if the solution needs tweaking the unit test will still ensure the fix is locking in. (of course not assuming you were going to work on this more today, but I'd hate to see this fantastic momentum lost) |
There is no unit test for what doesn't work [and I don't know yet what doesn't work - or if it has ever worked]... let's make that a separate CRM ticket? I strongly feel manage-able bite size - fundamentally correct fixes - are the way to work through an Epic. |
Hey @KarinG, I cannot confirm the same for 4.6. Just pointing this out because I don't want anyone to see your comment and simply assume that all is working in 4.6 too. Because without separate testing and confirmation, it should still be regarded as an issue. |
Ok that's odd - what I'm fixing here went into 4.7 only - so it made sense 4.6 wasn't affected - and I just confirmed it with the ED of my project that uses this heavily - we can edit Contributions that are linked the Memberships that have been generated w/ pricesets and neither the tax_amounts not the net_amounts go bananas; and everything on the PDF invoice adds up to. PS - I'm not saying everything re sales tax is working in 4.6 - but this specific issue appears to be; |
@KarinG Yes, I get that. But since this is a PR for 4.7. Can we just keep it within that scope. Solving these problems is confusing enough as it is! |
Oh I'm all for keeping within scope 😀 |
@KarinG and yet, 2 days ago I had to deal with a customer support request where membership with a priceset which was the
That's just wrong. And here's a few screenshots of this in 4.6. |
Hey I thought we were staying within scope :-)! What you're describing here is a different issue/mechanism. You're changing the status of the Contribution -> that triggers a bunch of other pathways into Financial Accounts... Copy/paste that into a separate JIRA ticket - could be one we can look at next. |
Agreed, 4.7. Different issue, happy for you to make that call. For that screenshot. I've amended the description. This problem occurred when CiviCRM automatically changed status from Pending to Completed when the payment was received as part of reconciling with Xero. |
@KarinG Actually, the problem detailed in the screenshots is https://issues.civicrm.org/jira/browse/CRM-19966 Remove unfair double taxation which is what this PR is for. So I'm not sure why we need to create a new issue for this. |
No it's not the same issue -> Your three screenshots in https://issues.civicrm.org/jira/browse/CRM-19966 - all have status = completed & show the Tax creeping up (from $10 -> $11 -> $12.10) -> that's what I was able to reproduce and that's what I fixed here. |
This is very frustrating. |
just a general principle, more JIRA tickets is better than less I think. Ie if we can fix something clear cut on a specific version then we should close a JIRA against it. |
@Eileen - ran some more tests re: API - if I run a test (doing the exact same update I've been doing via the GUI):
The amounts fixed in this issue (total_amount; tax_amount and net_amount) continue to look good:
|
@@ -851,4 +851,58 @@ public function testSubmitWithOutSaleTax() { | |||
$this->assertTrue(empty($lineItem['tax_amount'])); | |||
} | |||
|
|||
public function testReSubmitSaleTax() { |
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.
This is not working yet!
…ce that function is edited
Resolve immediate issues with test & add checks for mail content (sin…
Thank you for these core fixes - I'll continue to work on the PHP Unit test's assertions tonight. |
… - using default price_set.
Ok I fixed one PHP Unit test and another one to simulate Editing a Contribution in the BackOffice [and then checking to ensure net_amount; tax_amount; total_amount are all fine. There is a third test that can and probably should be written. Just not right now... |
I've been working on this with @KarinG & I agree that
merge on pass |
test this please |
This was flagged |
Actually, Pradeep was doing some extensive testing in last 24h and didn't notice @totten's merge. There were several errors still present with the code in this PR, marked by ** in this gist: https://gist.github.com/JoeMurray/be20be2119212eaa991af11c8ba9b951 We could either revert this merge or document them as issues under sales tax epic. I propose the latter. |
@JoeMurray - can you ask @pradpnayak to please elaborate on his #8: **8. Updated contribution #7 using contribution form with Sales Tax enabled. @eileenmcnaughton : Pradeep thinks (and I think he is correct) that this is cause by "Change to code at line 1804." That's the refactoring of the lineItem bit - that you did in order to make testing of Submit with ::UPDATE possible. Happy to look at that with you - once we know what scenario contribution #7 exactly is. |
I strongly favor we keep this merge as it was never meant to fix all tax issues. It fixes a fundamental one where net_amount had been redefined and where sales_tax were being charge on sales taxes on Edit Contribution. So this PR will eliminate for sure more other Issues - but I do want to make sure that we didn't cause a regression by making it possible to Unit test for this. |
@JoeMurray I agree with documenting them as issues under the sales tax epic. @pradpnayak's testing looks really good & converting that output into JIRA issues sounds like the next step. One really good thing about this PR is it actually adds unit tests covering sales tax output in invoices, which was previously uncovered by tests, so it's a really good basis for going forwards. I strongly believe our focus now should be on triage, rather than the code, as it's really hard to review fixes without that step. @agileware has also volunteered some time on this. We should aim to have an issue open for every remaining symptom (unless they are clearly really just one bug) and to get all the ones that we can't clearly reproduce closed, excluding the epic, which should be for tracking the other issues only |
I should also note the merged code was possibly different to what @pradpnayak tested as there were some changes to the PR during the QA & test-writing process, so we should double check the bugs against the now-master |
I agree with the comments over the last few days. I had intended to create separate issues in JIRA for what Pradeep turned up. He'll be doing that today now that we have spoken. We're also going to push the remaining work in CRM-19585 into separate issues under the epic, and create additional issues for each outstanding PR on that issue describing what each does. I think Pradeep is submitting additional tests for the errors documented in his tests. |
Thanks @JoeMurray |
Fixes for CRM-19966 Unfair Double Taxation and net_amounts.
Just a few follow on links The form validation issue was discussed here but it was left out of scope due to the feedback in this discussion. It seemed to be a non issue in 2017 & 2018 but has now become an issue for one site. There are 3 related gitlab issues https://lab.civicrm.org/dev/core/issues/267 |
Net amount is calculated in the BAO if not set so asking users to enter it does not gain us anything. Currently we require them to calculate it & edit it if they change the fee_amount or total_amount and we validate their data entry, and make them re-do it if they get it wrong. Since the field is pretty hidden it's unintuitive to need to change it and makes for a painful contribution update process. The current behaviour dates back to svn days - however since 2015 the BAO has handled the possibility of it not being set. In addition we have had code issues with the comparison around currency & float comparison issues eg. civicrm#11485 and https://lab.civicrm.org/dev/core/issues/260 ( in the latter case the data saves correctly without net_amount and incorrectly if it is changed to meet the form validation rule. (There was a proposal in Mar 2017 to address that civicrm#9948 (comment) by fixing the calculation but I believe just dropping the field is better). Our unit tests test the form submissions but for some reason net_amoutn was removed from the tests https://github.com/civicrm/civicrm-core/pull/9948/files#diff-40e2e0f106ba620465acf3a9a81f2498L1535 meaning our test coverage is more reliable without it being set.
Net amount is calculated in the BAO if not set so asking users to enter it does not gain us anything. Currently we require them to calculate it & edit it if they change the fee_amount or total_amount and we validate their data entry, and make them re-do it if they get it wrong. Since the field is pretty hidden it's unintuitive to need to change it and makes for a painful contribution update process. The current behaviour dates back to svn days - however since 2015 the BAO has handled the possibility of it not being set. In addition we have had code issues with the comparison around currency & float comparison issues eg. civicrm#11485 and https://lab.civicrm.org/dev/core/issues/260 ( in the latter case the data saves correctly without net_amount and incorrectly if it is changed to meet the form validation rule. (There was a proposal in Mar 2017 to address that civicrm#9948 (comment) by fixing the calculation but I believe just dropping the field is better). Our unit tests test the form submissions but for some reason net_amoutn was removed from the tests https://github.com/civicrm/civicrm-core/pull/9948/files#diff-40e2e0f106ba620465acf3a9a81f2498L1535 meaning our test coverage is more reliable without it being set.
if the total_amount is not in the currently submittedValues -> then it needs to be retrieved from $this->_values - however that total_amount is 'after' sales tax was previously added to it. Hence the subtraction. If we don't subtract it here - you end up being charged sales_tax on top of sales_tax - hence the screenshots in the JIRA issue
net_amount is defined as
"Net value of the contribution (Total Amount minus Fee)."
fee_amount is defined as:
"Processing fee for this transaction (if applicable)."
Neither are related to sales taxes