From 790552029e5b0c7248d19b9e8f51c32b49864703 Mon Sep 17 00:00:00 2001 From: timkuehn Date: Sun, 8 Dec 2024 10:42:21 -0600 Subject: [PATCH 1/3] added leadeds change to move promote to follow DDD principles --- app/controllers/entities/leads_controller.rb | 7 +++--- app/helpers/lead_promotion_helper.rb | 23 ++++++++++++++++++++ app/helpers/leads_helper.rb | 3 ++- app/models/entities/lead.rb | 16 +------------- 4 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 app/helpers/lead_promotion_helper.rb diff --git a/app/controllers/entities/leads_controller.rb b/app/controllers/entities/leads_controller.rb index 2c1f54434b..d4c3ce80b4 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 0000000000..b162115e9d --- /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/helpers/leads_helper.rb b/app/helpers/leads_helper.rb index a6e3d67929..07b1d5b0f0 100755 --- a/app/helpers/leads_helper.rb +++ b/app/helpers/leads_helper.rb @@ -83,4 +83,5 @@ def lead_summary(lead) summary << "#{t(:mobile_small)}: #{lead.mobile}" if lead.mobile.present? summary.join(', ') end -end + +end \ No newline at end of file diff --git a/app/models/entities/lead.rb b/app/models/entities/lead.rb index d8e881c3ad..3a0eec06a9 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 From 8010040c4e4b52d7418f1d83f970b3baac4857fb Mon Sep 17 00:00:00 2001 From: timkuehn Date: Sun, 8 Dec 2024 14:23:18 -0600 Subject: [PATCH 2/3] fixing whitespace issue in leads_helper.rb --- app/helpers/leads_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/helpers/leads_helper.rb b/app/helpers/leads_helper.rb index 07b1d5b0f0..2e7f9e9fe9 100755 --- a/app/helpers/leads_helper.rb +++ b/app/helpers/leads_helper.rb @@ -83,5 +83,4 @@ def lead_summary(lead) summary << "#{t(:mobile_small)}: #{lead.mobile}" if lead.mobile.present? summary.join(', ') end - end \ No newline at end of file From 2857cc99a092ea776848ff8ebb8ead06c5fe60b9 Mon Sep 17 00:00:00 2001 From: timkuehn Date: Sun, 8 Dec 2024 14:24:38 -0600 Subject: [PATCH 3/3] fixing whitespace issue in leads_helper.rb end of file --- app/helpers/leads_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/leads_helper.rb b/app/helpers/leads_helper.rb index 2e7f9e9fe9..a6e3d67929 100755 --- a/app/helpers/leads_helper.rb +++ b/app/helpers/leads_helper.rb @@ -83,4 +83,4 @@ def lead_summary(lead) summary << "#{t(:mobile_small)}: #{lead.mobile}" if lead.mobile.present? summary.join(', ') end -end \ No newline at end of file +end