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

Get the template contribution instead of the first contribution when using repeattransaction #17455

Closed

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Jun 1, 2020

Overview

When calling repeattransaction we should be preferring the template contribution (and using the function in CRM_Contribute_BAO_ContributionRecur to get the correct template contribution).
Currently we're using the first contribution.

Logic should be: template contribution ?? latest contribution.

Before

Contribution.repeattransaction uses first contribution as template.

After

Contribution.repeattransaction uses standard method to get template contribution.

Technical Details

Switch to standard function.

Comments

@eileenmcnaughton @monishdeb @artfulrobot This came out of #17032 and causes issues such as contribution source text not being what you expect it to be, lineitems matching first contribution instead of latest etc.

@civibot
Copy link

civibot bot commented Jun 1, 2020

(Standard links)

@civibot civibot bot added the master label Jun 1, 2020
@eileenmcnaughton
Copy link
Contributor

Can we get a test on this?

@mattwire mattwire force-pushed the repeattransactiontemplatecontrib branch 2 times, most recently from 2e18711 to b731a08 Compare July 19, 2020 14:59
@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

New zero warnings highscore: no warnings for 2,003 days!

  | Test Result (30 failures / +30)api_v3_ContributionTest.testRepeatTransactionMembershipRenewContributionNotCompleted with data set #1api_v3_ContributionTest.testRepeatTransactionMembershipRenewContributionNotCompleted with data set #3api_v3_ContributionTest.testRepeatTransactionMembershipRenewContributionNotCompleted with data set #5api_v3_ContributionTest.testRepeatTransactionMembershipRenewContributionNotCompleted with data set #8api_v3_ContributionTest.testRepeatTransactionMembershipRenewContributionNotCompleted with data set #10api_v3_ContributionTest.testRepeatTransactionUpdateNextSchedContributionDate with data set "receive_date_includes_time_with_installments"api_v3_ContributionTest.testRepeatTransactionUpdateNextSchedContributionDate with data set "receive_date_includes_time_no_installments"api_v3_ContributionTest.testRepeatTransactionapi_v3_ContributionTest.testRepeatTransactionLineItemsapi_v3_ContributionTest.testRepeatTransactionIsTestShow all failed tests >>>

@eileenmcnaughton
Copy link
Contributor

This is failing tests & has been for a while - but I salvaged the test & put up a passing patch #17972

@mattwire
Copy link
Contributor Author

@eileenmcnaughton I'm going to re-open this. I think we need to work through these test failures as we're passing way too many "contribution" objects around and taking bits from here and there. This PR tries to resolve that early on and make sure we are working with a single, specific contribution.

It also "enforces" the following logic for parameters to Contribution.repeattransaction:

  • If contribution_recur_id is set, find the template contribution based on that and ignore any contribution ID that is passed in.
  • Otherwise use contribution_id as passed.

The rationale behind this is:

  • Sometimes you only have one or the other of those parameters. If you really require that a specific contribution is used when you have a contribution_recur_id then just pre-process and remove the contribution_recur_id and specify the contribution_id that you desire. I've come across various situations where both contribution_id and contribution_recur_id are being passed and was confused as to which would take precedence. The current situation is a mix of "both" and "neither" which is pretty inconsistent.
  • If you pass both, how can you be sure which one the code will use? It makes no sense to use both.
  • Regarding renewal of related entities, that should get calculated either via the recurring contribution or via the existing membership_payment record on the contribution so should work in both cases.

@eileenmcnaughton
Copy link
Contributor

@mattwire if you want to actively work on the test fails it's fine for it to be open and I'll close the ones I re-opened.

However, it's not really the way that I imagine tackling cleaning up this function - which is really to work towards repeatransaction only calling repeatransaction, and not the full completeOrder function - which was the approach I used (ie save the contribution only once, in repeattransaction and not again in the main function). Note that the repeattransaction already takes the line items from the templatecontribution - and that's locked in by tests - so I wouldn't want to change that without a gitlab analysis. Also note that it's not clear to me that we gain much by passing in $contribution to repeattransaction at all.

I had thought the way to proceed was to look at what happens after repeattransaction is called, ensure it's tested & simplify / remove it. I guess in short you want to clean up how we build some variables that I think we should look to eliminate the usage of

However, as with all WIP it should only be open when you are actively working on it since this is the review queue.

@eileenmcnaughton
Copy link
Contributor

@mattwire note that the only time I think 'contribution id as passed' should be used is when it comes in the $input array. Currently we always set original_contribution_id in the $input when it comes from the api

That $input array is passed to the repeattransaction command - so the repeattransaction command could pass that into getTemplateContribution as one of the overrides & that could take precedence over the order already in there.

That leaves the problem that the api is calculating the 'original_contribution_id' when we don't pass it into the api - and a later PR could remove that - but for now it is coming up with the effective same result so it doesn't matter whether it follows sooner or later

@mattwire mattwire force-pushed the repeattransactiontemplatecontrib branch from b731a08 to c6d7b14 Compare July 28, 2020 14:20
@mattwire mattwire added the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Jul 28, 2020
@mattwire
Copy link
Contributor Author

@eileenmcnaughton I see what you mean about original_contribution_id being calculated in the API. I've just pushed another commit that should fix at least some test fails.

@eileenmcnaughton
Copy link
Contributor

hmm - it's worse

@eileenmcnaughton
Copy link
Contributor

I still don't think we should be calculating templateContribution in 2 places - we have everything we need in the repeattransaction function

@eileenmcnaughton eileenmcnaughton added needs-concept-approval needs-to-not-make-tests-fail and removed needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state labels Jul 29, 2020
@eileenmcnaughton
Copy link
Contributor

I removed the needs-work flag & put more specific flags on.

@mattwire mattwire force-pushed the repeattransactiontemplatecontrib branch from c6d7b14 to af256ac Compare July 29, 2020 10:17
@mattwire
Copy link
Contributor Author

Closing pending work on #17994

@mattwire mattwire closed this Jul 31, 2020
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