move-to-go 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/bin/move-to-go +210 -0
  3. data/lib/move-to-go/can_become_immutable.rb +29 -0
  4. data/lib/move-to-go/csv_helper.rb +47 -0
  5. data/lib/move-to-go/email_helper.rb +14 -0
  6. data/lib/move-to-go/errors.rb +31 -0
  7. data/lib/move-to-go/excel_helper.rb +10 -0
  8. data/lib/move-to-go/global_phone.json +6571 -0
  9. data/lib/move-to-go/model/address.rb +63 -0
  10. data/lib/move-to-go/model/class_settings.rb +50 -0
  11. data/lib/move-to-go/model/clientvisit.rb +10 -0
  12. data/lib/move-to-go/model/comment.rb +10 -0
  13. data/lib/move-to-go/model/coworker.rb +82 -0
  14. data/lib/move-to-go/model/coworker_reference.rb +33 -0
  15. data/lib/move-to-go/model/customfield.rb +87 -0
  16. data/lib/move-to-go/model/deal.rb +216 -0
  17. data/lib/move-to-go/model/deal_class_settings.rb +97 -0
  18. data/lib/move-to-go/model/deal_state.rb +15 -0
  19. data/lib/move-to-go/model/deal_status.rb +23 -0
  20. data/lib/move-to-go/model/deal_status_reference.rb +47 -0
  21. data/lib/move-to-go/model/deal_status_setting.rb +49 -0
  22. data/lib/move-to-go/model/documents.rb +76 -0
  23. data/lib/move-to-go/model/file.rb +193 -0
  24. data/lib/move-to-go/model/history.rb +148 -0
  25. data/lib/move-to-go/model/history_classification.rb +26 -0
  26. data/lib/move-to-go/model/link.rb +82 -0
  27. data/lib/move-to-go/model/organization.rb +250 -0
  28. data/lib/move-to-go/model/person.rb +164 -0
  29. data/lib/move-to-go/model/referencetosource.rb +58 -0
  30. data/lib/move-to-go/model/relation.rb +23 -0
  31. data/lib/move-to-go/model/rootmodel.rb +663 -0
  32. data/lib/move-to-go/model/salescall.rb +10 -0
  33. data/lib/move-to-go/model/settings.rb +61 -0
  34. data/lib/move-to-go/model/tag.rb +35 -0
  35. data/lib/move-to-go/model/talkedto.rb +10 -0
  36. data/lib/move-to-go/model/triedtoreach.rb +10 -0
  37. data/lib/move-to-go/model_helpers.rb +97 -0
  38. data/lib/move-to-go/phone_helper.rb +75 -0
  39. data/lib/move-to-go/roo_helper.rb +82 -0
  40. data/lib/move-to-go/serialize_helper.rb +199 -0
  41. data/lib/move-to-go/shard_helper.rb +96 -0
  42. data/lib/move-to-go/source.rb +108 -0
  43. data/lib/move-to-go/templating.rb +52 -0
  44. data/lib/move-to-go.rb +20 -0
  45. data/sources/VISMA/.gitignore +14 -0
  46. data/sources/VISMA/.move-to-go/readme.txt +1 -0
  47. data/sources/VISMA/.move-to-go/runner.rb +89 -0
  48. data/sources/VISMA/Database/KONTAKT.DBF +0 -0
  49. data/sources/VISMA/Database/KUND.DBF +0 -0
  50. data/sources/VISMA/Gemfile +5 -0
  51. data/sources/VISMA/converter.rb +120 -0
  52. data/sources/base-crm/.move-to-go/runner.rb +235 -0
  53. data/sources/base-crm/Gemfile +5 -0
  54. data/sources/base-crm/README.md +9 -0
  55. data/sources/base-crm/converter.rb +56 -0
  56. data/sources/base-crm/data/contacts.csv +13 -0
  57. data/sources/base-crm/data/coworkers.csv +3 -0
  58. data/sources/base-crm/data/deals.csv +5 -0
  59. data/sources/base-crm/data/histories.csv +6 -0
  60. data/sources/base-crm/data/leads.csv +4 -0
  61. data/sources/base-crm/data/tasks.csv +5 -0
  62. data/sources/csv/.gitignore +14 -0
  63. data/sources/csv/.move-to-go/readme.txt +1 -0
  64. data/sources/csv/.move-to-go/runner.rb +65 -0
  65. data/sources/csv/Gemfile +5 -0
  66. data/sources/csv/converter.rb +218 -0
  67. data/sources/csv/data/coworkers.csv +2 -0
  68. data/sources/csv/data/deals.csv +2 -0
  69. data/sources/csv/data/organizations.csv +2 -0
  70. data/sources/csv/data/persons.csv +2 -0
  71. data/sources/custom/.gitignore +14 -0
  72. data/sources/custom/.move-to-go/readme.txt +1 -0
  73. data/sources/custom/.move-to-go/runner.rb +30 -0
  74. data/sources/custom/Gemfile +4 -0
  75. data/sources/custom/converter.rb +45 -0
  76. data/sources/excel/.gitignore +14 -0
  77. data/sources/excel/.move-to-go/readme.txt +3 -0
  78. data/sources/excel/.move-to-go/runner.rb +140 -0
  79. data/sources/excel/Gemfile +7 -0
  80. data/sources/excel/converter.rb +188 -0
  81. data/sources/excel/files/avtal.docx +0 -0
  82. data/sources/excel/files/more/avtal.docx +0 -0
  83. data/sources/excel/files/more/offert-2.pdf +0 -0
  84. data/sources/excel/files/offert-2.docx +0 -0
  85. data/sources/excel/files/offert.docx +0 -0
  86. data/sources/excel/sample-data.xlsx +0 -0
  87. data/sources/excel-basic/.gitignore +14 -0
  88. data/sources/excel-basic/.move-to-go/readme.txt +3 -0
  89. data/sources/excel-basic/.move-to-go/runner.rb +139 -0
  90. data/sources/excel-basic/Exempelfil.xlsx +0 -0
  91. data/sources/excel-basic/Gemfile +6 -0
  92. data/sources/excel-basic/converter.rb +175 -0
  93. data/sources/excel-basic/files/avtal.docx +0 -0
  94. data/sources/excel-basic/files/more/avtal.docx +0 -0
  95. data/sources/excel-basic/files/more/offert-2.pdf +0 -0
  96. data/sources/excel-basic/files/offert-2.docx +0 -0
  97. data/sources/excel-basic/files/offert.docx +0 -0
  98. data/sources/lime-crm-basic/.gitignore +14 -0
  99. data/sources/lime-crm-basic/.move-to-go/readme.txt +1 -0
  100. data/sources/lime-crm-basic/.move-to-go/runner.rb +524 -0
  101. data/sources/lime-crm-basic/Gemfile +6 -0
  102. data/sources/lime-crm-basic/converter.rb +396 -0
  103. data/sources/lime-easy/.gitignore +14 -0
  104. data/sources/lime-easy/.move-to-go/readme.txt +1 -0
  105. data/sources/lime-easy/.move-to-go/runner.rb +348 -0
  106. data/sources/lime-easy/Export/readme.txt +6 -0
  107. data/sources/lime-easy/Gemfile +5 -0
  108. data/sources/lime-easy/converter.rb +362 -0
  109. data/sources/salesforce/.gitignore +14 -0
  110. data/sources/salesforce/.move-to-go/readme.txt +1 -0
  111. data/sources/salesforce/.move-to-go/runner.rb +404 -0
  112. data/sources/salesforce/Gemfile +6 -0
  113. data/sources/salesforce/Gemfile.lock +48 -0
  114. data/sources/salesforce/converter.rb +113 -0
  115. data/sources/salesforce/export/readme.txt +3 -0
  116. data/spec/address_spec.rb +49 -0
  117. data/spec/class_settings_spec.rb +37 -0
  118. data/spec/coworker_spec.rb +94 -0
  119. data/spec/custom_field_spec.rb +22 -0
  120. data/spec/deal_class_settings_spec.rb +116 -0
  121. data/spec/deal_spec.rb +232 -0
  122. data/spec/deal_status_reference_spec.rb +17 -0
  123. data/spec/documents_spec.rb +64 -0
  124. data/spec/file_spec.rb +178 -0
  125. data/spec/helpers/csv_helper_spec.rb +45 -0
  126. data/spec/helpers/email_helper_spec.rb +37 -0
  127. data/spec/helpers/phone_helper_spec.rb +119 -0
  128. data/spec/helpers/roo_helper_spec.rb +10 -0
  129. data/spec/helpers/serialize_helper_spec.rb +253 -0
  130. data/spec/helpers/shard_helper_spec.rb +141 -0
  131. data/spec/helpers/xsd_validate_spec.rb +57 -0
  132. data/spec/history_spec.rb +150 -0
  133. data/spec/link_spec.rb +107 -0
  134. data/spec/organization_spec.rb +221 -0
  135. data/spec/person_spec.rb +129 -0
  136. data/spec/rootmodel_spec.rb +993 -0
  137. data/spec/spec_helper.rb +30 -0
  138. metadata +362 -0
@@ -0,0 +1,63 @@
1
+ require 'iso_country_codes'
2
+ module MoveToGo
3
+ class Address
4
+ attr_accessor :street, :zip_code, :city, :country_code, :location
5
+ def serialize_variables
6
+ [ :street, :zip_code, :city, :country_code, :location].map {|p| {:id=>p,:type=>:string} }
7
+ end
8
+ include SerializeHelper
9
+ def initialize()
10
+ end
11
+
12
+ # What fields/rows on the class is supposed to be used by the Gem to generate the xml
13
+ # This method uses {#serialize_variables}. It also adds {#country_name} to be serialized
14
+ def get_import_rows
15
+ (serialize_variables+[{:id=>:country_name, :type=>:string}]).map do |p|
16
+ map_to_row p
17
+ end
18
+ end
19
+ # Used as a convenience in order to get country code from internally used {#country_code}
20
+ def country_name
21
+ if @country_code
22
+ IsoCountryCodes.find(@country_code).name
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
28
+ # Used as a convenience in order to map country name to the internal {#country_code}
29
+ def country_name=(name)
30
+ @country_code = case name
31
+ when nil
32
+ nil
33
+ when 'Sverige'
34
+ 'SE'
35
+ else
36
+ begin
37
+ IsoCountryCodes.search_by_name(name).first.alpha2
38
+ rescue
39
+ nil
40
+ end
41
+ end
42
+ end
43
+ # parses a line like "226 48 LUND" into its corresponding
44
+ # zipcode and city properties on the address
45
+ def parse_zip_and_address_se(line)
46
+ Address.parse_line_to_zip_and_address_se(line, self)
47
+ end
48
+
49
+ private
50
+ def self.parse_line_to_zip_and_address_se(line, address)
51
+ matched_zipcode = /^\d{3}\s?\d{2}/.match(line)
52
+ if matched_zipcode && matched_zipcode.length == 1
53
+ address.zip_code = matched_zipcode[0].strip()
54
+ matched_city = /\D*$/.match(line)
55
+ if matched_city && matched_city.length == 1
56
+ address.city = matched_city[0].strip()
57
+ return address
58
+ end
59
+ end
60
+ return nil
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,50 @@
1
+ # Encoding: utf-8
2
+ module MoveToGo
3
+ class ClassSettings
4
+ include SerializeHelper
5
+ attr_reader :custom_fields
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [{:id => :custom_fields, :type => :custom_fields} ]
18
+ end
19
+
20
+ def serialize_name
21
+ "ClassSettings"
22
+ end
23
+
24
+ # Set custom field. If there is already an existing custom field, then it is overwritten.
25
+ def set_custom_field(obj)
26
+ @custom_fields = [] if @custom_fields.nil?
27
+
28
+ if obj.is_a?(CustomField)
29
+ field = obj
30
+ else
31
+ field = CustomField.new(obj)
32
+ end
33
+
34
+ if field.integration_id == "" && field.id == ""
35
+ raise InvalidCustomFieldError, "Custom field must have either id or integration_id"
36
+ end
37
+
38
+ index = @custom_fields.find_index do |custom_field|
39
+ custom_field.same_as?(field)
40
+ end
41
+ if index
42
+ @custom_fields.delete_at index
43
+ end
44
+
45
+ @custom_fields.push field
46
+
47
+ return field
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'history'
2
+ module MoveToGo
3
+ class ClientVisit < History
4
+ def initialize(opt = nil)
5
+ super(opt)
6
+
7
+ @classification = HistoryClassification::ClientVisit
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'history'
2
+ module MoveToGo
3
+ class Comment < History
4
+ def initialize(opt = nil)
5
+ super(opt)
6
+
7
+ @classification = HistoryClassification::Comment
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ module MoveToGo
3
+ class Coworker < CanBecomeImmutable
4
+ include SerializeHelper
5
+ immutable_accessor :id
6
+ immutable_accessor :integration_id
7
+ immutable_accessor :email
8
+ immutable_accessor :first_name
9
+ immutable_accessor :last_name
10
+ immutable_accessor :direct_phone_number
11
+ immutable_accessor :mobile_phone_number
12
+ immutable_accessor :home_phone_number
13
+
14
+ def initialize(opt = nil)
15
+ if opt != nil
16
+ serialize_variables.each do |myattr|
17
+ val = opt[myattr[:id]]
18
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
19
+ end
20
+ end
21
+ end
22
+
23
+ def serialize_variables
24
+ [
25
+ :id, :integration_id, :email, :first_name, :last_name,
26
+ :direct_phone_number, :mobile_phone_number, :home_phone_number
27
+ ].map {|p| { :id => p, :type => :string } }
28
+ end
29
+
30
+ def to_reference
31
+ reference = CoworkerReference.new
32
+ reference.id = @id
33
+ reference.integration_id = @integration_id
34
+ reference.heading = "#{@first_name} #{@last_name}".strip
35
+
36
+ return reference
37
+ end
38
+
39
+ def serialize_name
40
+ "Coworker"
41
+ end
42
+
43
+ def ==(that)
44
+ if that.nil?
45
+ return false
46
+ end
47
+
48
+ if that.is_a? Coworker
49
+ return @integration_id == that.integration_id
50
+ end
51
+
52
+ return false
53
+ end
54
+
55
+ def parse_name_to_firstname_lastname_se(name, when_missing = '')
56
+ if name.nil? or name.empty?
57
+ @first_name = when_missing
58
+ return
59
+ end
60
+
61
+ splitted = name.split(' ')
62
+ @first_name = splitted[0]
63
+ if splitted.length > 1
64
+ @last_name = splitted.drop(1).join(' ')
65
+ end
66
+ end
67
+
68
+ def to_email_chars(s)
69
+ s.tr " åäöèé", "-aaoee"
70
+ end
71
+
72
+ def guess_email(domain)
73
+ return '' if @last_name.nil? || @last_name.empty?
74
+ return '' if @first_name.nil? || @first_name.empty?
75
+
76
+ firstname = to_email_chars @first_name.downcase
77
+ lastname = to_email_chars @last_name.downcase
78
+ return "#{firstname}.#{lastname}@#{domain}"
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,33 @@
1
+ module MoveToGo
2
+ class CoworkerReference
3
+ include SerializeHelper
4
+ attr_accessor :id, :heading, :integration_id
5
+
6
+ def initialize(opt = nil)
7
+ if opt != nil
8
+ serialize_variables.each do |myattr|
9
+ val = opt[myattr[:id]]
10
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
11
+ end
12
+ end
13
+ end
14
+
15
+ def serialize_variables
16
+ [:id, :integration_id, :heading].map {|p| {:id => p, :type => :string} }
17
+ end
18
+
19
+ def serialize_name
20
+ "CoworkerReference"
21
+ end
22
+
23
+ def self.from_coworker(coworker)
24
+ if coworker.nil?
25
+ return nil
26
+ elsif coworker.is_a?(Coworker)
27
+ return coworker.to_reference
28
+ elsif coworker.is_a?(CoworkerReference)
29
+ return coworker
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,87 @@
1
+ module MoveToGo
2
+ class CustomFieldReference
3
+ include SerializeHelper, ModelWithIntegrationIdSameAs
4
+
5
+ attr_accessor :integration_id
6
+
7
+ def initialize(opt=nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [:integration_id].map {|p| { :id => p, :type => :string } }
18
+ end
19
+
20
+ def get_import_rows
21
+ serialize_variables.map do |p|
22
+ map_to_row p
23
+ end
24
+ end
25
+
26
+ def serialize_name
27
+ "CustomFieldReference"
28
+ end
29
+ end
30
+
31
+ class CustomField
32
+ include SerializeHelper, ModelWithIntegrationIdSameAs
33
+ attr_accessor :id, :integration_id, :title, :type
34
+
35
+ def initialize(opt=nil)
36
+ if opt != nil
37
+ serialize_variables.each do |myattr|
38
+ val = opt[myattr[:id]]
39
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
40
+ end
41
+ end
42
+ end
43
+
44
+ def serialize_variables
45
+ [:id, :integration_id, :title, :type].map {|p| { :id => p, :type => :string } }
46
+ end
47
+
48
+ def get_import_rows
49
+ serialize_variables.map do |p|
50
+ map_to_row p
51
+ end
52
+ end
53
+
54
+ def serialize_name
55
+ "CustomField"
56
+ end
57
+ end
58
+
59
+ class CustomValue
60
+ include SerializeHelper
61
+ attr_accessor :field, :value
62
+
63
+ def initialize(opt=nil)
64
+ if opt != nil
65
+ serialize_variables.each do |myattr|
66
+ val = opt[myattr[:id]]
67
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
68
+ end
69
+ end
70
+ end
71
+
72
+ def serialize_variables
73
+ [ { :id =>:field, :type => :custom_field_reference },
74
+ { :id =>:value, :type => :string }]
75
+ end
76
+
77
+ def get_import_rows
78
+ serialize_variables.map do |p|
79
+ map_to_row p
80
+ end
81
+ end
82
+
83
+ def serialize_name
84
+ "CustomValue"
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,216 @@
1
+ module MoveToGo
2
+ class DealReference
3
+ include SerializeHelper
4
+ attr_accessor :id, :integration_id
5
+ def serialize_variables
6
+ [ :id, :integration_id ].map { |prop| {:id => prop, :type => :string} }
7
+ end
8
+
9
+ def initialize(opt = nil)
10
+ if opt != nil
11
+ serialize_variables.each do |var|
12
+ value = opt[var[:id]]
13
+ instance_variable_set("@" + var[:id].to_s, value) if value != nil
14
+ end
15
+ end
16
+ end
17
+
18
+ def to_s
19
+ return "(#{id}, #{integration_id})"
20
+ end
21
+
22
+ def empty?
23
+ return !@integration_id && !@id
24
+ end
25
+
26
+ def self.from_deal(deal)
27
+ if deal.nil?
28
+ return nil
29
+ elsif deal.is_a?(Deal)
30
+ return deal.to_reference
31
+ elsif deal.is_a?(DealReference)
32
+ return deal
33
+ end
34
+ end
35
+ end
36
+
37
+ class Deal < CanBecomeImmutable
38
+ include SerializeHelper, ModelHasCustomFields, ModelHasTags
39
+
40
+ # Get/set the deal's status. Statuses must be configured in
41
+ # LIME Go before the import.
42
+ immutable_accessor :status
43
+
44
+ immutable_accessor :id
45
+ immutable_accessor :integration_id
46
+ immutable_accessor :name
47
+ immutable_accessor :description
48
+ immutable_accessor :probability
49
+ immutable_accessor :order_date
50
+
51
+ # you add custom values by using {#set_custom_value}
52
+ attr_reader :custom_values
53
+
54
+ attr_reader :customer, :responsible_coworker, :customer_contact, :value
55
+
56
+ def serialize_variables
57
+ [ :id, :integration_id, :name, :description, :probability, :value, :order_date ].map {
58
+ |p| {
59
+ :id => p,
60
+ :type => :string
61
+ }
62
+ } +
63
+ [
64
+ { :id => :customer_reference, :type => :organization_reference, :element_name => :customer },
65
+ { :id => :responsible_coworker_reference, :type => :coworker_reference, :element_name => :responsible_coworker },
66
+ { :id => :customer_contact_reference, :type => :person_reference, :element_name => :customer_contact},
67
+ { :id => :custom_values, :type => :custom_values },
68
+ { :id => :tags, :type => :tags },
69
+ { :id => :status, :type => :deal_status }
70
+ ]
71
+ end
72
+
73
+ def serialize_name
74
+ "Deal"
75
+ end
76
+
77
+ def initialize(opt = nil)
78
+ if !opt.nil?
79
+ serialize_variables.each do |myattr|
80
+ val = opt[myattr[:id]]
81
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
82
+ end
83
+ end
84
+
85
+ set_tag 'Import'
86
+ end
87
+
88
+ def to_s
89
+ return "deal[id=#{@id}, integration_id=#{@integration_id}]"
90
+ end
91
+
92
+ def to_reference
93
+ reference = DealReference.new
94
+ reference.id = @id
95
+ reference.integration_id = @integration_id
96
+ return reference
97
+ end
98
+
99
+ def validate(labels = nil)
100
+ error = String.new
101
+ warnings = String.new
102
+
103
+ if @name.nil? || @name.empty?
104
+ error = "A name is required for deal.\n}"
105
+ end
106
+
107
+ if !@status.nil? && @status.status_reference.nil?
108
+ error = "#{error}\nStatus must have a status reference."
109
+ end
110
+
111
+ if !@status.nil? && !@status.status_reference.nil? && @status.status_reference.validate.length > 0
112
+ error = "#{error}\n#{@status.status_reference.validate}"
113
+ end
114
+
115
+ if !@status.nil? && !@status.status_reference.nil? && (labels.nil? || (!labels.nil? && !labels.include?(@status.status_reference.label)))
116
+ warnings = "Deal status '#{@status.status_reference.label}' missing, add to settings"
117
+ end
118
+
119
+ if error.length > 0
120
+ error = "#{error}\n#{serialize()}"
121
+ end
122
+
123
+ return [error, warnings]
124
+ end
125
+
126
+
127
+ def with_status
128
+ @status = DealStatus.new if @status.nil?
129
+ yield @status
130
+ end
131
+
132
+ # Sets the deal's status to the specifed status. The specifed
133
+ # status could be either a DealStatusSetting, a string or an
134
+ # integer. Use DealStatusSetting if you want to create new
135
+ # statuses during import (you will probably add the
136
+ # DealStatusSettings to the settings model). If the statuses
137
+ # already exists in the application use the status label
138
+ # (String) or integration id (Integer) here.
139
+ def status=(status)
140
+ raise_if_immutable
141
+ @status = DealStatus.new if @status.nil?
142
+
143
+ @status.status_reference = DealStatusReference.from_deal_status(status)
144
+ end
145
+
146
+ def customer=(customer)
147
+ raise_if_immutable
148
+ @customer_reference = OrganizationReference.from_organization(customer)
149
+
150
+ if customer.is_a?(Organization)
151
+ @customer = customer
152
+ end
153
+ end
154
+
155
+ # Gets the customer to which this deal belongs
156
+ def customer()
157
+ return @customer
158
+ end
159
+
160
+ def responsible_coworker=(coworker)
161
+ raise_if_immutable
162
+ @responsible_coworker_reference = CoworkerReference.from_coworker(coworker)
163
+
164
+ if coworker.is_a?(Coworker)
165
+ @responsible_coworker = coworker
166
+ end
167
+ end
168
+
169
+ def customer_contact=(person)
170
+ raise_if_immutable
171
+ @customer_contact_reference = PersonReference.from_person(person)
172
+
173
+ if person.is_a?(Person)
174
+ @customer_contact = person
175
+ end
176
+ end
177
+
178
+ # Sets the deal's value. Both . and , are treated as thousand
179
+ # separators and thus cents and other fractions will be
180
+ # ignored. This makes it easier for us to convert a string
181
+ # into an integer value.
182
+ def value=(value)
183
+ raise_if_immutable
184
+
185
+ if value.nil?
186
+ @value = "0"
187
+ elsif value.respond_to?(:empty?) && value.empty?
188
+ @value = "0"
189
+ else
190
+ # we have had some issues with LIME Easy imports where
191
+ # the value was in the format "357 000". We need to
192
+ # remove those spaces.
193
+ fixed_value = value.to_s.gsub(" ", "")
194
+
195
+ # we assume that both , and . are thousand separators
196
+ # and remove them from the value string. We dont care
197
+ # about decimal separators since the value is a deal's
198
+ # value which is much larger than cents and ores.
199
+ fixed_value = fixed_value.gsub(",", "")
200
+ fixed_value = fixed_value.gsub(".", "")
201
+
202
+ if is_integer?(fixed_value)
203
+ @value = fixed_value
204
+ elsif fixed_value.length == 0
205
+ @value = "0"
206
+ else
207
+ raise InvalidValueError, value
208
+ end
209
+ end
210
+ end
211
+
212
+ def is_integer?(value)
213
+ true if Integer(value) rescue false
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ require_relative 'class_settings'
3
+
4
+ module MoveToGo
5
+ class DealClassSettings < ClassSettings
6
+ attr_reader :statuses
7
+
8
+ attr_reader :default_status
9
+
10
+
11
+
12
+ def initialize(opt = nil)
13
+ @statuses = []
14
+ if opt != nil
15
+ serialize_variables.each do |myattr|
16
+ val = opt[myattr[:id]]
17
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
18
+ end
19
+ end
20
+ end
21
+
22
+ def serialize_variables
23
+ super() + [{:id => :statuses, :type => :statuses },
24
+ {:id => :default_status, :type => :deal_status_reference}
25
+ ]
26
+ end
27
+
28
+ def add_status(obj)
29
+ @statuses = [] if @statuses.nil?
30
+
31
+ if obj.is_a?(DealStatusSetting)
32
+ status = obj
33
+ else
34
+ status = DealStatusSetting.new(obj)
35
+ end
36
+
37
+ if status.label.nil? || status.label.empty?
38
+ raise InvalidDealStatusError, "Deal status must have a label"
39
+ end
40
+
41
+ if status.assessment.nil?
42
+ status.assessment = DealState::NotAnEndState
43
+ end
44
+
45
+ index = @statuses.find_index do |deal_status|
46
+ deal_status.same_as?(status)
47
+ end
48
+ if index
49
+ @statuses.delete_at index
50
+ end
51
+
52
+ @statuses.push status
53
+
54
+ return status
55
+ end
56
+
57
+ # Sets the default status for new deals. When a deal is
58
+ # created in LIME Go it will get this status. Valid values are
59
+ # an integration_id or label. The status must exist or be
60
+ # created with this import.
61
+ def default_status=(status)
62
+ if status.nil?
63
+ return
64
+ end
65
+
66
+ if status.is_a?(DealStatusReference)
67
+ @default_status = status
68
+ else
69
+ @default_status = DealStatusReference.from_deal_status(status)
70
+ end
71
+ end
72
+
73
+ def find_status_by_label(label)
74
+ return nil if @statuses.nil? || label.nil?
75
+
76
+ return @statuses.find do |status|
77
+ !status.label.nil? && status.label.casecmp(label) == 0
78
+ end
79
+ end
80
+
81
+ def find_status_by_integration_id(integration_id)
82
+ return nil if @statuses.nil? || integration_id.nil?
83
+
84
+ return @statuses.find do |status|
85
+ !status.integration_id.nil? && status.integration_id.casecmp(integration_id) == 0
86
+ end
87
+ end
88
+
89
+ def find_status_by_id(id)
90
+ return nil if @statuses.nil?
91
+
92
+ return @statuses.find do |status|
93
+ !status.id.nil? && status.id.casecmp(integration_id) == 0
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,15 @@
1
+ module MoveToGo
2
+ module DealState
3
+ # This is the default, a deal with a status with this state is
4
+ # currently being worked on.
5
+ NotAnEndState = 0
6
+
7
+ # The deal has reached a positive end state, eg we have won
8
+ # the deal.
9
+ PositiveEndState = 1
10
+
11
+ # The deal has reached a negative end state, eg we have lost
12
+ # the deal.
13
+ NegativeEndState = -1
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module MoveToGo
2
+ class DealStatus
3
+ include SerializeHelper
4
+
5
+ attr_accessor :id, :date, :status_reference, :history
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [ :id, :label, :history ].map{ |p| { :id => p, :type => :string } } +
18
+ [ :date ].map { |p| { :id => p, :type => :date } } +
19
+ [ :status_reference ].map { |p| { :id => p, :type => :deal_status_reference } }
20
+ end
21
+
22
+ end
23
+ end