Class: Insightly::Opportunity

Inherits:
ReadWrite show all
Includes:
LinkHelper, TagHelper
Defined in:
lib/insightly/opportunity.rb

Constant Summary collapse

CUSTOM_FIELD_PREFIX =
"OPPORTUNITY_FIELD"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TagHelper

#add_tag, #tags, #tags=

Methods included from LinkHelper

#add_link, #contact_ids, #contacts, #links, #links=, #opportunities, #opportunity_ids, #organisation_ids, #organisations

Methods inherited from ReadWrite

#post_collection, #put_collection, #to_json, #update_data

Methods inherited from Base

#==, all, api_field, #build, build, #config, custom_fields, date_to_insightly, #get_collection, #initialize, #load, #process, #reload, #remote_data, #remote_id, #remote_id=, #remote_id?, #remote_id_field, #to_json, #url_base

Constructor Details

This class inherits a constructor from Insightly::Base

Class Method Details

.find_by_name(name) ⇒ Object



77
78
79
80
81
82
# File 'lib/insightly/opportunity.rb', line 77

def self.find_by_name(name)
  Insightly::Opportunity.all.each do |o|
    return o if o.opportunity_name && o.opportunity_name == name
  end
  nil
end

.search_by_name(name) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/insightly/opportunity.rb', line 84

def self.search_by_name(name)
  list = []
  Insightly::Opportunity.all.each do |o|
    if o.opportunity_name && o.opportunity_name.match(name)
      list << o
    end
  end
  list
end

Instance Method Details



107
108
109
110
111
# File 'lib/insightly/opportunity.rb', line 107

def fix_for_link(link)
  #This needs to auto set the org id on the item
  link.opportunity_id = self.remote_id
  link
end

#saveObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/insightly/opportunity.rb', line 94

def save
  creating = remote_id ? false : true

  super
  if creating
    @state_reason = Insightly::OpportunityStateReason.find_by_state_reason("Open", "Created by API")

    if @state_reason
      put_collection("OpportunityStateChange/#{opportunity_id}", @state_reason.remote_data.to_json)
    end
  end

end

#tasksObject



40
41
42
43
44
45
46
# File 'lib/insightly/opportunity.rb', line 40

def tasks
  list = []
  Insightly::TaskLink.search_by_opportunity_id(opportunity_id).each do |x|
    list << Insightly::Task.new(x.task_id)
  end
  list
end