Fix pledge action on failed/ cancelled contribution
In digging into #927 (closed) the pledge action appears to be incorrect to me when a contribution is cancelled or fails.
Currently there is a call to update the pledge which might reset it's status back to overdue or whatever. However if the pledge has 4 payments one of those is still attached to the failed payment and is not available in the UI to have a new payment added to it. It is effectively voided rather than released and needs a database intervention.
This is a pretty obscure scenario so rarely reached. However, I propose that it should be
- if a contribution attached to a plege payment is cancelled or fails then the contribution should be unattached (contribution_id set to NULL) and the pledge_payment field actual_amount reset to null and pledge payment status reset to Pending .
- I think this can be done whenever a contribution is updated with a status of failed or cancelled and there is a pledge payment related to it (this means we are saying we would clean up on null edit - which we do with a number of other things we deem to be part of the data model and we don't have to look up so see if status is changing - just that status is cancelled/failed & the pledge_payment exists).
- I think this should be moved back out of the extension into being called directly from contibution.create action. The reason is that I think this is actually our data model as opposed to a business process. The way the UI works & the fact no additional payment row is created suggests there was never an intent to have non-payments assigned to pledge payment rows.
Edited by eileen