CRM-19739: New Account Relationship Option Screen does not show exception
authorJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 13 Jul 2017 11:06:25 +0000 (16:36 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 13 Jul 2017 11:23:13 +0000 (16:53 +0530)
CRM/Financial/BAO/FinancialTypeAccount.php
CRM/Financial/Form/FinancialTypeAccount.php
tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php

index 92b8aa8d6199e39f2ca84770126e0e5c122222e9..c0febdc9e03e4464703ebd5622c3e2573ecfc982 100644 (file)
@@ -91,7 +91,10 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
       $financialTypeAccount->find(TRUE);
     }
     $financialTypeAccount->copyValues($params);
-    self::validateRelationship($financialTypeAccount);
+    $valid = self::validateRelationship($financialTypeAccount);
+    if (!$valid) {
+      return FALSE;
+    }
     $financialTypeAccount->save();
     return $financialTypeAccount;
   }
@@ -102,6 +105,7 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin
    * @param int $financialTypeAccountId
    * @param int $accountId
    *
+   * @return bool
    */
   public static function del($financialTypeAccountId, $accountId = NULL) {
     // check if financial type is present
@@ -282,8 +286,10 @@ WHERE cog.name = 'payment_instrument' ";
       $params = array(
         1 => $accountRelationships[$financialTypeAccount->account_relationship],
       );
-      throw new Exception(ts("This financial account cannot have '%1' relationship.", $params));
+      CRM_Core_Session::setStatus(ts('This financial account cannot have \'%1\' relationship.', $params), ts('Error'), 'error');
+      return FALSE;
     }
+    return TRUE;
   }
 
 }
index e686724d37010168cbf74d14d8297d05360e4a8a..d1f8cb50ffeee4e4bc49d2360454608157484ad7 100644 (file)
@@ -300,7 +300,9 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form {
         $params['entity_id'] = $this->_aid;
       }
       $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids);
-      CRM_Core_Session::setStatus(ts('The financial type Account has been saved.'));
+      if ($financialTypeAccount) {
+        CRM_Core_Session::setStatus(ts('The financial type Account has been saved.'));
+      }
     }
 
     $buttonName = $this->controller->getButtonName();
index 88172853d05d21f4af7d1cd58d3df536c20261cb..c29b51875dd697cc7a613d49394d1a5bfce6d4b3 100644 (file)
@@ -131,14 +131,8 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase {
     $financialAccountType->entity_id = array_search('Member Dues', $financialType);
     $financialAccountType->account_relationship = array_search('Credit/Contra Revenue Account is', $accountRelationships);
     $financialAccountType->financial_account_id = array_search('Liability', $financialAccount);
-    try {
-      CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType);
-      $this->fail("Missed expected exception");
-    }
-    catch (Exception $e) {
-      $this->assertTrue(TRUE, 'Received expected exception');
-      $this->assertEquals($e->getMessage(), "This financial account cannot have 'Credit/Contra Revenue Account is' relationship.");
-    }
+    $valid = CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType);
+    $this->assertFalse($valid);
   }
 
   /**