Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
Partially resolve #44 by working around financial type checking in pr…
Browse files Browse the repository at this point in the history
…ice field value BAO
  • Loading branch information
seamuslee001 committed Jan 13, 2020
1 parent 53a2b24 commit 7005762
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions CRM/Lineitemedit/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,13 +952,20 @@ public static function createPriceFieldByContributionID($contributionID) {
'visibility_id' => "admin",
]);

$newPriceFieldValue = civicrm_api3('PriceFieldValue', 'create', [
$ftActive = civicrm_api3('FinancialType', 'getsingle', ['id' => $previousLineItem['financial_type_id']])['is_active'];
$priceFieldValueParams = [
'label' => ts('Additional Lineitem ' . $totalPF),
'price_field_id' => $newPriceField['id'],
'amount' => 1.00,
'financial_type_id' => civicrm_api3('PriceFieldValue', 'getvalue', ['id' => $previousLineItem['price_field_value_id'], 'return' => 'financial_type_id']),
]);

'financial_type_id' => $previousLineItem['financial_type_id'],
];
if (!$ftActive) {
$priceFieldValueParams['is_active'] = 0;
}
$newPriceFieldValue = civicrm_api3('PriceFieldValue', 'create', $priceFieldValueParams);
if (!$ftActive) {
CRM_Price_BAO_PriceFieldValue::setIsActive($newPriceFieldValue['id'], 1);
}
return [$newPriceField['id'], $newPriceFieldValue['id']];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Lineitemedit/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testGeneratePriceField() {
$this->assertEquals('additional_lineitem_1', $newPriceField['name']);
$newPriceFieldValue = $this->callAPISuccess('PriceFieldValue', 'getsingle', ['id' => $result[1]]);
$this->assertEquals('additional_lineitem_1', $newPriceFieldValue['name']);
$this->assertEuqals($this->_financialTypeId, $newPriceFieldValue['financial_type_id']);
$this->assertEquals($this->_financialTypeId, $newPriceFieldValue['financial_type_id']);
CRM_Financial_BAO_FinancialType::setIsActive($this->_financialTypeId, 1);
$this->callAPISuccess('System', 'flush', []);
$this->callAPISuccess('PriceFieldValue', 'delete', ['id' => $newPriceFieldValue['id']]);
Expand Down

0 comments on commit 7005762

Please sign in to comment.