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

[REF] Fix silly function to do less handling of non-existent scenarios #13563

Merged
merged 2 commits into from
Feb 16, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Feb 11, 2019

Overview

code cleanup

Before

  1. Function getPaymentInfo calls getPartialPaymentWithType which calls CRM_Contribute_BAO_Contribution::getContributionBalance
  2. Function getPaymentInfo accepts a parameter $returnType and has code handling for it, but no code ever passed this

After

  1. Function getPaymentInfo calls CRM_Contribute_BAO_Contribution::getContributionBalance
  2. parameter $returnType removed from getPartialPaymentWithType

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

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....
@civibot
Copy link

civibot bot commented Feb 11, 2019

(Standard links)

@civibot civibot bot added the master label Feb 11, 2019
elseif ($paymentVal > 0) {
$value['amount_owed'] = $paymentVal;
}
}
Copy link
Member

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?

Copy link
Contributor Author

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);

Copy link
Contributor Author

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);

Copy link
Member

@monishdeb monishdeb Feb 11, 2019

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@eileenmcnaughton eileenmcnaughton force-pushed the fn_fix_payment_by_type branch 2 times, most recently from d23722f to 17d8fac Compare February 11, 2019 21:24
@eileenmcnaughton
Copy link
Contributor Author

test this please

1 similar comment
@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton
Copy link
Contributor Author

@monishdeb it passes

@eileenmcnaughton
Copy link
Contributor Author

@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);

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@eileenmcnaughton eileenmcnaughton Feb 16, 2019

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" :-)

Copy link
Member

@monishdeb monishdeb Feb 16, 2019

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:-)

Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

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

Source LOC

@monishdeb
Copy link
Member

Tested refund/ partial/ pending payment for Event's and memberships's payment. Working fine for me (also tried payment API). Merging now

@monishdeb monishdeb merged commit 4cd3a8e into civicrm:master Feb 16, 2019
@eileenmcnaughton eileenmcnaughton deleted the fn_fix_payment_by_type branch February 16, 2019 15:12
@eileenmcnaughton
Copy link
Contributor Author

thanks @monishdeb

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.

2 participants