Class: MoveToGo::Deal
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- MoveToGo::Deal
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/move-to-go/model/deal.rb
Instance Attribute Summary collapse
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#customer ⇒ Object
Gets the customer to which this deal belongs.
-
#customer_contact ⇒ Object
Returns the value of attribute customer_contact.
-
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes included from ModelHasTags
Instance Method Summary collapse
-
#description ⇒ Object
:attr_accessor: description.
-
#id ⇒ Object
:attr_accessor: id.
-
#initialize(opt = nil) ⇒ Deal
constructor
A new instance of Deal.
-
#integration_id ⇒ Object
:attr_accessor: integration_id.
- #is_integer?(value) ⇒ Boolean
-
#name ⇒ Object
:attr_accessor: name.
-
#offer_date ⇒ Object
:attr_accessor: offer_date.
-
#order_date ⇒ Object
:attr_accessor: order_date.
-
#probability ⇒ Object
:attr_accessor: probability.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
-
#status ⇒ Object
:attr_accessor: status Get/set the deal’s status.
-
#status=(status) ⇒ Object
Sets the deal’s status to the specifed status.
- #to_reference ⇒ Object
- #to_s ⇒ Object
- #validate(labels = nil) ⇒ Object
- #with_status {|@status| ... } ⇒ Object
Methods included from SerializeHelper
#get_import_rows, #serialize, #serialize_to_file
Methods included from ModelHasCustomFields
Methods included from ModelHasTags
Methods inherited from CanBecomeImmutable
immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable
Constructor Details
#initialize(opt = nil) ⇒ Deal
Returns a new instance of Deal.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/move-to-go/model/deal.rb', line 94 def initialize(opt = nil) if !opt.nil? serialize_variables.each do |myattr| val = opt[myattr[:id]] instance_variable_set("@" + myattr[:id].to_s, val) if val != nil end end set_tag 'Import' end |
Instance Attribute Details
#custom_values ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
69 70 71 |
# File 'lib/move-to-go/model/deal.rb', line 69 def custom_values @custom_values end |
#customer ⇒ Object
Gets the customer to which this deal belongs
183 184 185 |
# File 'lib/move-to-go/model/deal.rb', line 183 def customer @customer end |
#customer_contact ⇒ Object
Returns the value of attribute customer_contact.
71 72 73 |
# File 'lib/move-to-go/model/deal.rb', line 71 def customer_contact @customer_contact end |
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
71 72 73 |
# File 'lib/move-to-go/model/deal.rb', line 71 def responsible_coworker @responsible_coworker end |
#value ⇒ Object
Returns the value of attribute value.
71 72 73 |
# File 'lib/move-to-go/model/deal.rb', line 71 def value @value end |
Instance Method Details
#description ⇒ Object
:attr_accessor: description
57 |
# File 'lib/move-to-go/model/deal.rb', line 57 immutable_accessor :description |
#id ⇒ Object
:attr_accessor: id
48 |
# File 'lib/move-to-go/model/deal.rb', line 48 immutable_accessor :id |
#integration_id ⇒ Object
:attr_accessor: integration_id
51 |
# File 'lib/move-to-go/model/deal.rb', line 51 immutable_accessor :integration_id |
#is_integer?(value) ⇒ Boolean
239 240 241 |
# File 'lib/move-to-go/model/deal.rb', line 239 def is_integer?(value) true if Integer(value) rescue false end |
#name ⇒ Object
:attr_accessor: name
54 |
# File 'lib/move-to-go/model/deal.rb', line 54 immutable_accessor :name |
#offer_date ⇒ Object
:attr_accessor: offer_date
66 |
# File 'lib/move-to-go/model/deal.rb', line 66 immutable_accessor :offer_date |
#order_date ⇒ Object
:attr_accessor: order_date
63 |
# File 'lib/move-to-go/model/deal.rb', line 63 immutable_accessor :order_date |
#probability ⇒ Object
:attr_accessor: probability
60 |
# File 'lib/move-to-go/model/deal.rb', line 60 immutable_accessor :probability |
#serialize_name ⇒ Object
90 91 92 |
# File 'lib/move-to-go/model/deal.rb', line 90 def serialize_name "Deal" end |
#serialize_variables ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/move-to-go/model/deal.rb', line 73 def serialize_variables [ :id, :integration_id, :name, :description, :probability, :value, :order_date, :offer_date ].map { |p| { :id => p, :type => :string } } + [ { :id => :customer_reference, :type => :organization_reference, :element_name => :customer }, { :id => :responsible_coworker_reference, :type => :coworker_reference, :element_name => :responsible_coworker }, { :id => :customer_contact_reference, :type => :person_reference, :element_name => :customer_contact}, { :id => :custom_values, :type => :custom_values }, { :id => :tags, :type => :tags }, { :id => :status, :type => :deal_status } ] end |
#status ⇒ Object
:attr_accessor: status Get/set the deal’s status. Statuses must be configured in LIME Go before the import.
44 |
# File 'lib/move-to-go/model/deal.rb', line 44 immutable_accessor :status |
#status=(status) ⇒ Object
Sets the deal’s status to the specifed status. The specifed status could be either a DealStatusSetting, a string or an integer. Use DealStatusSetting if you want to create new statuses during import (you will probably add the DealStatusSettings to the settings model). If the statuses already exists in the application use the status label (String) or integration id (Integer) here.
166 167 168 169 170 171 |
# File 'lib/move-to-go/model/deal.rb', line 166 def status=(status) raise_if_immutable @status = DealStatus.new if @status.nil? @status.status_reference = DealStatusReference.from_deal_status(status) end |
#to_reference ⇒ Object
109 110 111 112 113 114 |
# File 'lib/move-to-go/model/deal.rb', line 109 def to_reference reference = DealReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
105 106 107 |
# File 'lib/move-to-go/model/deal.rb', line 105 def to_s return "deal[id=#{@id}, integration_id=#{@integration_id}]" end |
#validate(labels = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/move-to-go/model/deal.rb', line 116 def validate(labels = nil) errors = [] warnings = [] if @name.nil? || @name.empty? errors.push("A name is required for deal.") end if is_integer?(@value) && @value.to_i < 0 errors.push("The value must be positive for deal.") end if !@status.nil? && @status.status_reference.nil? errors.push("Status must have a status reference.") end if !@status.nil? && !@status.status_reference.nil? && @status.status_reference.validate.length > 0 val = @status.status_reference.validate if val.length > 0 errors.push(val) end end if !@status.nil? && !@status.status_reference.nil? && (labels.nil? || (!labels.nil? && !labels.include?(@status.status_reference.label))) warnings.push("Deal status '#{@status.status_reference.label}' missing, add to settings") end if @status == nil warnings.push("No status set on deal (#{@integration_id}) '#{@name}', will be set to default status at import") end if errors.length > 0 errors.push(serialize()) end return [errors.join('\n'), warnings.join('\n')] end |
#with_status {|@status| ... } ⇒ Object
154 155 156 157 |
# File 'lib/move-to-go/model/deal.rb', line 154 def with_status @status = DealStatus.new if @status.nil? yield @status end |