[REF] Deprecate calls to createCreditNoteId #15492
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Code cleanup - createCreditNoteId is called from 3 places but only one is necessary, deprecate the other 2.
Before
Calls to createCreditNoteId are distributed & confusing
After
Only one 'active' place - in Contribution::add when the status is updated. The others are deprecated
Technical Details
createCreditNoteId is called from BAO_Contribution::add whenever the contribution
status is 'Cancelled' or 'Refunded. If was not previously called for 'ChargeBack' but it turned out it was later set so ChargeBack handling is move to be included in that call for no change in behaviour.
A few lines later recordFinancialAccounts is called, so by the time recordFinancialAccounts is called
it is already set & the empty check will prevent these lines being hit.
All 4 places where updateFinancialAccounts are called in the
code are from recordFinancialAccounts.
Record financial accounts is called from Contribution Create & Payment create.
contribution.create does not rely on these lines to set the creditnote_id, as discussed.
In the BAO_Payment there are 2 scenarios
It's logically OK for the code to NOT to create a credit note when being called from payment.create
because payment.create is NOT cancelling the contribution or refunding it and the funtion NEVER changes
the contribution status to Refunded, Cancelled, Chargeback (those are 'business' statuses).
Payment.create updates contribution status to reflect a payment has been made - eg change from
Pending to partially paid or various payment-related-statuses to 'Completed'.
ie Payment.create is
whether the payment is being returned due to overpayment or other payment related concerns does
not belong in the payment code.
Payment create never changes contribution
status to Refunded, Cancelled or ChargeBack so the lines would never be hit from payment.create
This leaves us with the conclusion the lines are never hit. For safety/sanity we can deprectate them rather
than remove them by now. That way if the above analysis is wrong a test will fail.
Less likely (given financial test coverage) the deprecation notice will show up in the wild in the next few months.
(It's rather unclear how it DOES fit in since it feels like creditnote_id only applies if the entire
contribution is being refunded & really should be generated at the point at which, for example, the event
fees associated with it are changed - however, complaints to date about creditnote_id have all focussed
on performance issues, not logic issues
Comments
@bjendres @monishdeb it turns out we can get the createCreditNoteID to being something that could just be called from a pre hook as the other places in the code are not needed after some digging