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-20750: Incorrect financial trxn entries when payment instrument i… #10920

Merged
merged 3 commits into from
Sep 13, 2017

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 30, 2017

@monishdeb this is the portion of #10539 that I understand. Mostly I have removed the whitespace changes & the test changes (as opposed to the additional test). I expect this to fail & the reason for the test changes to become clearer to me.

Note that I did a further extraction of self::isPaymentInstrumentChange for readability.

In general I feel fairly good about test coverage of the function being changed & most of your change is just tidying up code (unscattering & moving to a function).

There is a change in here that is not spelt out - when altering a check number 2 transactions will no longer be created (a negative & a positive one). Much as I passionately agree with that change I think it needs to be spelt out in the spec & if Joe agrees to it I believe some documentation needs to be updated


Overview

Fix to incorrect financial items created when editing a payment through the back office contribution form

Before

After altering the credit card details are incorrectly assigned to the reversal entry
[https://issues.civicrm.org/jira/secure/attachment/61870/Screen%20Shot%202017-06-20%20at%205.35.02%20PM.png]

After

Reversal entry is 'clean' of the details from the new transaction. Code readability improved & unit test added

Technical Details

Comments

This is a reviewers commit of #10539

I have done an extraction and made changes to the test. I have not changed what the test tests, which was my concern in the first commit before review.

Notable changes

  1. I removed this from the reversal entry. I believe the reversal should be reversing against the original account. If this value is to be used it would be a from_financial_account_id entry
$lastFinancialTrxn['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($currentContribution->payment_instrument_id);
  1. I have changed from
    elseif ((!CRM_Utils_System::isNull($params['contribution']->payment_instrument_id) ||
    to
elseif ((!CRM_Utils_System::isNull($params['payment_instrument_id'])

& switched && rather than || in the logic. This was causing a test failure which was changed in the original PR by changes to the test. However, I felt that the logic in fact was wrong, rather than the test. We should check if there is an attempt to change the payment_instrument_id (as represented by the $params array) rather than whether the $params['contribution'] has one.

Unfortunately I think I might be personally guilty of having added $params['contribution'] to the $params array in about 4.2 as a hack to get some data onto the form :-(

@eileenmcnaughton
Copy link
Contributor Author

test this please

…s changed on backoffice Contribution edit form

added unit test

CRM-20750, fixed db entries

----------------------------------------
* CRM-20750: Incorrect financial trxn entries when payment instrument is changed on backoffice Contribution edit form
  https://issues.civicrm.org/jira/browse/CRM-20750
On trying to investigate why a test change was required in the original PR I came to the following conclusions:

1) the test function was causing problems by being hard to read. As a result it was too easy to see it as
'accounts magic' - I started a cleanup here
2) Once I understood what was being tested & failing I concluded the change in the PR was in fact wrong
as it was putting a negative entry against the new financial account rather than the original one.
Change logic for determinig paymentInstrumentChange to look at whether
['payment_instrument_id'] isset. If not it has not been passed by the calling
function and by definition the calling function is not attempting to change it
@eileenmcnaughton eileenmcnaughton changed the title [WIP] CRM-20750: Incorrect financial trxn entries when payment instrument i… CRM-20750: Incorrect financial trxn entries when payment instrument i… Sep 11, 2017
@eileenmcnaughton
Copy link
Contributor Author

@monishdeb can you review this as a proposed replacement for #10539 - note that your commit is more-or-less-yours with some refactoring added but my 2 are logic changes from yours.

@monishdeb
Copy link
Member

@eileenmcnaughton I agree with the final patch. Thanks a lot :)

Tested on my local, working fine :
image
Sooner or later I will submit PR to make _checkFinancialTrxn(..) readable as per checkFinancialTrxnPaymentInstrumentChange(...)

Should I merge it then?

}
elseif ((!CRM_Utils_System::isNull($params['payment_instrument_id']) &&
!CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id)) &&
$params['contribution']->payment_instrument_id != $params['prevContribution']->payment_instrument_id
Copy link
Contributor

Choose a reason for hiding this comment

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

checking non null value for payment_instrument_id from $params['payment_instrument_id'] and $params['prevContribution']->payment_instrument_id, but in next line comparing payment_instrument from
$params['contribution']->payment_instrument_id

Copy link
Member

@monishdeb monishdeb Sep 13, 2017

Choose a reason for hiding this comment

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

@sunilpawar we are still comparing payment_instrument_id of 'contribution' and 'prevContribution' respectively. On which line we are comparing the payment_instrument_id with name payment_instrument ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@monishdeb can we connect Skype? i already send skype request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was something well spotted by @sunilpawar & this should be merged
#10980

@colemanw colemanw merged commit 95e42bb into civicrm:master Sep 13, 2017
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Sep 13, 2017
sunilpawar pushed a commit to cividesk/civicrm-core that referenced this pull request Sep 14, 2017
Get changes from civicrm#10920
with additional changes for recurring payment.
seamuslee001 pushed a commit to seamuslee001/civicrm-core that referenced this pull request Oct 12, 2017
sunilpawar pushed a commit to cividesk/civicrm-core that referenced this pull request Mar 14, 2018
Get changes from civicrm#10920
with additional changes for recurring payment.
sunilpawar pushed a commit to cividesk/civicrm-core that referenced this pull request Dec 3, 2018
Get changes from civicrm#10920
with additional changes for recurring payment.
sunilpawar pushed a commit to cividesk/civicrm-core that referenced this pull request Feb 27, 2019
Get changes from civicrm#10920
with additional changes for recurring payment.
yashodha pushed a commit to cividesk/civicrm-core that referenced this pull request Oct 18, 2019
Get changes from civicrm#10920
with additional changes for recurring payment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants