Class: OpportunityObserver
- Inherits:
-
ActiveRecord::Observer
- Object
- ActiveRecord::Observer
- OpportunityObserver
- Defined in:
- app/models/observers/opportunity_observer.rb
Overview
Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Constant Summary collapse
- @@opportunities =
{}
Instance Method Summary collapse
Instance Method Details
#after_create(item) ⇒ Object
23 24 25 26 27 |
# File 'app/models/observers/opportunity_observer.rb', line 23 def after_create(item) if item.campaign && item.stage == "won" update_campaign_revenue(item.campaign, (item.amount || 0) - (item.discount || 0)) end end |
#after_update(item) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/observers/opportunity_observer.rb', line 33 def after_update(item) original = @@opportunities.delete(item.id) if original if original.stage != "won" && item.stage == "won" # :other to :won -- add to total campaign revenue. update_campaign_revenue(item.campaign, (item.amount || 0) - (item.discount || 0)) return log_activity(item, :won) elsif original.stage == "won" && item.stage != "won" # :won to :other -- substract from total campaign revenue. update_campaign_revenue(original.campaign, -((original.amount || 0) - (original.discount || 0))) end end end |
#before_update(item) ⇒ Object
29 30 31 |
# File 'app/models/observers/opportunity_observer.rb', line 29 def before_update(item) @@opportunities[item.id] = Opportunity.find(item.id).freeze end |