diff --git a/app/controllers/entities/leads_controller.rb b/app/controllers/entities/leads_controller.rb index 2c1f54434..d4c3ce80b 100644 --- a/app/controllers/entities/leads_controller.rb +++ b/app/controllers/entities/leads_controller.rb @@ -6,6 +6,7 @@ # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ class LeadsController < EntitiesController + include LeadPromotionHelper before_action :get_data_for_sidebar, only: :index autocomplete :account, :name, full: true @@ -115,8 +116,8 @@ def convert # PUT /leads/1/promote #---------------------------------------------------------------------------- - def promote - @account, @opportunity, @contact = @lead.promote(params.permit!) +def promote + @account, @opportunity, @contact = promote_lead(@lead, params.permit!) @accounts = Account.my(current_user).order('name') @stage = Setting.unroll(:opportunity_stage) @@ -270,4 +271,4 @@ def update_sidebar end ActiveSupport.run_load_hooks(:fat_free_crm_leads_controller, self) -end +end \ No newline at end of file diff --git a/app/helpers/lead_promotion_helper.rb b/app/helpers/lead_promotion_helper.rb new file mode 100644 index 000000000..b162115e9 --- /dev/null +++ b/app/helpers/lead_promotion_helper.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Copyright (c) 2008-2013 Michael Dvorkin and contributors. +# +# Fat Free CRM is freely distributable under the terms of MIT license. +# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php +#------------------------------------------------------------------------------ +module LeadPromotionHelper + # Promote the lead by creating a contact and optional opportunity. Upon + # successful promotion Lead status gets set to :converted. + #---------------------------------------------------------------------------- + def promote_lead(lead, params) + account_params = params[:account] || {} + opportunity_params = params[:opportunity] || {} + + account = Account.create_or_select_for(lead, account_params) + opportunity = Opportunity.create_for(lead, account, opportunity_params) + contact = Contact.create_for(lead, account, opportunity, params) + + [account, opportunity, contact] + end + end + \ No newline at end of file diff --git a/app/models/entities/lead.rb b/app/models/entities/lead.rb index d8e881c3a..3a0eec06a 100644 --- a/app/models/entities/lead.rb +++ b/app/models/entities/lead.rb @@ -119,20 +119,6 @@ def update_with_lead_counters(attributes) end end - # Promote the lead by creating contact and optional opportunity. Upon - # successful promotion Lead status gets set to :converted. - #---------------------------------------------------------------------------- - def promote(params) - account_params = params[:account] || {} - opportunity_params = params[:opportunity] || {} - - account = Account.create_or_select_for(self, account_params) - opportunity = Opportunity.create_for(self, account, opportunity_params) - contact = Contact.create_for(self, account, opportunity, params) - - [account, opportunity, contact] - end - #---------------------------------------------------------------------------- def convert update_attribute(:status, "converted") @@ -184,4 +170,4 @@ def users_for_shared_access end ActiveSupport.run_load_hooks(:fat_free_crm_lead, self) -end +end \ No newline at end of file