Skip to content

Commit

Permalink
Merge pull request #10981 from jitendrapurohit/CRM-21183
Browse files Browse the repository at this point in the history
CRM-21183: Updating Partially paid contribution to Completed doesn't …
  • Loading branch information
eileenmcnaughton authored Sep 15, 2017
2 parents 8cce260 + 1e9b7f9 commit 2feb8bd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1835,13 +1835,13 @@ public static function transitionComponents($params, $processContributionObject

// only pending contribution related object processed.
if ($previousContriStatusId &&
($previousContriStatusId != array_search('Pending', $contributionStatuses))
!in_array($contributionStatuses[$previousContriStatusId], array('Pending', 'Partially paid'))
) {
// this is case when we already processed contribution object.
return $updateResult;
}
elseif (!$previousContriStatusId &&
$contribution->contribution_status_id != array_search('Pending', $contributionStatuses)
!in_array($contributionStatuses[$contribution->contribution_status_id], array('Pending', 'Partially paid'))
) {
// this is case when we are going to process contribution object later.
return $updateResult;
Expand Down
40 changes: 40 additions & 0 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,46 @@ public function testSubmitPayLaterWithBilling() {
));
}

/**
* Test if membership is updated to New after contribution
* is updated from Partially paid to Completed.
*/
public function testSubmitUpdateMembershipFromPartiallyPaid() {
$memStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate');

//Perform a pay later membership contribution.
$this->testSubmitPayLaterWithBilling();
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
$this->assertEquals($membership['status_id'], array_search('Pending', $memStatus));
$contribution = $this->callAPISuccessGetSingle('MembershipPayment', array(
'membership_id' => $membership['id'],
));

//Update contribution to Partially paid.
$prevContribution = $this->callAPISuccess('Contribution', 'create', array(
'id' => $contribution['contribution_id'],
'contribution_status_id' => 'Partially paid',
));
$prevContribution = $prevContribution['values'][1];

//Complete the contribution from offline form.
$form = new CRM_Contribute_Form_Contribution();
$submitParams = array(
'id' => $contribution['contribution_id'],
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
'price_set_id' => 0,
);
$fields = array('total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id');
foreach ($fields as $val) {
$submitParams[$val] = $prevContribution[$val];
}
$form->testSubmit($submitParams, CRM_Core_Action::UPDATE);

//Check if Membership is updated to New.
$membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
$this->assertEquals($membership['status_id'], array_search('New', $memStatus));
}

/**
* Test the submit function of the membership form.
*/
Expand Down

0 comments on commit 2feb8bd

Please sign in to comment.