Commit e81d05f2 authored by jitendra's avatar jitendra Committed by totten

CRM-20675: Fix incorrect renewal activity created when membership updated via api

parent 63de7b4d
......@@ -4601,6 +4601,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
'contact_id' => $membership->contact_id,
'is_test' => $membership->is_test,
'membership_type_id' => $membership->membership_type_id,
'membership_activity_status' => 'Completed',
);
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
......
......@@ -189,7 +189,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
);
// 1. Update Schedule Membership Signup/Renwal activity to completed on successful payment of pending membership
// 2. OR Create renewal activity scheduled if its membership renewal will be paid later
if (!empty($activityParams['id']) || $activityType == 'Membership Renewal') {
if (!empty($params['membership_activity_status']) && (!empty($activityParams['id']) || $activityType == 'Membership Renewal')) {
CRM_Activity_BAO_Activity::addActivity($membership, $activityType, $targetContactID, $activityParams);
break;
}
......@@ -1170,6 +1170,7 @@ AND civicrm_membership.is_test = %2";
$currentMembership['today_date'] = $today;
if ($status['id'] !== $currentMembership['status_id']) {
$oldStatus = $currentMembership['status_id'];
$memberDAO = new CRM_Member_DAO_Membership();
$memberDAO->id = $currentMembership['id'];
$memberDAO->find(TRUE);
......@@ -1216,6 +1217,19 @@ AND civicrm_membership.is_test = %2";
else {
$logParams['modified_id'] = $currentMembership['contact_id'];
}
//Create activity for status change.
$allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get');
CRM_Activity_BAO_Activity::addActivity($memberDAO,
'Change Membership Status',
NULL,
array(
'subject' => "Status changed from {$allStatus[$oldStatus]} to {$allStatus[$status['id']]}",
'source_contact_id' => $logParams['modified_id'],
'priority_id' => 'Normal',
)
);
CRM_Member_BAO_MembershipLog::add($logParams, CRM_Core_DAO::$_nullArray);
}
}
......@@ -1946,6 +1960,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND
if (!empty($currentMembership['id'])) {
$ids['membership'] = $currentMembership['id'];
}
$memParams['membership_activity_status'] = ($pending || $isPayLater) ? 'Scheduled' : 'Completed';
}
//CRM-4555
if ($pending) {
......
......@@ -848,6 +848,19 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
);
$result = $this->callAPISuccess('membership', 'create', $params);
//Update Status and check activities created.
$updateStatus = array(
'id' => $result['id'],
'status_id' => 6,
);
$this->callAPISuccess('Membership', 'create', $updateStatus);
$activities = CRM_Activity_BAO_Activity::getContactActivity($this->_contactID);
$this->assertEquals(2, count($activities));
$activityNames = array_flip(CRM_Utils_Array::collect('activity_name', $activities));
$this->assertArrayHasKey('Membership Signup', $activityNames);
$this->assertArrayHasKey('Change Membership Status', $activityNames);
$this->callAPISuccess('Membership', 'Delete', array(
'id' => $result['id'],
));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment