Class: GoImport::Deal

Inherits:
CanBecomeImmutable show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/go_import/model/deal.rb

Instance Attribute Summary collapse

Attributes included from ModelHasTags

#tags

Instance Method Summary collapse

Methods included from SerializeHelper

#get_import_rows, #serialize, #serialize_to_file

Methods included from ModelHasCustomFields

#set_custom_value

Methods included from ModelHasTags

#set_tag

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.



77
78
79
80
81
82
83
84
85
86
# File 'lib/go_import/model/deal.rb', line 77

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_valuesObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



52
53
54
# File 'lib/go_import/model/deal.rb', line 52

def custom_values
  @custom_values
end

#customerObject

Gets the customer to which this deal belongs



156
157
158
# File 'lib/go_import/model/deal.rb', line 156

def customer
  @customer
end

#customer_contactObject

Returns the value of attribute customer_contact.



54
55
56
# File 'lib/go_import/model/deal.rb', line 54

def customer_contact
  @customer_contact
end

#responsible_coworkerObject

Returns the value of attribute responsible_coworker.



54
55
56
# File 'lib/go_import/model/deal.rb', line 54

def responsible_coworker
  @responsible_coworker
end

#valueObject

Returns the value of attribute value.



54
55
56
# File 'lib/go_import/model/deal.rb', line 54

def value
  @value
end

Instance Method Details

#is_integer?(value) ⇒ Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/go_import/model/deal.rb', line 212

def is_integer?(value)
    true if Integer(value) rescue false
end

#serialize_nameObject



73
74
75
# File 'lib/go_import/model/deal.rb', line 73

def serialize_name
    "Deal"
end

#serialize_variablesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/go_import/model/deal.rb', line 56

def serialize_variables
    [ :id, :integration_id, :name, :description, :probability, :value, :order_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=(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.



139
140
141
142
143
144
# File 'lib/go_import/model/deal.rb', line 139

def status=(status)
    raise_if_immutable
    @status = DealStatus.new if @status.nil?
    
    @status.status_reference = DealStatusReference.from_deal_status(status)
end

#to_referenceObject



92
93
94
95
96
97
# File 'lib/go_import/model/deal.rb', line 92

def to_reference
    reference = DealReference.new
    reference.id = @id
    reference.integration_id = @integration_id
    return reference
end

#to_sObject



88
89
90
# File 'lib/go_import/model/deal.rb', line 88

def to_s
    return "deal[id=#{@id}, integration_id=#{@integration_id}]"
end

#validate(labels = nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/go_import/model/deal.rb', line 99

def validate(labels = nil)
    error = String.new
    warnings = String.new

    if @name.nil? || @name.empty?
        error = "A name is required for deal.\n}"
    end

    if !@status.nil? && @status.status_reference.nil?
        error = "#{error}\nStatus must have a status reference."
    end

    if !@status.nil? && !@status.status_reference.nil? && @status.status_reference.validate.length > 0
        error = "#{error}\n#{@status.status_reference.validate}"
    end

    if !@status.nil? && !@status.status_reference.nil? && (labels.nil? || (!labels.nil? && !labels.include?(@status.status_reference.label)))
        warnings = "Deal status '#{@status.status_reference.label}' missing, add to settings"
    end

    if error.length > 0
        error = "#{error}\n#{serialize()}"
    end

    return [error, warnings]
end

#with_status {|@status| ... } ⇒ Object

Yields:

  • (@status)


127
128
129
130
# File 'lib/go_import/model/deal.rb', line 127

def with_status
    @status = DealStatus.new if @status.nil?
    yield @status
end