Skip to content

Commit 7b507a0

Browse files
author
Mike Dvorkin
committed
Display newly created opportunity when converting lead from campaign page
[fatfreecrm#121 state:open]
1 parent 45b3315 commit 7b507a0

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

CHANGELOG

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Fri, Nov 6, 2009
88
---------------------------------------------------------------------
99
- Adjust total campaign revenue when related opportunity is won (LH #121).
1010
- Refresh campaign sidebar when updating related opportunity (LH #121).
11-
- Update campaign summary when rejecting or converting related lead (LH #121).
11+
- Refresh campaign sidebar when rejecting or converting related lead (LH #121).
12+
- Display newly created opportunity when converting lead from campaign page (LH #121).
1213

1314
Thu, Nov 5, 2009
1415
---------------------------------------------------------------------

app/controllers/leads_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def promote
178178
@users = User.except(@current_user).all
179179
@account, @opportunity, @contact = @lead.promote(params)
180180
@accounts = Account.my(@current_user).all(:order => "name")
181+
@stage = Setting.as_hash(:opportunity_stage)
181182

182183
respond_to do |format|
183184
if @account.errors.empty? && @opportunity.errors.empty? && @contact.errors.empty?

app/models/activity_observer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ActivityObserver < ActiveRecord::Observer
2424
def after_create(subject)
2525
log_activity(subject, :created)
2626
if subject.is_a?(Opportunity) && subject.campaign && subject.stage == "won"
27-
update_campaign_revenue(subject.campaign, subject.amount - subject.discount)
27+
update_campaign_revenue(subject.campaign, (subject.amount || 0) - (subject.discount || 0))
2828
end
2929
end
3030

app/views/leads/promote.js.rjs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if @lead.status == "converted"
1212
page << refresh_sidebar(:index, :filters)
1313
elsif called_from_landing_page?("campaigns")
1414
page << refresh_sidebar_for(:campaigns, :show, :summary)
15+
if @opportunity
16+
page.insert_html :top, :opportunities, :partial => "opportunities/opportunity", :collection => [ @opportunity ]
17+
end
1518
else
1619
page[:recently].replace :partial => "common/recently"
1720
end

spec/controllers/leads_controller_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ def get_data_for_sidebar
688688
assigns[:accounts].should == [ @account ]
689689
assigns[:opportunity].should == @opportunity
690690
assigns[:contact].should == @contact
691+
assigns[:stage].should be_instance_of(Hash)
691692
response.should render_template("leads/promote")
692693
end
693694

spec/views/leads/promote.rjs_spec.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@
6363
end
6464
end
6565

66-
describe "from related asset page -" do
66+
describe "from related campaign page -" do
6767
before(:each) do
6868
request.env["HTTP_REFERER"] = "http://localhost/campaigns/123"
69+
assigns[:campaign] = Factory(:campaign)
70+
assigns[:stage] = {}
71+
assigns[:opportunity] = @opportunity = Factory(:opportunity)
6972
end
7073

7174
it "should replace [Convert Lead] with lead partial and highligh it" do
@@ -77,7 +80,6 @@
7780
end
7881

7982
it "should update campaign sidebar" do
80-
assigns[:campaign] = campaign = Factory(:campaign)
8183
render "leads/promote.js.rjs"
8284

8385
response.should have_rjs("sidebar") do |rjs|
@@ -86,6 +88,14 @@
8688
end
8789
end
8890

91+
it "should insert new opportunity if any" do
92+
render "leads/promote.js.rjs"
93+
94+
response.should have_rjs(:insert, :top) do |rjs|
95+
with_tag("li[id=opportunity_#{@opportunity.id}]")
96+
end
97+
end
98+
8999
end
90100
end # no errors
91101

0 commit comments

Comments
 (0)