go_import 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/bin/go-import CHANGED
@@ -9,7 +9,7 @@ class GoImportCommandLine < Thor
9
9
 
10
10
  desc "about", "About go-import"
11
11
  def about()
12
- puts "go-import is an import tool for LIME Go. It can take virtually any input source and create pretty looking xml-files that LIME Go likes. go-import has some predefined sources that will make it easy for you to migrate your data."
12
+ puts "go-import is an import tool for LIME Go. It can take virtually any input source and create import data files that LIME Go likes. go-import has some predefined sources that will make it easy for you to migrate your data."
13
13
  puts ""
14
14
  end
15
15
 
@@ -26,22 +26,14 @@ class GoImportCommandLine < Thor
26
26
  puts "\nCreate a new project with 'go-import new' with one of these sources."
27
27
  end
28
28
 
29
- desc "new", "Creates a new migration project with a specifed name and source"
30
- option(:project,
31
- :desc => "Name of the project. The project will be created in a folder with the same name.",
32
- :type => :string,
33
- :required => true)
34
- option(:source,
35
- :desc => "Name of the source to use. Use list-sources to show available sources.",
36
- :type => :string,
37
- :required => true)
38
- def new(project = nil, source = nil)
29
+ desc "new <PROJECT> <SOURCE>", "Creates a new migration project with a specifed name and source"
30
+ def new(project, source)
39
31
  sources = GoImport::Sources.new(source_path)
40
32
 
41
- if sources.create_project_from_source(options.project, options.source)
42
- puts "\nProject '#{options.project}' created from source '#{options.source}'."
43
- puts "Modify the #{options.project}/converter.rb script to suit your source."
44
- puts "Use 'go-import run' from the project directory to create the xml file for LIME Go."
33
+ if sources.create_project_from_source(project, source)
34
+ puts "\nProject '#{project}' created from source '#{source}'."
35
+ puts "Modify the #{project}/converter.rb script to suit your source."
36
+ puts "Use 'go-import run' from the project directory to create the zip file for LIME Go."
45
37
  end
46
38
  end
47
39
 
@@ -21,6 +21,8 @@ def convert_source
21
21
  raise
22
22
  end
23
23
 
24
+ validate_constants()
25
+
24
26
  converter = Converter.new
25
27
  rootmodel = GoImport::RootModel.new
26
28
 
@@ -35,26 +37,30 @@ def convert_source
35
37
  # from everywhere....
36
38
  process_rows COWORKER_FILE do |row|
37
39
  coworkers[row['idUser']] = row['PowerSellUserID']
38
- rootmodel.add_coworker(converter.to_coworker(row))
40
+
41
+ rootmodel.add_coworker(to_coworker(row))
39
42
  end
40
43
 
41
44
  # organizations
42
45
  process_rows ORGANIZATION_FILE do |row|
43
- rootmodel.add_organization(converter.to_organization(row, coworkers, rootmodel))
46
+ organization = init_organization(row)
47
+ rootmodel.add_organization(
48
+ converter.to_organization(organization, row))
44
49
  end
45
50
 
46
51
  # persons
47
52
  # depends on organizations
48
53
  process_rows PERSON_FILE do |row|
49
54
  people[row['personIndex']] = "#{row['PowerSellReferenceID']}-#{row['PowerSellCompanyID']}"
50
- # adds it self to the employer
51
- converter.to_person(row, rootmodel)
55
+ # init method also adds the person to the employer
56
+ person = init_person(row, rootmodel)
57
+ converter.to_person(person, row)
52
58
  end
53
59
 
54
60
  # organization notes
55
61
  process_rows ORGANIZATION_NOTE_FILE do |row|
56
62
  # adds itself if applicable
57
- rootmodel.add_note(converter.to_organization_note(row, coworkers, people, rootmodel))
63
+ rootmodel.add_note(to_organization_note(row, coworkers, people, rootmodel))
58
64
  end
59
65
 
60
66
  # Organization - Deal connection
@@ -68,23 +74,193 @@ def convert_source
68
74
  # deals can reference coworkers (responsible), organizations
69
75
  # and persons (contact)
70
76
  process_rows DEAL_FILE do |row|
71
- rootmodel.add_deal(converter.to_deal(row, includes, coworkers, rootmodel))
77
+ deal = init_deal(row, rootmodel, includes)
78
+ rootmodel.add_deal(converter.to_deal(deal, row))
72
79
  end
73
80
 
74
81
  # deal notes
75
82
  process_rows DEAL_NOTE_FILE do |row|
76
83
  # adds itself if applicable
77
- rootmodel.add_note(converter.to_deal_note(row, coworkers, rootmodel))
84
+ rootmodel.add_note(to_deal_note(row, coworkers, rootmodel))
78
85
  end
79
86
 
80
87
  # company documents
81
- process_rows ORGANIZATION_DOCUMENT_FILE do |row|
82
- rootmodel.add_file(converter.to_organization_document(row, coworkers, rootmodel))
88
+ if defined?(IMPORT_DOCUMENTS) && !IMPORT_DOCUMENTS.nil? && IMPORT_DOCUMENTS
89
+ process_rows ORGANIZATION_DOCUMENT_FILE do |row|
90
+ rootmodel.add_file(to_organization_document(row, coworkers, rootmodel))
91
+ end
83
92
  end
84
93
 
94
+
85
95
  return rootmodel
86
96
  end
87
97
 
98
+ def to_coworker(row)
99
+ coworker = GoImport::Coworker.new
100
+ # integration_id is typically the userId in Easy
101
+ # Must be set to be able to import the same file more
102
+ # than once without creating duplicates
103
+ coworker.integration_id = row['PowerSellUserID']
104
+ coworker.parse_name_to_firstname_lastname_se(row['Name'])
105
+ return coworker
106
+ end
107
+
108
+ def init_organization(row)
109
+ organization = GoImport::Organization.new
110
+ # integration_id is typically the company Id in Easy
111
+ # Must be set to be able to import the same file more
112
+ # than once without creating duplicates
113
+ organization.integration_id = row['PowerSellCompanyID']
114
+
115
+ # Easy standard fields
116
+ organization.name = row['Company name']
117
+ organization.central_phone_number = row['Telephone']
118
+
119
+ if defined?(ORGANIZATION_RESPONSIBLE_FIELD) && !ORGANIZATION_RESPONSIBLE_FIELD.nil? && !ORGANIZATION_RESPONSIBLE_FIELD.empty?
120
+ # Responsible coworker for the organization.
121
+ # For instance responsible sales rep.
122
+ coworker_id = coworkers[row["idUser-#{ORGANIZATION_RESPONSIBLE_FIELD}"]]
123
+ organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
124
+ end
125
+
126
+ return organization
127
+ end
128
+
129
+ def init_person(row, rootmodel)
130
+ person = GoImport::Person.new
131
+
132
+ # Easy standard fields created in configure method Easy
133
+ # persons don't have a globally unique Id, they are only
134
+ # unique within the scope of the company, so we combine the
135
+ # referenceId and the companyId to make a globally unique
136
+ # integration_id
137
+ person.integration_id = "#{row['PowerSellReferenceID']}-#{row['PowerSellCompanyID']}"
138
+ person.first_name = row['First name']
139
+ person.last_name = row['Last name']
140
+
141
+ # set employer connection
142
+ employer = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
143
+ if employer
144
+ employer.add_employee person
145
+ end
146
+
147
+ return person
148
+ end
149
+
150
+ # Turns a row from the Easy exported Company-History.txt file into
151
+ # a go_import model that is used to generate xml.
152
+ # Uses coworkers hash to lookup coworkers to connect
153
+ # Uses people hash to lookup persons to connect
154
+ def to_organization_note(row, coworkers, people, rootmodel)
155
+ organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
156
+
157
+ coworker_id = coworkers[row['idUser']]
158
+ coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
159
+
160
+ if organization && coworker
161
+ note = GoImport::Note.new()
162
+ note.organization = organization
163
+ note.created_by = coworker
164
+ note.person = organization.find_employee_by_integration_id(people[row['idPerson']])
165
+ note.date = row['Date']
166
+ note.text = "#{row['Category']}: #{row['History']}"
167
+
168
+ return note.text.empty? ? nil : note
169
+ end
170
+
171
+ return nil
172
+ end
173
+
174
+ def to_organization_document(row, coworkers, rootmodel)
175
+ file = GoImport::File.new()
176
+
177
+ file.integration_id = row['PowerSellDocumentID']
178
+ file.path = row['Path']
179
+ file.name = row['Comment']
180
+
181
+ coworker_id = coworkers[row['idUser-Created']]
182
+ file.created_by = rootmodel.find_coworker_by_integration_id(coworker_id)
183
+ file.organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
184
+
185
+ return file
186
+ end
187
+
188
+ def init_deal(row, rootmodel, includes)
189
+ deal = GoImport::Deal.new
190
+
191
+ deal.integration_id = row['PowerSellProjectID']
192
+ deal.name = row['Name']
193
+ deal.description = row['Description']
194
+
195
+ if defined?(DEAL_RESPONSIBLE_FIELD) && !DEAL_RESPONSIBLE_FIELD.nil? && !DEAL_RESPONSIBLE_FIELD.empty?
196
+ coworker_id = coworkers[row["isUser-#{DEAL_RESPONSIBLE_FIELD}"]]
197
+ deal.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
198
+ end
199
+
200
+ # Make the deal - organization connection
201
+ if includes
202
+ organization_id = includes[row['PowerSellProjectID']]
203
+ organization = rootmodel.find_organization_by_integration_id(organization_id)
204
+ if organization
205
+ deal.customer = organization
206
+ end
207
+ end
208
+
209
+ return deal
210
+ end
211
+
212
+ # Turns a row from the Easy exported Project-History.txt file into
213
+ # a go_import model that is used to generate xml
214
+ # Uses coworkers hash to lookup coworkers to connect
215
+ def to_deal_note(row, coworkers, rootmodel)
216
+ # TODO: This could be improved to read a person from an
217
+ # organization connected to this deal if any, but since it is
218
+ # a many to many connection between organizations and deals
219
+ # it's not a straight forward task
220
+ deal = rootmodel.find_deal_by_integration_id(row['PowerSellProjectID'])
221
+
222
+ coworker_id = coworkers[row['idUser']]
223
+ coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
224
+
225
+ if deal && coworker
226
+ note = GoImport::Note.new()
227
+ note.deal = deal
228
+ note.created_by = coworker
229
+ note.date = row['Date']
230
+ # Raw history looks like this <category>: <person>: <text>
231
+ note.text = row['RawHistory']
232
+
233
+ return note.text.empty? ? nil : note
234
+ end
235
+
236
+ return nil
237
+ end
238
+
239
+
240
+ def validate_constants()
241
+ if !defined?(ORGANIZATION_RESPONSIBLE_FIELD)
242
+ puts "WARNING: You have not defined a resposible coworker field for organization.
243
+ If you don't have such a field, you can just ignore this warning.
244
+ Otherwise you should define 'ORGANIZATION_RESPONSIBLE_FIELD' in converter.rb
245
+ with the value of the field name in Easy (e.g 'Ansvarig')."
246
+ end
247
+
248
+ if !defined?(DEAL_RESPONSIBLE_FIELD)
249
+ puts "WARNING: You have not defined a resposible coworker field for deal.
250
+ If you don't have such a field, you can just ignore this warning.
251
+ Otherwise you should define 'DEAL_RESPONSIBLE_FIELD' in converter.rb
252
+ with the value of the field name in Easy (e.g 'Ansvarig')."
253
+ end
254
+
255
+ if !defined?(IMPORT_DOCUMENTS) || IMPORT_DOCUMENTS.nil? || !IMPORT_DOCUMENTS
256
+ puts "WARNING: You are about to run the import without documents.
257
+ If that is your intention then you can ignore this warning.
258
+ Otherwise you should define 'IMPORT_DOCUMENTS' in converter.rb
259
+ with the value 'true'."
260
+ end
261
+ end
262
+
263
+
88
264
  def process_rows(file_name)
89
265
  data = File.open(file_name, 'r').read.encode('UTF-8',"ISO-8859-1").strip().gsub('"', '')
90
266
  data = '"' + data.gsub("\t", "\"\t\"") + '"'
@@ -19,9 +19,9 @@ require 'go_import'
19
19
  # Follow these steps:
20
20
  #
21
21
  # 1) Export all data from KONTAKT.mdb to a folder named Export located
22
- # in the folder created by go_import unpack_template. Export data
23
- # using the magical tool called PowerSellMigrationExport.exe that can
24
- # be found in K:\Lundalogik\LIME Easy\Tillbeh�r\Migrationsexport.
22
+ # in the folder created by go_import new. Export data using the
23
+ # magical tool called PowerSellMigrationExport.exe that can be found
24
+ # in K:\Lundalogik\LIME Easy\Tillbeh�r\Migrationsexport.
25
25
  #
26
26
  # 2) Modify this file (the to_* methods) according to your customer's
27
27
  # KONTAKT.mdb and wishes.
@@ -34,294 +34,246 @@ require 'go_import'
34
34
  # You will get a WARNING from 'go-import run' about FILES_FOLDER has
35
35
  # not been set. You can ignore the warning since documents are
36
36
  # exported with an absolute path from LIME Easy.
37
- class Converter
38
- # Turns a user from the User.txt Easy Export file into
39
- # a go_import coworker.
40
- def to_coworker(row)
41
- coworker = GoImport::Coworker.new
42
- # integration_id is typically the userId in Easy
43
- # Must be set to be able to import the same file more
44
- # than once without creating duplicates
45
37
 
46
- # NOTE: You shouldn't have to modify this method
38
+ ############################################################################
39
+ ## Constants
40
+ # Edit these constants to fit your needs
47
41
 
48
- coworker.integration_id = row['PowerSellUserID']
49
- coworker.parse_name_to_firstname_lastname_se(row['Name'])
42
+ # determines if documents should be imported.
43
+ # IMPORT_DOCUMENTS = true
44
+
45
+ # set the name of the company-resposible field.
46
+ # ORGANIZATION_RESPONSIBLE_FIELD = "Responsible"
47
+
48
+ # set the name of the deal-responsible field.
49
+ # DEAL_RESPONSIBLE_FIELD = "Responsible"
50
50
 
51
- return coworker
52
- end
53
51
 
54
- # Turns a row from the Easy exported Company.txt file into a
55
- # go_import organization.
56
- def to_organization(row, coworkers, rootmodel)
57
- organization = GoImport::Organization.new
58
- # integration_id is typically the company Id in Easy
59
- # Must be set to be able to import the same file more
60
- # than once without creating duplicates
61
-
62
- # Easy standard fields
63
- organization.integration_id = row['PowerSellCompanyID']
64
- organization.name = row['Company name']
65
- organization.central_phone_number = row['Telephone']
66
-
67
- # *** TODO: Customize below this line (address, superfield,
68
- # relation, etc)
69
-
70
- # NOTE!! if a bisnode-id is present maybe you want to consider
71
- # not setting this (because if you set the address LIME Go
72
- # will NOT automagically update the address from PAR)
73
- # Addresses consists of several parts in Go. Lots of other
52
+ class Converter
53
+ # Reads a row from the Easy exported Company.txt
54
+ # and ads custom fields to the go_import organization.
55
+
56
+ # NOTE!!! You should customize this method to include
57
+ # and transform the fields you want to import to LIME Go.
58
+ # The method includes examples of different types of
59
+ # fields and how you should handle them.
60
+ # Sometimes it's enough to uncomment some code and
61
+ # change the row name but in most cases you need to
62
+ # do some thinking of your own.
63
+ def to_organization(organization, row)
64
+ # Here are some standard fields that are present
65
+ # on a LIME Go organization and are usually represented
66
+ # as superfields in Easy.
67
+
68
+ # organization.email = row['e-mail']
69
+ # organization.organization_number = row['orgnr']
70
+ # organization.web_site = row['website']
71
+
72
+ ####################################################################
73
+ ## Bisnode ID fields
74
+
75
+ # NOTE!!! If a bisnode-id is present you dont need to set
76
+ # fields like address or website since they are reterived from
77
+ # PAR.
78
+
79
+ # bisnode_id = row['Bisnode-id']
80
+
81
+ # if bisnode_id && !bisnode_id.empty?
82
+ # organization.with_source do |source|
83
+ # source.par_se(bisnode_id)
84
+ # end
85
+ # end
86
+
87
+ # If a company is missing a bisnode ID then you should do this
88
+ # in order to capture any possible data that is written manually
89
+ # on that company card.
90
+
91
+ # if bisnode_id && bisnode_id.empty?
92
+ # organization.web_site = row['website']
93
+ # end
94
+
95
+ ####################################################################
96
+ # Address fields.
97
+ # Addresses consists of several parts in LIME Go. Lots of other
74
98
  # systems have the address all in one line, to be able to
75
99
  # match when importing it is way better to split the addresses
76
- organization.with_postal_address do |address|
77
- address.street = row['street']
78
- address.zip_code = row['zip']
79
- address.city = row['city']
80
- address.location = row['location']
81
- end
82
-
83
- # Easy superfields
84
-
85
- # Same as postal address
86
- organization.with_visit_address do |addr|
87
- addr.street = row['visit street']
88
- addr.zip_code = row['visit zip']
89
- addr.city = row['visit city']
90
- end
91
-
92
- organization.email = row['e-mail']
93
- organization.organization_number = row['orgnr']
94
-
95
- # Set Bisnode Id if present
96
- bisnode_id = row['Bisnode-id']
97
-
98
- if bisnode_id && !bisnode_id.empty?
99
- organization.with_source do |source|
100
- source.par_se(bisnode_id)
101
- end
102
- end
103
-
104
- # Only set other Bisnode fields if the Bisnode Id is empty
105
- if bisnode_id && bisnode_id.empty?
106
- organization.web_site = row['website']
107
- end
108
-
109
- # Responsible coworker for the organization.
110
- # For instance responsible sales rep.
111
- coworker_id = coworkers[row['idUser-Responsible']]
112
- organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
113
100
 
101
+ # organization.with_postal_address do |address|
102
+ # address.street = row['street']
103
+ # address.zip_code = row['zip']
104
+ # address.city = row['city']
105
+ # address.location = row['location']
106
+ # end
107
+
108
+ # Same as visting address
109
+
110
+ # organization.with_visit_address do |addr|
111
+ # addr.street = row['visit street']
112
+ # addr.zip_code = row['visit zip']
113
+ # addr.city = row['visit city']
114
+ # end
115
+
116
+ #####################################################################
117
+ ## Tags.
114
118
  # Tags are set and defined at the same place
115
119
  # Setting a tag: Imported is useful for the user
116
- organization.set_tag("Imported")
117
120
 
121
+ # organization.set_tag("Imported")
122
+
123
+ #####################################################################
124
+ ## Option fields.
118
125
  # Option fields are normally translated into tags
119
126
  # The option field customer category for instance,
120
127
  # has the options "A-customer", "B-customer", and "C-customer"
121
- organization.set_tag(row['customer category'])
122
128
 
123
- # Relation
129
+ # organization.set_tag(row['customer category'])
130
+
131
+ #####################################################################
132
+ ## LIME Go Relation.
124
133
  # let's say that there is a option field in Easy called 'Customer relation'
125
134
  # with the options '1.Customer', '2.Prospect' '3.Partner' and '4.Lost customer'
126
- if row['Customer relation'] == '1.Customer'
127
- # We have made a deal with this organization.
128
- organization.relation = GoImport::Relation::IsACustomer
129
- elsif row['Customer relation'] == '3.Partner'
130
- # We have made a deal with this organization.
131
- organization.relation = GoImport::Relation::IsACustomer
132
- elsif row['Customer relation'] == '2.Prospect'
133
- # Something is happening with this organization, we might have
134
- # booked a meeting with them or created a deal, etc.
135
- organization.relation = GoImport::Relation::WorkingOnIt
136
- elsif row['Customer relation'] == '4.Lost customer'
137
- # We had something going with this organization but we
138
- # couldn't close the deal and we don't think they will be a
139
- # customer to us in the foreseeable future.
140
- organization.relation = GoImport::Relation::BeenInTouch
141
- else
142
- organization.relation = GoImport::Relation::NoRelation
143
- end
135
+
136
+ # if row['Customer relation'] == '1.Customer'
137
+ # We have made a deal with this organization.
138
+ # organization.relation = GoImport::Relation::IsACustomer
139
+ # elsif row['Customer relation'] == '3.Partner'
140
+ # We have made a deal with this organization.
141
+ # organization.relation = GoImport::Relation::IsACustomer
142
+ # elsif row['Customer relation'] == '2.Prospect'
143
+ # Something is happening with this organization, we might have
144
+ # booked a meeting with them or created a deal, etc.
145
+ # organization.relation = GoImport::Relation::WorkingOnIt
146
+ # elsif row['Customer relation'] == '4.Lost customer'
147
+ # We had something going with this organization but we
148
+ # couldn't close the deal and we don't think they will be a
149
+ # customer to us in the foreseeable future.
150
+ # organization.relation = GoImport::Relation::BeenInTouch
151
+ # else
152
+ # organization.relation = GoImport::Relation::NoRelation
153
+ # end
144
154
 
145
155
  return organization
146
156
  end
147
157
 
148
- # Turns a row from the Easy exported Company-Person.txt file into
149
- # a go_import model that is used to generate xml
150
- def to_person(row, rootmodel)
151
- person = GoImport::Person.new
152
-
153
- # Easy standard fields created in configure method Easy
154
- # persons don't have a globally unique Id, they are only
155
- # unique within the scope of the company, so we combine the
156
- # referenceId and the companyId to make a globally unique
157
- # integration_id
158
- person.integration_id = "#{row['PowerSellReferenceID']}-#{row['PowerSellCompanyID']}"
159
- person.first_name = row['First name']
160
- person.last_name = row['Last name']
161
-
162
- # set employer connection
163
- employer = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
164
- if employer
165
- employer.add_employee person
166
- end
167
-
168
- # *** TODO: Customize below this line (superfields, tags, etc)
169
-
170
- # Easy superfields
171
- person.direct_phone_number = row['Direktnummer']
172
- person.mobile_phone_number = row['Mobil']
173
- person.email = row['e-mail']
174
- person.position = row['position']
175
-
176
- # Populate a Go custom field
177
- person.set_custom_value("shoe_size", row['shoe size'])
178
-
179
- # Tags
180
- person.set_tag("Imported")
181
-
182
- # Checkbox fields
158
+ # Reads a row from the Easy exported Company-Person.txt
159
+ # and ads custom fields to the go_import organization.
160
+
161
+ # NOTE!!! You should customize this method to include
162
+ # and transform the fields you want to import to LIME Go.
163
+ # The method includes examples of different types of
164
+ # fields and how you should handle them.
165
+ # Sometimes it's enough to uncomment some code and
166
+ # change the row name but in most cases you need to
167
+ # do some thinking of your own.
168
+ def to_person(person, row)
169
+ ## Here are some standard fields that are present
170
+ # on a LIME Go person and are usually represented
171
+ # as superfields in Easy.
172
+
173
+ # person.direct_phone_number = row['Direktnummer']
174
+ # person.mobile_phone_number = row['Mobil']
175
+ # person.email = row['e-mail']
176
+ # person.position = row['position']
177
+
178
+ #####################################################################
179
+ ## Tags.
180
+ # Tags are set and defined at the same place
181
+ # Setting a tag: Imported is useful for the user
182
+
183
+ # person.set_tag("Imported")
184
+
185
+ #####################################################################
186
+ ## Checkbox fields.
187
+ # Checkbox fields are normally translated into tags
183
188
  # Xmas card field is a checkbox in Easy
184
- if row['Xmas card'] == "1"
185
- person.set_tag("Xmas card")
186
- end
187
-
188
- # Multioption fields or "Set"- fields
189
- if row['intrests']
190
- intrests = row['intrests'].split(';')
191
- intrests.each do |intrest|
192
- person.set_tag(intrest)
193
- end
194
- end
189
+
190
+ # if row['Xmas card'] == "1"
191
+ # person.set_tag("Xmas card")
192
+ # end
193
+
194
+ #####################################################################
195
+ ## Multioption fields or "Set"- fields.
196
+ # Set fields are normally translated into multiple tags in LIME Go
197
+ # interests is an example of a set field in LIME Easy.
198
+
199
+ # if row['intrests']
200
+ # intrests = row['intrests'].split(';')
201
+ # intrests.each do |intrest|
202
+ # person.set_tag(intrest)
203
+ # end
204
+ # end
205
+
206
+ #####################################################################
207
+ ## LIME Go custom fields.
208
+ # This is how you populate a LIME Go custom field that was created in
209
+ # the configure method.
210
+ # person.set_custom_value("shoe_size", row['shoe size'])
195
211
  end
196
212
 
197
- # Turns a row from the Easy exported Project.txt file into
198
- # a go_import model that is used to generate xml.
199
- # Uses includes hash to lookup organizations to connect
200
- # Uses coworkers hash to lookup coworkers to connect
201
- def to_deal(row, includes, coworkers, rootmodel)
202
- deal = GoImport::Deal.new
203
- # Easy standard fields
204
- deal.integration_id = row['PowerSellProjectID']
205
- deal.name = row['Name']
206
- deal.description = row['Description']
213
+ # Reads a row from the Easy exported Project.txt
214
+ # and ads custom fields to the go_import organization.
207
215
 
208
- # Easy superfields
209
- deal.order_date = row['order date']
216
+ # NOTE!!! You should customize this method to include
217
+ # and transform the fields you want to import to LIME Go.
218
+ # The method includes examples of different types of
219
+ # fields and how you should handle them.
220
+ # Sometimes it's enough to uncomment some code and
221
+ # change the row name but in most cases you need to
222
+ # do some thinking of your own.
223
+ def to_deal(deal, row)
224
+ ## Here are some standard fields that are present
225
+ # on a LIME Go deal and are usually represented
226
+ # as superfields in Easy.
210
227
 
211
- coworker_id = coworkers[row['isUser-Ansvarig']]
212
- deal.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
228
+ # deal.order_date = row['order date']
213
229
 
214
- # Should be integer
230
+ # Deal.value should be integer
215
231
  # The currency used in Easy should match the one used in Go
216
- deal.value = row['value']
232
+
233
+ # deal.value = row['value']
217
234
 
218
235
  # should be between 0 - 100
219
236
  # remove everything that is not an intiger
220
- deal.probability = row['probability'].gsub(/[^\d]/,"").to_i unless row['probability'].nil?
237
+
238
+ # deal.probability = row['probability'].gsub(/[^\d]/,"").to_i unless row['probability'].nil?
221
239
 
222
240
  # Sets the deal's status to the value of the Easy field. This
223
241
  # assumes that the status is already created in LIME Go. To
224
242
  # create statuses during import add them to the settings
225
243
  # during configure.
226
- if !row['Status'].nil? && !row['Status'].empty?
227
- deal.status = row['Status']
228
- end
229
-
230
- # Tags
231
- deal.set_tag("Imported")
232
-
233
- # Make the deal - organization connection
234
- if includes
235
- organization_id = includes[row['PowerSellProjectID']]
236
- organization = rootmodel.find_organization_by_integration_id(organization_id)
237
- if organization
238
- deal.customer = organization
239
- end
240
- end
241
-
242
- return deal
243
- end
244
-
245
- # Turns a row from the Easy exported Company-History.txt file into
246
- # a go_import model that is used to generate xml.
247
- # Uses coworkers hash to lookup coworkers to connect
248
- # Uses people hash to lookup persons to connect
249
- def to_organization_note(row, coworkers, people, rootmodel)
250
- organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
251
-
252
- coworker_id = coworkers[row['idUser']]
253
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
254
-
255
- if organization && coworker
256
- note = GoImport::Note.new()
257
- note.organization = organization
258
- note.created_by = coworker
259
- note.person = organization.find_employee_by_integration_id(people[row['idPerson']])
260
- note.date = row['Date']
261
- note.text = "#{row['Category']}: #{row['History']}"
262
244
 
263
- return note.text.empty? ? nil : note
264
- end
245
+ # if !row['Status'].nil? && !row['Status'].empty?
246
+ # deal.status = row['Status']
247
+ # end
265
248
 
266
- return nil
267
- end
268
-
269
- def to_organization_document(row, coworkers, rootmodel)
270
- file = GoImport::File.new()
271
-
272
- file.integration_id = row['PowerSellDocumentID']
273
- file.path = row['Path']
274
- file.name = row['Comment']
275
-
276
- coworker_id = coworkers[row['idUser-Created']]
277
- file.created_by = rootmodel.find_coworker_by_integration_id(coworker_id)
278
- file.organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
249
+ #####################################################################
250
+ ## Tags.
251
+ # Tags are set and defined at the same place
252
+ # Setting a tag: Imported is useful for the user
279
253
 
280
- return file
281
- end
254
+ # deal.set_tag("Imported")
282
255
 
283
- # Turns a row from the Easy exported Project-History.txt file into
284
- # a go_import model that is used to generate xml
285
- # Uses coworkers hash to lookup coworkers to connect
286
- def to_deal_note(row, coworkers, rootmodel)
287
- # TODO: This could be improved to read a person from an
288
- # organization connected to this deal if any, but since it is
289
- # a many to many connection between organizations and deals
290
- # it's not a straight forward task
291
- deal = rootmodel.find_deal_by_integration_id(row['PowerSellProjectID'])
292
-
293
- coworker_id = coworkers[row['idUser']]
294
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
295
-
296
- if deal && coworker
297
- note = GoImport::Note.new()
298
- note.deal = deal
299
- note.created_by = coworker
300
- note.date = row['Date']
301
- # Raw history looks like this <category>: <person>: <text>
302
- note.text = row['RawHistory']
303
-
304
- return note.text.empty? ? nil : note
305
- end
306
-
307
- return nil
256
+ return deal
308
257
  end
309
258
 
310
259
  def configure(rootmodel)
311
- # add custom field to your rootmodel here. Custom fields can
312
- # be added to organization, deal and person. Valid types are
313
- # :String and :Link. If no type is specified :String is used
314
- # as default.
315
- rootmodel.settings.with_person do |person|
316
- person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe size', :type => :String} )
317
- end
318
-
319
- rootmodel.settings.with_deal do |deal|
260
+ #####################################################################
261
+ ## LIME Go custom fields.
262
+ # This is how you add a custom field in LIME Go.
263
+ # Custom fields can be added to organization, deal and person.
264
+ # Valid types are :String and :Link. If no type is specified
265
+ # :String is used as default.
266
+
267
+ # rootmodel.settings.with_person do |person|
268
+ # person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe size', :type => :String} )
269
+ # end
270
+
271
+ # rootmodel.settings.with_deal do |deal|
320
272
  # assessment is default DealState::NoEndState
321
- deal.add_status( {:label => '1. Kvalificering' })
322
- deal.add_status( {:label => '2. Deal closed', :assessment => GoImport::DealState::PositiveEndState })
323
- deal.add_status( {:label => '4. Deal lost', :assessment => GoImport::DealState::NegativeEndState })
324
- end
273
+ # deal.add_status( {:label => '1. Kvalificering' })
274
+ # deal.add_status( {:label => '2. Deal closed', :assessment => GoImport::DealState::PositiveEndState })
275
+ # deal.add_status( {:label => '4. Deal lost', :assessment => GoImport::DealState::NegativeEndState })
276
+ # end
325
277
  end
326
278
  end
327
279
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
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-09-18 00:00:00.000000000 Z
15
+ date: 2014-09-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: iso_country_codes