diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 7af0b6c01049dff61661e4301e14001b23710e1d..67c95393882e83f44754e9de1a7e7b6f3258b6c4 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -1736,6 +1736,10 @@ SELECT relationship_type_id, relationship_direction //contact before creating new membership record. CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId, $relatedContactId); } + //skip status calculation for pay later memberships. + if (!empty($membershipValues['status_id']) && $membershipValues['status_id'] == $pendingStatusId) { + $membershipValues['skipStatusCal'] = TRUE; + } // check whether we have some related memberships still available $query = " diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 2f5c6ed8f40b063f65c1b80f4549633edfb64bd0..f58ce8bd2de605b527a6e7c58241287580c994b7 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -631,6 +631,28 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(0, $result['count']); + //Create pay_later membership for organization. + $employerId[2] = $this->organizationCreate(array(), 1); + $params = array( + 'contact_id' => $employerId[2], + 'membership_type_id' => $membershipTypeId, + 'source' => 'Test pay later suite', + 'is_pay_later' => 1, + 'status_id' => 5, + ); + $organizationMembership = CRM_Member_BAO_Membership::add($params); + $organizationMembershipID = $organizationMembership->id; + $memberContactId[3] = $this->individualCreate(array('employer_id' => $employerId[2]), 0); + // Check that the employee inherited the membership + $params = array( + 'contact_id' => $memberContactId[3], + 'membership_type_id' => $membershipTypeId, + ); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(1, $result['count']); + $result = $result['values'][$result['id']]; + $this->assertEquals($organizationMembershipID, $result['owner_membership_id']); + // Set up params for enable/disable checks $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1])); $params = array(