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 1 commit
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
6 changes: 4 additions & 2 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1832,16 +1832,18 @@ public static function transitionComponents($params, $processContributionObject
}
}
elseif ($contributionStatusId == array_search('Completed', $contributionStatuses)) {
$pending = array_search('Pending', $contributionStatuses);
$partaillyPaid = array_search('Partially paid', $contributionStatuses);

// only pending contribution related object processed.
if ($previousContriStatusId &&
($previousContriStatusId != array_search('Pending', $contributionStatuses))
(!in_array($previousContriStatusId, array($pending, $partaillyPaid)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about (!in_array($contributionStatuses[$previousContriStatusId], array('Pending', 'Partially paid'))) ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

) {
// this is case when we already processed contribution object.
return $updateResult;
}
elseif (!$previousContriStatusId &&
$contribution->contribution_status_id != array_search('Pending', $contributionStatuses)
(!in_array($contribution->contribution_status_id, array($pending, $partaillyPaid)))
) {
// 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' => 8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use labels??

));
$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' => 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use labels??

'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