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

dev/core#3084 Bug fix on line item financial types #23295

Merged
merged 1 commit into from
Apr 29, 2022
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
2 changes: 1 addition & 1 deletion CRM/Financial/BAO/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function setOverridableFinancialTypeID(?int $overridableFinancialTypeID):
*
* @var bool
*/
protected $isPermitOverrideFinancialTypeForMultipleLines = TRUE;
protected $isPermitOverrideFinancialTypeForMultipleLines = FALSE;

/**
* @return bool
Expand Down
30 changes: 19 additions & 11 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,17 @@ public function testSubmitRecur(): void {
* @throws \API_Exception
*/
public function testSubmitRecurTwoRows(): void {
$pfvIDs = $this->createMembershipPriceSet();
$this->createMembershipPriceSet();
MembershipType::update()
->addWhere('id', '=', $this->ids['membership_type']['AnnualRollingOrg2'])
->setValues(['frequency_interval' => 1, 'frequency_unit' => 'month', 'auto_renew' => 1])->execute();
$form = $this->getForm();
$form->_mode = 'live';
$priceParams = [
'price_' . $this->getPriceFieldID() => $pfvIDs,
'price_' . $this->getPriceFieldID() => [
$this->ids['PriceFieldValue']['AnnualRollingOrg2'] => 1,
$this->ids['PriceFieldValue']['AnnualRolling'] => 1,
],
'price_set_id' => $this->getPriceSetID(),
'membership_type_id' => NULL,
// Set financial type id to null to check it is retrieved from the price set.
Expand Down Expand Up @@ -1160,8 +1163,6 @@ public function testSubmitRecurCompleteInstant(): void {
* @throws \CiviCRM_API3_Exception
*/
public function testTwoInheritedMembershipsViaPriceSetInBackend(): void {
// @todo figure out why financial validation fails with this test.
$this->isValidateFinancialsOnPostAssert = FALSE;
// Create an organization and give it a "Member of" relationship to $this->_individualId.
$orgID = $this->organizationCreate();
$relationship = $this->callAPISuccess('Relationship', 'create', [
Expand All @@ -1172,7 +1173,7 @@ public function testTwoInheritedMembershipsViaPriceSetInBackend(): void {
]);

// Create two memberships for the organization, via a price set in the back end.
$this->createTwoMembershipsViaPriceSetInBackEnd($orgID);
$this->createTwoMembershipsViaPriceSetInBackEnd($orgID, FALSE);

// Check the primary memberships on the organization.
$orgMembershipResult = $this->callAPISuccess('membership', 'get', [
Expand Down Expand Up @@ -1242,8 +1243,6 @@ public function testTwoInheritedMembershipsViaPriceSetInBackend(): void {
* @throws \CiviCRM_API3_Exception
*/
public function testTwoMembershipsViaPriceSetInBackendWithDiscount(): void {
// @todo figure out how to fix to pass valid financials.
$this->isValidateFinancialsOnPostAssert = FALSE;
// Register buildAmount hook to apply discount.
$this->hookClass->setHook('civicrm_buildAmount', [$this, 'buildAmountMembershipDiscount']);
$this->enableTaxAndInvoicing();
Expand Down Expand Up @@ -1364,15 +1363,19 @@ protected function getBaseSubmitParams(): array {
* create two memberships for the same individual, via a price set in the back end.
*
* @param int $contactId Id of contact on which the memberships will be created.
* @param bool $isTaxEnabled
* Is tax enabled for the Member Dues financial type.
* Note that currently this ALSO assumes a discount has been
* applied - this overloading would ideally be cleaned up.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function createTwoMembershipsViaPriceSetInBackEnd($contactId): void {
protected function createTwoMembershipsViaPriceSetInBackEnd(int $contactId, $isTaxEnabled = TRUE): void {
$form = $this->getForm();
$form->preProcess();
$this->createLoggedInUser();
$pfvIDs = $this->createMembershipPriceSet();
$this->createMembershipPriceSet();

// register for both of these memberships via backoffice membership form submission
$params = [
Expand All @@ -1381,14 +1384,19 @@ protected function createTwoMembershipsViaPriceSetInBackEnd($contactId): void {
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
"price_" . $this->getPriceFieldID() => $pfvIDs,
'price_' . $this->getPriceFieldID() => [
$this->ids['PriceFieldValue']['AnnualRollingOrg2'] => 1,
$this->ids['PriceFieldValue']['AnnualRolling'] => 1,
],
// $15 for discounted goat + $259 = $274 + $27.4 in tax.
// or without tax (and without discount) $279.
'total_amount' => $isTaxEnabled ? 301.4 : 279,
'price_set_id' => $this->getPriceSetID(),
'membership_type_id' => [1 => 0],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
'source' => '',
'total_amount' => '30.00',
//Member dues, see data.xml
'financial_type_id' => '2',
'soft_credit_type_id' => '',
Expand Down
10 changes: 2 additions & 8 deletions tests/phpunit/CRMTraits/Financial/PriceSetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ protected function createContributionWithTwoLineItemsAgainstPriceSet($params, ar
*
* The price field is of type checkbox and each price-option
* corresponds to a membership type
*
* @return array
*/
protected function createMembershipPriceSet(): array {
protected function createMembershipPriceSet(): void {
$this->ids['PriceSet']['membership'] = (int) $this->callAPISuccess('PriceSet', 'create', [
'is_quick_config' => 0,
'extends' => 'CiviMember',
Expand All @@ -109,15 +107,11 @@ protected function createMembershipPriceSet(): array {
'price_field_id' => $this->ids['PriceField']['membership'],
'label' => array_shift($labels),
'amount' => array_shift($amounts),
'financial_type_id' => 'Donation',
'financial_type_id' => 'Member Dues',
'membership_type_id' => $membershipTypeID,
'membership_num_terms' => array_shift($membershipNumTerms),
])['id'];
}
return [
$this->ids['PriceFieldValue']['AnnualRollingOrg2'] => 1,
$this->ids['PriceFieldValue']['AnnualRolling'] => 1,
];
}

/**
Expand Down