fatfreecrm / fat_free_crm

Ruby on Rails CRM platform
http://www.fatfreecrm.com
Other
3.58k stars 1.32k forks source link

Creating Contact with creating new account can fail on validation errors #524

Open klyonrad opened 7 years ago

klyonrad commented 7 years ago
  1. /contacts
  2. Create Contact
  3. Enter required data
  4. Enter new_company in Account field
  5. Submit Form

consequences:

  Rendered /Users/dkd-luedicke/.rvm/gems/ruby-2.2.4/bundler/gems/fat_free_crm-348ff2d77b41/app/views/contacts/_index_brief.html.haml (31.4ms)
  Rendered /Users/dkd-luedicke/.rvm/gems/ruby-2.2.4/bundler/gems/fat_free_crm-348ff2d77b41/app/views/contacts/_contact.html.haml (50.0ms)
  Rendered /Users/dkd-luedicke/.rvm/gems/ruby-2.2.4/bundler/gems/fat_free_crm-348ff2d77b41/app/views/contacts/create.js.haml (77.9ms)

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"accounts", :id=>#<Account id: nil, user_id: 32, assigned_to: nil, name: "new_account", access: "Public", website: nil, toll_free_phone: nil, phone: nil, fax: nil, deleted_at: nil, created_at: nil, updated_at: nil, email: nil, background_info: nil, rating: 0, category: nil, subscribed_users: #<Set: {}>, cf_ustidnr: nil, cf_phone_2: nil, cf_phone_2_2: nil, cf_day_rate: nil, cf_payment_method: nil, cf_status: nil, cf_type: nil, custom_system_client_id: nil>} missing required keys: [:id]):
    16:   .indentslim
    17:     = link_to_if can?(:read, contact), contact.full_name(@current_user.preference[:contacts_naming]), contact
    18:     %tt
    19:       = brief_account_info(contact)
    20: 
    21:       - if (lead = contact.lead) and lead.referred_by?
    22:         &ndash;
klyonrad commented 7 years ago

Digging deeper I found out that the accont is not saved due to validation errors - that is an effect of custom fields that we have.

and the method

  def self.create_or_select_for(model, params)
    if params[:id].present?
      account = Account.find(params[:id])
    else
      account = Account.new(params)
      if account.access != "Lead" || model.nil?
        account.save
      else
        account.save_with_model_permissions(model)
      end
    end
    account
  end

does not handle errors that could happen on .save

johnnyshields commented 6 years ago

Same issue as: https://github.com/fatfreecrm/fat_free_crm/issues/253 - Can't convert a lead to a contact with a new Account which has mandatory custom fields