app/models/entities/lead.rb in fat_free_crm-0.18.2 vs app/models/entities/lead.rb in fat_free_crm-0.19.0
- old
+ new
@@ -37,24 +37,24 @@
# background_info :string(255)
# skype :string(128)
#
class Lead < ActiveRecord::Base
- belongs_to :user
- belongs_to :campaign
- belongs_to :assignee, class_name: "User", foreign_key: :assigned_to
+ belongs_to :user, optional: true # TODO: Is this really optional?
+ belongs_to :campaign, optional: true # TODO: Is this really optional?
+ belongs_to :assignee, class_name: "User", foreign_key: :assigned_to, optional: true # TODO: Is this really optional?
has_one :contact, dependent: :nullify # On destroy keep the contact, but nullify its lead_id
has_many :tasks, as: :asset, dependent: :destroy # , :order => 'created_at DESC'
has_one :business_address, -> { where "address_type='Business'" }, dependent: :destroy, as: :addressable, class_name: "Address"
has_many :addresses, dependent: :destroy, as: :addressable, class_name: "Address" # advanced search uses this
has_many :emails, as: :mediator
serialize :subscribed_users, Set
- accepts_nested_attributes_for :business_address, allow_destroy: true
+ accepts_nested_attributes_for :business_address, allow_destroy: true, reject_if: proc { |attributes| Address.reject_address(attributes) }
- scope :state, ->(filters) {
+ scope :state, lambda { |filters|
where(['status IN (?)' + (filters.delete('other') ? ' OR status IS NULL' : ''), filters])
}
scope :converted, -> { where(status: 'converted') }
scope :for_campaign, ->(id) { where(campaign_id: id) }
scope :created_by, ->(user) { where(user_id: user.id) }
@@ -121,11 +121,11 @@
# 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] ? params[:account] : {}
- opportunity_params = params[:opportunity] ? params[:opportunity] : {}
+ 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)