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-21183: Updating Partially paid contribution to Completed doesn't … #10981

Merged
merged 2 commits into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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