-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
[REF] Fix silly function to do less handling of non-existent scenarios #13563
[REF] Fix silly function to do less handling of non-existent scenarios #13563
Conversation
If you dig down into CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType you find that just calling CRM_Contribute_BAO_Contribution::getContributionBalance is all it actually does here....
(Standard links)
|
CRM/Core/BAO/FinancialTrxn.php
Outdated
elseif ($paymentVal > 0) { | ||
$value['amount_owed'] = $paymentVal; | ||
} | ||
} |
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 umm the 'Record Payment' b/o form still uses these amounts:
CRM//Contribute/Form/AdditionalPayment.php:112: if (!empty($paymentInfo['refund_due'])) {
CRM//Contribute/Form/AdditionalPayment.php:113: $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
CRM//Contribute/Form/AdditionalPayment.php:609: if (!empty($paymentInfo['refund_due'])) {
CRM//Contribute/Form/AdditionalPayment.php:610: $this->_refund = $paymentInfo['refund_due'];
to decide if its refund or owed amount.
Won't it cause a regression?
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.
@monishdeb they are calling a different fn
$paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE);
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.
an no I see - it should already be broken since they don't pass 'TRUE' & the default is false
$paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType);
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.
Actually, the default is $returnType = TRUE if you look in this line https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/BAO/FinancialTrxn.php#L451
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.
Ug you are right - well I'll drop out that commit then
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.
@monishdeb OK I dropped the param but assume true not false now
d23722f
to
17d8fac
Compare
17d8fac
to
2fc731d
Compare
test this please |
1 similar comment
test this please |
@monishdeb it passes |
@monishdeb I think this is OK now? |
@@ -4041,7 +4035,8 @@ public static function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $us | |||
$total = $total['total_amount']; | |||
} | |||
|
|||
$paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total); | |||
$paymentBalance = CRM_Contribute_BAO_Contribution::getContributionBalance($contributionId, $total); | |||
|
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 this will cause an issue with the calculation done below(see L4049, L4057), whereas it is expecting $paymentBalance to be an amount but as per the patch it always returns a array.
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.
@monishdeb - no getContributionBalance returns an amount - when it's called within getPartialPaymentByType they take that amount & create an array for presumably legacy reasons
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.
Oops sorry, my bad didn't saw what function is been called here. Hmm let me do a quick test at UI level, then I'll merge it.
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.
thanks @monishdeb- I think once #13610 is merged & we can clean up the payment form it's going to be easy to remove that getPartialPaymentWithType function altogether.
And now ... all Civi devs repeat after me
"if a function doesn't return the format I want, I will never again just add another parameter to get it to return a different format. I understand a wrapper function is acceptable if I really need to change the format but only if I avoid just butchering something unrelated onto the function" :-)
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.
Hmm rationally, its good in terms of clarity and the definite role each wrapper function has to play rather then bring more parameters to it and to extend its functionality, which is a pain for dev to understand the code (like the export and changeFee fns). Bad in terms of increase in SLOC but thats fine, we have to be more descriptive on how we define a function. It really help us to understand the code or figure out the bug and bring any change without worrying about different scenarios.
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.
:-)
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.
SLOC = single line of code? I think drupal has some stuff around that in it's standards (basically goal is readability not brevity)
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.
Source LOC
Tested refund/ partial/ pending payment for Event's and memberships's payment. Working fine for me (also tried payment API). Merging now |
thanks @monishdeb |
Overview
code cleanup
Before
After
Technical Details
Really I don't think getPartialPaymentWithType has any reason to exist. I kept to this small change however because I think it's pretty easy to review. If anyone wants to tackle fully getting rid of it I'm happy to do that PR or review it
Comments
@mattwire @pradpnayak @monishdeb I'm sure you must have been annoyed by this at some point
testing note
this code has existing test coverage