From a900072cb8009b45f734359ce0ee57c0d8e7563a Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 27 Jun 2018 05:01:34 +0530 Subject: [PATCH] Moved code from form layer to BAO and used api instead of BAO function --- CRM/Admin/Form/Options.php | 12 ------------ CRM/Core/BAO/OptionValue.php | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 1f2821d399..fd4aa9dfa1 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -486,18 +486,6 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { $optionValue = CRM_Core_OptionValue::addOptionValue($params, $this->_gName, $this->_action, $this->_id); - // CRM-11516 - if (!empty($params['financial_account_id'])) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); - $params = array( - 'entity_table' => 'civicrm_option_value', - 'entity_id' => $optionValue->id, - 'account_relationship' => $relationTypeId, - 'financial_account_id' => $params['financial_account_id'], - ); - CRM_Financial_BAO_FinancialTypeAccount::add($params); - } - CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array( 1 => $this->_gLabel, 2 => $optionValue->label, diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php index cfb4b45dce..98a331c6f4 100644 --- a/CRM/Core/BAO/OptionValue.php +++ b/CRM/Core/BAO/OptionValue.php @@ -243,6 +243,29 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue { $optionValue->id = $id; $optionValue->save(); CRM_Core_PseudoConstant::flush(); + + // Create relationship for payment intrument options + if (!empty($params['financial_account_id'])) { + $optionName = civicrm_api3('OptionGroup', 'getvalue', [ + 'return' => 'name', + 'id' => $params['option_group_id'], + ]); + // Only create relationship for payment intrument options + if ($optionName == 'payment_instrument') { + $relationTypeId = civicrm_api3('OptionValue', 'getvalue', [ + 'return' => 'value', + 'option_group_id' => 'account_relationship', + 'name' => 'Asset Account is', + ]); + $params = [ + 'entity_table' => 'civicrm_option_value', + 'entity_id' => $optionValue->id, + 'account_relationship' => $relationTypeId, + 'financial_account_id' => $params['financial_account_id'], + ]; + CRM_Financial_BAO_FinancialTypeAccount::add($params); + } + } return $optionValue; } -- 2.25.1