fruit_to_lime 2.5.6 → 2.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,8 +62,8 @@ module FruitToLime
62
62
  def add_coworker(coworker)
63
63
  @coworkers = [] if @coworkers == nil
64
64
 
65
- if coworker == nil
66
- raise "Missing coworker to add!"
65
+ if coworker.nil?
66
+ return nil
67
67
  end
68
68
 
69
69
  coworker = Coworker.new(coworker) if !coworker.is_a?(Coworker)
@@ -103,7 +103,7 @@ module FruitToLime
103
103
  @organizations = [] if @organizations.nil?
104
104
 
105
105
  if organization.nil?
106
- raise "Missing organization to add"
106
+ return nil
107
107
  end
108
108
 
109
109
  organization = Organization.new(organization) if !organization.is_a?(Organization)
@@ -143,7 +143,7 @@ module FruitToLime
143
143
  @deals = [] if @deals.nil?
144
144
 
145
145
  if deal.nil?
146
- raise "Missing deal to add"
146
+ return nil
147
147
  end
148
148
 
149
149
  deal = Deal.new(deal) if !deal.is_a?(Deal)
@@ -187,8 +187,8 @@ module FruitToLime
187
187
  @notes = [] if @notes == nil
188
188
 
189
189
  if note.nil?
190
- raise "Missing note to add"
191
- end
190
+ return nil
191
+ end
192
192
 
193
193
  note = Note.new(note) if !note.is_a?(Note)
194
194
 
@@ -202,13 +202,13 @@ module FruitToLime
202
202
  return note
203
203
  end
204
204
 
205
- def with_new_note
206
- @notes = [] if @notes == nil
205
+ # def with_new_note
206
+ # @notes = [] if @notes == nil
207
207
 
208
- note = Note.new
209
- @notes.push note
210
- yield note
211
- end
208
+ # note = Note.new
209
+ # @notes.push note
210
+ # yield note
211
+ # end
212
212
 
213
213
  def find_coworker_by_integration_id(integration_id)
214
214
  return @coworkers.find do |coworker|
@@ -335,7 +335,7 @@ module FruitToLime
335
335
 
336
336
  def with_non_empty_integration_id(objects)
337
337
  return objects.select do |obj|
338
- obj.integration_id!=nil && !obj.integration_id.empty?
338
+ obj.integration_id != nil && !obj.integration_id.empty?
339
339
  end
340
340
  end
341
341
  end
@@ -191,6 +191,39 @@ describe "RootModel" do
191
191
  rootmodel.notes.length.should eq 1
192
192
  end
193
193
 
194
+ it "will not add a nil note" do
195
+ # given, when
196
+ rootmodel.add_note(nil)
197
+
198
+ # then
199
+ rootmodel.notes.length.should eq 0
200
+ end
201
+
202
+ it "will not add a nil organization" do
203
+ # given, when
204
+ rootmodel.add_organization(nil)
205
+
206
+ # then
207
+ rootmodel.organizations.length.should eq 0
208
+ end
209
+
210
+ it "will not add a nil deal" do
211
+ # given, when
212
+ rootmodel.add_deal(nil)
213
+
214
+ # then
215
+ rootmodel.deals.length.should eq 0
216
+ end
217
+
218
+ it "will not add a nil coworker" do
219
+ # given, when
220
+ rootmodel.add_coworker(nil)
221
+
222
+ # then
223
+ # 1 since we always have the import coworker
224
+ rootmodel.coworkers.length.should eq 1
225
+ end
226
+
194
227
  it "will not add a new organizations when the organizations is already added (same integration id)" do
195
228
  # given
196
229
  rootmodel.add_note({
@@ -7,7 +7,7 @@ class Exporter
7
7
  def to_coworker(row)
8
8
  coworker = FruitToLime::Coworker.new
9
9
  # integration_id is typically the userId in Easy
10
- # Must be set to be able to import the same file more
10
+ # Must be set to be able to import the same file more
11
11
  # than once without creating duplicates
12
12
  coworker.integration_id = row['userId']
13
13
  coworker.parse_name_to_firstname_lastname_se(row['Name'])
@@ -15,20 +15,21 @@ class Exporter
15
15
  return coworker
16
16
  end
17
17
 
18
- # turns a row from the Easy exported Company.txt file into
19
- # a fruit_to_lime model that is used to generate xml
20
- # Uses rootmodel to locate other related stuff such coworker
21
- def to_organization(row, rootmodel, coworkers)
18
+ # Turns a row from the Easy exported Company.txt file into a
19
+ # fruit_to_lime model that is used to generate xml
20
+ def to_organization(row, coworkers)
22
21
  organization = FruitToLime::Organization.new
23
22
  # integration_id is typically the company Id in Easy
24
- # Must be set to be able to import the same file more
23
+ # Must be set to be able to import the same file more
25
24
  # than once without creating duplicates
26
-
25
+
27
26
  # Easy standard fields
28
27
  organization.integration_id = row['companyId']
29
28
  organization.name = row['company name']
30
29
  organization.central_phone_number = row['Telephone']
31
30
 
31
+ # NOTE!! if a bisnode-id is present maybe you want to
32
+ # consider not setting this.
32
33
  # Addresses consists of several parts in Go.
33
34
  # Lots of other systems have the address all in one
34
35
  # line, to be able to match when importing it is
@@ -44,15 +45,16 @@ class Exporter
44
45
  organization.email = row['e-mail']
45
46
  organization.web_site = row['website']
46
47
 
48
+ # Same as postal address
47
49
  organization.with_visit_address do |addr|
48
50
  addr.street = row['visit street']
49
51
  addr.zip_code = row['visit zip']
50
52
  addr.city = row['visit city']
51
53
  end
52
-
54
+
53
55
  # Set Bisnode Id if present
54
56
  bisnode_id = row['Bisnode-id']
55
-
57
+
56
58
  if bisnode_id && !bisnode_id.empty?
57
59
  organization.with_source do |source|
58
60
  source.par_se(bisnode_id)
@@ -64,10 +66,10 @@ class Exporter
64
66
  organization.organization_number = row['orgnr']
65
67
  end
66
68
 
69
+ # Responsible coworker for the organization.
70
+ # For instance responsible sales rep.
67
71
  coworker_id = coworkers[row['userIndex - our reference']]
68
- organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
69
-
70
- # relation
72
+ organization.responsible_coworker = @rootmodel.find_coworker_by_integration_id(coworker_id)
71
73
 
72
74
  # Tags are set and defined at the same place
73
75
  # Setting a tag: Imported is useful for the user
@@ -78,13 +80,41 @@ class Exporter
78
80
  # has the options "A-customer", "B-customer", and "C-customer"
79
81
  organization.set_tag(row['customer category'])
80
82
 
83
+ # Relation
84
+ # let's say that there is a option field in Easy called 'Customer relation'
85
+ # with the options '1.Customer', '2.Prospect' '3.Partner' and '4.Lost customer'
86
+ if row['Customer relation'] == '1.Customer'
87
+ # We have made a deal with this organization.
88
+ organization.relation = Relation::IsACustomer
89
+ elsif row['Customer relation'] == '3.Partner'
90
+ # We have made a deal with this organization.
91
+ organization.relation = Relation::IsACustomer
92
+ elsif row['Customer relation'] == '2.Prospect'
93
+ # Something is happening with this organization, we might have
94
+ # booked a meeting with them or created a deal, etc.
95
+ organization.relation = Relation::WorkingOnIt
96
+ elsif row['Customer relation'] == '4.Lost customer'
97
+ # We had something going with this organization but we
98
+ # couldn't close the deal and we don't think they will be a
99
+ # customer to us in the foreseeable future.
100
+ organization.relation = Relation::BeenInTouch
101
+ else
102
+ organization.relation = Relation::NoRelation
103
+ end
104
+
81
105
  return organization
82
106
  end
83
107
 
84
- def to_person(row, rootmodel)
108
+ # Turns a row from the Easy exported Company-Person.txt file into
109
+ # a fruit_to_lime model that is used to generate xml
110
+ def to_person(row)
85
111
  person = FruitToLime::Person.new
86
-
87
- # Easy standard fields
112
+
113
+ # Easy standard fields created in configure method Easy
114
+ # persons don't have a globally unique Id, they are only
115
+ # unique within the scope of the company, so we combine the
116
+ # referenceId and the companyId to make a globally unique
117
+ # integration_id
88
118
  person.integration_id = "#{row['referenceId']}-#{row['companyId']}"
89
119
  person.first_name = row['First name']
90
120
  person.last_name = row['Last name']
@@ -95,100 +125,122 @@ class Exporter
95
125
  person.email = row['e-mail']
96
126
  person.position = row['position']
97
127
 
98
- person.set_custom_value("intrests", row['intrests'])
128
+ # Populate a Go custom field
99
129
  person.set_custom_value("shoe_size", row['shoe size'])
100
-
130
+
101
131
  # Tags
102
132
  person.set_tag("Imported")
103
133
 
134
+ # Checkbox fields
104
135
  # Xmas card field is a checkbox in Easy
105
136
  if row['Xmas card'] == "1"
106
137
  person.set_tag("Xmas card")
107
138
  end
108
139
 
140
+ # Multioption fields or "Set"- fields
141
+ intrests = row['intrests'].split(';')
142
+ intrests.each do |intrest|
143
+ person.set_tag(intrest)
144
+ end
145
+
109
146
  # set employer connection
110
- employer = rootmodel.find_organization_by_integration_id(row['companyId'])
147
+ employer = @rootmodel.find_organization_by_integration_id(row['companyId'])
111
148
  if employer
112
149
  employer.add_employee person
113
150
  end
114
151
  end
115
152
 
116
- def to_deal(row, rootmodel, includes, coworkers)
153
+ # Turns a row from the Easy exported Project.txt file into
154
+ # a fruit_to_lime model that is used to generate xml.
155
+ # Uses includes hash to lookup organizations to connect
156
+ # Uses coworkers hash to lookup coworkers to connect
157
+ def to_deal(row, includes, coworkers)
117
158
  deal = FruitToLime::Deal.new
118
159
  # Easy standard fields
119
160
  deal.integration_id = row['projectId']
120
161
  deal.name = row['Name']
121
162
  deal.description = row['Description']
122
163
 
123
- # Easy superfields
164
+ # Easy superfields
124
165
  deal.order_date = row[' order date']
125
166
 
126
167
  coworker_id = coworkers[row['userIndex']]
127
- deal.responsible_coworker = rootmodel.find_coworker_by_integration_id coworker_id
128
-
129
- # should be integer
130
- # make the currency used in Easy matches the one used in Go
168
+ deal.responsible_coworker = @rootmodel.find_coworker_by_integration_id coworker_id
169
+
170
+ # Should be integer
171
+ # The currency used in Easy should match the one used in Go
131
172
  deal.value = row['value']
132
173
 
133
174
  # should be between 0 - 100
134
175
  # remove everything that is not an intiger
135
176
  deal.probability = row['probability'].gsub(/[^\d]/,"").to_i
136
177
 
178
+ # Create a status object and set it's label to the value of the Easy field
137
179
  deal.status = FruitToLime::DealStatus.new
138
- deal.status.label = row['Status']
139
-
180
+ deal.status.label = row['Status']
140
181
 
141
- # tags
182
+ # Tags
142
183
  deal.set_tag("Imported")
143
184
 
144
- # find stuff connected to deal
185
+ # Make the deal - organization connection
145
186
  if includes
146
187
  organization_id = includes[row['projectId']]
147
- organization = rootmodel.find_organization_by_integration_id(organization_id)
188
+ organization = @rootmodel.find_organization_by_integration_id(organization_id)
148
189
  if organization
149
190
  deal.customer = organization
150
191
  end
151
192
  end
152
-
193
+
153
194
  return deal
154
195
  end
155
196
 
156
- def to_organization_note(row, rootmodel, coworkers, people)
157
- note = FruitToLime::Note.new()
158
-
159
- organization = rootmodel.find_organization_by_integration_id(row['companyId'])
160
-
197
+ # Turns a row from the Easy exported Company-History.txt file into
198
+ # a fruit_to_lime model that is used to generate xml.
199
+ # Uses coworkers hash to lookup coworkers to connect
200
+ # Uses people hash to lookup persons to connect
201
+ def to_organization_note(row, coworkers, people)
202
+ organization = @rootmodel.find_organization_by_integration_id(row['companyId'])
203
+
161
204
  coworker_id = coworkers[row['userIndex']]
162
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
205
+ coworker = @rootmodel.find_coworker_by_integration_id(coworker_id)
163
206
 
164
207
  if organization && coworker
208
+ note = FruitToLime::Note.new()
165
209
  note.organization = organization
166
210
  note.created_by = coworker
167
211
  note.person = organization.find_employee_by_integration_id(people[row['personIndex']])
168
212
  note.date = row['Date']
169
213
  note.text = "#{row['Category']}: #{row['History']}"
170
214
 
171
- rootmodel.add_note(note) unless note.text.empty?
215
+ return note.text.empty? ? nil : note
172
216
  end
173
217
 
174
218
  return note
175
219
  end
176
220
 
177
- def to_deal_note(row, rootmodel, coworkers)
221
+ # Turns a row from the Easy exported Project-History.txt file into
222
+ # a fruit_to_lime model that is used to generate xml
223
+ # Uses coworkers hash to lookup coworkers to connect
224
+ def to_deal_note(row, coworkers)
225
+ # TODO: This could be improved to read a person from an
226
+ # organization connected to this deal if any, but since it is
227
+ # a many to many connection between organizations and deals
228
+ # it's not a straight forward task
178
229
  note = FruitToLime::Note.new()
179
230
 
180
- deal = rootmodel.find_deal_by_integration_id(row['projectId'])
181
-
231
+ deal = @rootmodel.find_deal_by_integration_id(row['projectId'])
232
+
182
233
  coworker_id = coworkers[row['userIndex']]
183
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
234
+ coworker = @rootmodel.find_coworker_by_integration_id(coworker_id)
184
235
 
185
236
  if deal && coworker
186
237
  note.deal = deal
187
238
  note.created_by = coworker
188
239
  note.date = row['Date']
240
+ # Raw history looks like this <category>: <person>: <text>
189
241
  note.text = row['RawHistory']
190
242
 
191
- rootmodel.add_note(note) unless note.text.empty?
243
+ return note.text.empty? ? nil : note
192
244
  end
193
245
 
194
246
  return note
@@ -200,8 +252,7 @@ class Exporter
200
252
  # :String and :Link. If no type is specified :String is used
201
253
  # as default.
202
254
  model.settings.with_person do |person|
203
- person.set_custom_field( { :integration_id => 'intrests', :title => 'Intrests', :type => :String} )
204
- person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe size'} )
255
+ person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe size', :type => :String} )
205
256
  end
206
257
  end
207
258
 
@@ -219,12 +270,12 @@ class Exporter
219
270
  def to_model(coworkers_filename, organization_filename, persons_filename, orgnotes_filename, includes_filename, deals_filename, dealnotes_filename)
220
271
  # A rootmodel is used to represent all entitite/models
221
272
  # that is exported
222
- rootmodel = FruitToLime::RootModel.new
273
+ @rootmodel = FruitToLime::RootModel.new
223
274
  coworkers = Hash.new
224
275
  includes = Hash.new
225
276
  people = Hash.new
226
277
 
227
- configure rootmodel
278
+ configure @rootmodel
228
279
 
229
280
  # coworkers
230
281
  # start with these since they are referenced
@@ -232,15 +283,14 @@ class Exporter
232
283
  if coworkers_filename && !coworkers_filename.empty?
233
284
  process_rows coworkers_filename do |row|
234
285
  coworkers[row['userIndex']] = row['userId']
235
- rootmodel.add_coworker(to_coworker(row))
236
-
286
+ @rootmodel.add_coworker(to_coworker(row))
237
287
  end
238
288
  end
239
289
 
240
290
  # organizations
241
291
  if organization_filename && !organization_filename.empty?
242
292
  process_rows organization_filename do |row|
243
- rootmodel.add_organization(to_organization(row, rootmodel, coworkers))
293
+ @rootmodel.add_organization(to_organization(row, coworkers))
244
294
  end
245
295
  end
246
296
 
@@ -250,40 +300,45 @@ class Exporter
250
300
  process_rows persons_filename do |row|
251
301
  people[row['personIndex']] = "#{row['referenceId']}-#{row['companyId']}"
252
302
  # adds it self to the employer
253
- to_person(row, rootmodel)
303
+ to_person(row)
254
304
  end
255
305
  end
256
306
 
307
+ # organization notes
257
308
  if orgnotes_filename && !orgnotes_filename.empty?
258
309
  process_rows orgnotes_filename do |row|
259
310
  # adds itself if applicable
260
- to_organization_note(row, rootmodel, coworkers, people)
311
+ @rootmodel.add_note(to_organization_note(row, coworkers, people))
261
312
  end
262
313
  end
263
314
 
264
- # deals
265
- # deals can reference coworkers (responsible), organizations
266
- # and persons (contact)
315
+ # Organization - Deal connection
316
+ # Reads the includes.txt and creats a hash
317
+ # that connect organizations to deals
267
318
  if includes_filename && !includes_filename.empty?
268
319
  process_rows includes_filename do |row|
269
320
  includes[row['projectId']] = row['companyId']
270
321
  end
271
322
  end
272
-
323
+
324
+ # deals
325
+ # deals can reference coworkers (responsible), organizations
326
+ # and persons (contact)
273
327
  if deals_filename && !deals_filename.empty?
274
328
  process_rows deals_filename do |row|
275
- rootmodel.add_deal(to_deal(row, rootmodel, includes, coworkers))
329
+ @rootmodel.add_deal(to_deal(row, includes, coworkers))
276
330
  end
277
331
  end
278
332
 
333
+ # deal notes
279
334
  if dealnotes_filename && !dealnotes_filename.empty?
280
335
  process_rows dealnotes_filename do |row|
281
336
  # adds itself if applicable
282
- to_deal_note(row, rootmodel, coworkers)
337
+ @rootmodel.add_note(to_deal_note(row, coworkers))
283
338
  end
284
339
  end
285
340
 
286
- return rootmodel
341
+ return @rootmodel
287
342
  end
288
343
 
289
344
  def save_xml(file)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fruit_to_lime
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.6
4
+ version: 2.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-06-26 00:00:00.000000000 Z
15
+ date: 2014-06-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: iso_country_codes