Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-14362

Creating a financial type fails if financial account (INC) already exists.

    Details

      Description

      To Do:

      1) If a financial account exists with same name as financial type that is being created, then create a relationship with that financial_account with the financial type rather than attempting to create it first. Make sure that you don't use the default financial account for a different type of relationship if the pre-existing financial account with same name is not a revenue account. Don't add a revenue account relationship if the pre-existing financial_account is not a revenue account.
      2) Put a unique index on relevant fields to ensure that Financial_type is a unique name and provide a message if creating or updating would lead to a duplicate: "Financial type must have a unique name."

      I have already reproduced this in the public civicrm sandbox at: http://drupal.demo.civicrm.org/civicrm/admin/financial/financialType

      Steps to reproduce:

      1) Go to the screen at: Administer ... CiviContribute ... Financial Types

      2) Click the button "Add Financial Type"

      3) In the "name" field type "Member Dues" or any other name where a Financial Account of type Revenue (INC) already exists.

      4) Click the "Save" button.

      You will see the error message below:

      DB Error: already exists
      Error Details
      Database Error Code: Duplicate entry 'Member Dues' for key 'UI_name', 1062
      Additional Details:
      Array
      (
      [callback] => Array
      (
      [0] => CRM_Core_Error
      [1] => handle
      )

      [code] => -5
      [message] => DB Error: already exists
      [mode] => 16
      [debug_info] => INSERT INTO civicrm_financial_account (name , contact_id , financial_account_type_id , account_type_code , description , is_header_account , is_deductible , is_tax , is_active , is_default ) VALUES ('Member Dues' , 1 , 3 , 'INC' , NULL , 0 , 0 , 0 , 1 , 0 ) [nativecode=1062 ** Duplicate entry 'Member Dues' for key 'UI_name']
      [type] => DB_Error
      [user_info] => INSERT INTO civicrm_financial_account (name , contact_id , financial_account_type_id , account_type_code , description , is_header_account , is_deductible , is_tax , is_active , is_default ) VALUES ('Member Dues' , 1 , 3 , 'INC' , NULL , 0 , 0 , 0 , 1 , 0 ) [nativecode=1062 ** Duplicate entry 'Member Dues' for key 'UI_name']
      [to_string] => [db_error: message="DB Error: already exists" code=-5 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_financial_account (name , contact_id , financial_account_type_id , account_type_code , description , is_header_account , is_deductible , is_tax , is_active , is_default ) VALUES ('Member Dues' , 1 , 3 , 'INC' , NULL , 0 , 0 , 0 , 1 , 0 ) [nativecode=1062 ** Duplicate entry 'Member Dues' for key 'UI_name']"]
      )

      Note: As a side effect the new financial type DOES get created, BUT it has NO relationships to any financial accounts.

      Is it even valid to have 2 or more financial types with identical names? The system is currently allowing this, although it does not allow 2 or more financial accounts with the same name.

        Attachments

        1. CRM-14362_a.PNG
          100 kB
          David Greenberg
        2. CRM-14362_b.PNG
          99 kB
          David Greenberg

          Activity

            People

            • Assignee:
              joemurray Joe Murray
              Reporter:
              sgladstone Sarah Gladstone
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 10 minutes
                10m