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,140 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'move-to-go'
4
+ require 'roo'
5
+ require 'progress'
6
+ require_relative("../converter")
7
+
8
+ def convert_source
9
+ puts "Trying to convert Excel source to LIME Go..."
10
+
11
+ converter = Converter.new
12
+
13
+ # First we read each sheet from the excel file into separate
14
+ # variables
15
+
16
+ if defined?(EXCEL_FILE) && !EXCEL_FILE.empty?()
17
+ if !::File.exists?(EXCEL_FILE)
18
+ puts "ERROR: Cant find excel file to import: '#{EXCEL_FILE}'."
19
+ raise
20
+ end
21
+ else
22
+ puts "ERROR: You must set EXCEL_FILE in converter.rb to point to the excel file that should be imported."
23
+ raise
24
+ end
25
+
26
+ excel_workbook = MoveToGo::ExcelHelper.Open(EXCEL_FILE)
27
+
28
+ if defined?(COWORKER_SHEET)
29
+ if excel_workbook.has_sheet?(COWORKER_SHEET)
30
+ coworker_rows = excel_workbook.rows_for_sheet COWORKER_SHEET
31
+ else
32
+ puts "WARNING: can't find sheet '#{COWORKER_SHEET}'"
33
+ end
34
+ end
35
+
36
+ if defined?(ORGANIZATION_SHEET)
37
+ if excel_workbook.has_sheet?(ORGANIZATION_SHEET)
38
+ organization_rows = excel_workbook.rows_for_sheet ORGANIZATION_SHEET
39
+ converter.organization_hook(row, organization, rootmodel) if defined? converter.organization_hook
40
+ else
41
+ puts "WARNING: can't find sheet '#{ORGANIZATION_SHEET}'"
42
+ end
43
+ end
44
+
45
+ if defined?(PERSON_SHEET)
46
+ if excel_workbook.has_sheet?(PERSON_SHEET)
47
+ person_rows = excel_workbook.rows_for_sheet PERSON_SHEET
48
+ else
49
+ puts "WARNING: can't find sheet '#{PERSON_SHEET}'"
50
+ end
51
+ end
52
+
53
+ if defined?(DEAL_SHEET)
54
+ if excel_workbook.has_sheet?(DEAL_SHEET)
55
+ deal_rows = excel_workbook.rows_for_sheet DEAL_SHEET
56
+ else
57
+ puts "WARNING: can't find sheet '#{DEAL_SHEET}'"
58
+ end
59
+ end
60
+
61
+ if defined?(HISTORY_SHEET)
62
+ if excel_workbook.has_sheet?(HISTORY_SHEET)
63
+ history_rows = excel_workbook.rows_for_sheet HISTORY_SHEET
64
+ else
65
+ puts "WARNING: can't find sheet '#{HISTORY_SHEET}'"
66
+ end
67
+ end
68
+
69
+ if defined?(FILE_SHEET)
70
+ if excel_workbook.has_sheet?(FILE_SHEET)
71
+ file_rows = excel_workbook.rows_for_sheet FILE_SHEET
72
+ else
73
+ puts "WARNING: can't find sheet '#{FILE_SHEET}'"
74
+ end
75
+ end
76
+
77
+ # Then we create a rootmodel that will contain all data that
78
+ # should be exported to LIME Go.
79
+ rootmodel = MoveToGo::RootModel.new
80
+
81
+ # And configure the model if we have any custom fields
82
+ converter.configure rootmodel
83
+
84
+ # Now start to read data from the excel file and add to the
85
+ # rootmodel. We begin with coworkers since they are referenced
86
+ # from everywhere (orgs, deals, histories)
87
+ if defined?(coworker_rows) && !coworker_rows.nil?
88
+ puts "Trying to convert coworkers..."
89
+ coworker_rows.each do |row|
90
+ rootmodel.add_coworker(converter.to_coworker(row))
91
+ end
92
+ end
93
+
94
+ # Then create organizations, they are only referenced by
95
+ # coworkers.
96
+ if defined?(organization_rows) && !organization_rows.nil?
97
+ puts "Trying to convert organizations..."
98
+ organization_rows.with_progress().each do |row|
99
+ organization = converter.to_organization(row, rootmodel)
100
+ rootmodel.add_organization(organization)
101
+ end
102
+ end
103
+
104
+ # Add people and link them to their organizations
105
+ if defined?(person_rows) && !person_rows.nil?
106
+ puts "Trying to convert persons..."
107
+ person_rows.with_progress().each do |row|
108
+ # People are special since they are not added directly to
109
+ # the root model
110
+ converter.import_person_to_organization(row, rootmodel)
111
+ end
112
+ end
113
+
114
+ # Deals can connected to coworkers, organizations and people.
115
+ if defined?(deal_rows) && !deal_rows.nil?
116
+ puts "Trying to convert deals..."
117
+ deal_rows.with_progress().each do |row|
118
+ rootmodel.add_deal(converter.to_deal(row, rootmodel))
119
+ end
120
+ end
121
+
122
+ # History must be owned by a coworker and the be added to
123
+ # organizations and histories and might refernce a person
124
+ if defined?(history_rows) && !history_rows.nil?
125
+ puts "Trying to convert histories..."
126
+ history_rows.with_progress().each do |row|
127
+ rootmodel.add_history(converter.to_history(row, rootmodel))
128
+ end
129
+ end
130
+
131
+ if defined?(file_rows) && !file_rows.nil?
132
+ puts "Trying to convert files..."
133
+ file_rows.with_progress().each do |row|
134
+ rootmodel.add_file(converter.to_file(row, rootmodel))
135
+ end
136
+ end
137
+
138
+ return rootmodel
139
+ end
140
+
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'roo', '~> 2.0'
5
+ gem 'thor'
6
+ gem 'move-to-go'
7
+ gem 'progress'
@@ -0,0 +1,188 @@
1
+ # encoding: UTF-8
2
+ require 'move-to-go'
3
+ require 'roo'
4
+
5
+ # This Converter will convert an Excel file to a XML file that can be
6
+ # imported into LIME Go.
7
+ #
8
+ # You need to customize this script to suit your Excel file.
9
+
10
+ # First set the name of the Excel file to convert. It is a filename
11
+ # relative to this folder.
12
+ EXCEL_FILE = "sample-data.xlsx"
13
+
14
+ COWORKER_SHEET = "Medarbetare"
15
+ ORGANIZATION_SHEET = "Företag"
16
+ PERSON_SHEET = "Kontaktperson"
17
+ DEAL_SHEET = "Affär"
18
+ HISTORY_SHEET = "Anteckningar"
19
+ FILE_SHEET = "Dokument"
20
+
21
+ # Then you need to modify the script below according to the TODO
22
+ # comments.
23
+
24
+ # To generate the xml-file that should be sent to LIME Go with the
25
+ # command:
26
+ # move-to-go run
27
+
28
+ # If you are importing files then you must set the FILES_FOLDER
29
+ # constant. FILES_FOLDER should point to the folder where the files
30
+ # are stored. FILES_FOLDER can be relative to the project directory
31
+ # or absolute. Note that you need to escape \ with a \ so in order to
32
+ # write \ use \\.
33
+ FILES_FOLDER = "./files"
34
+
35
+ # If you are importing files with an absolute path (eg
36
+ # m:\documents\readme.doc) then you probably wont have files at that
37
+ # location on the computer where "move-to-go run" is executed. Set
38
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
39
+ # the customers site. Ie, in this example m:\documents.
40
+ # Note that you need to escape \ with a \ so in order to write \ use
41
+ # \\.
42
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
43
+
44
+ class Converter
45
+ def configure(rootmodel)
46
+ # *** TODO: Add custom field to your rootmodel here. Custom fields
47
+ # can be added to organization, deal and person. Valid types
48
+ # are :String and :Link. If no type is specified :String is
49
+ # used as default.
50
+
51
+ # rootmodel.settings.with_organization do |organization|
52
+ # organization.set_custom_field( { :integration_id => 'source', :title => 'Källa', :type => :Link } )
53
+ # end
54
+
55
+ # rootmodel.settings.with_person do |person|
56
+ # person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe size', :type => :String} )
57
+ # end
58
+
59
+ # rootmodel.settings.with_deal do |deal|
60
+ # assessment is default DealState::NoEndState
61
+ # deal.add_status( {:label => '1. Kvalificering' })
62
+ # deal.add_status( {:label => '2. Deal closed', :assessment => MoveToGo::DealState::PositiveEndState })
63
+ # deal.add_status( {:label => '4. Deal lost', :assessment => MoveToGo::DealState::NegativeEndState })
64
+ # end
65
+ end
66
+
67
+ def import_person_to_organization(row, rootmodel)
68
+ person = to_person(row, rootmodel)
69
+ organization = rootmodel.find_organization_by_integration_id(row['ID'])
70
+
71
+ if !organization.nil?
72
+ organization.add_employee(person)
73
+ end
74
+ end
75
+
76
+ def to_coworker(row)
77
+ coworker = MoveToGo::Coworker.new()
78
+
79
+ # *** TODO:
80
+ #
81
+ # Set coworker properties from the row.
82
+
83
+ coworker.parse_name_to_firstname_lastname_se row['Namn/Titel']
84
+ coworker.integration_id = row['Namn/Titel']
85
+ if MoveToGo::EmailHelper.is_valid?(row['Email'])
86
+ coworker.email = row['Email']
87
+ end
88
+
89
+ return coworker
90
+ end
91
+
92
+ def to_deal(row, rootmodel)
93
+ deal = MoveToGo::Deal.new()
94
+
95
+ # *** TODO:
96
+ #
97
+ # Set deal properties from the row.
98
+
99
+ return deal
100
+ end
101
+
102
+ def to_organization(row, rootmodel)
103
+ organization = MoveToGo::Organization.new()
104
+
105
+ # Integrationid is typically the id in the system that we are
106
+ # getting the csv from. Must be set to be able to import the
107
+ # same file more than once without creating duplicates
108
+ organization.integration_id = row['ID']
109
+
110
+ # Sets the organization's relation. Relation must be a value
111
+ # from MoveToGo::Relation.
112
+ organization.relation = MoveToGo::Relation::IsACustomer
113
+
114
+ # *** TODO:
115
+ #
116
+ # Set organization properties from the row.
117
+
118
+ organization.name = row['Namn']
119
+
120
+ # Set responsible such as
121
+ # organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(row['Medarbetare'])
122
+
123
+ # Custom fields should be set like this.
124
+ # organization.set_custom_value("source", "internet")
125
+
126
+ return organization
127
+ end
128
+
129
+ def to_person(row, rootmodel)
130
+ person = MoveToGo::Person.new()
131
+
132
+ # *** TODO:
133
+ #
134
+ # Set person properties from the row.
135
+
136
+ person.parse_name_to_firstname_lastname_se(row['Namn'])
137
+ if MoveToGo::EmailHelper.is_valid?(row['Email'])
138
+ person.email = row['Email']
139
+ end
140
+ person.mobile_phone_number, person.direct_phone_number =
141
+ MoveToGo::PhoneHelper.parse_numbers(row['Telefon'], [",", "/", "\\"])
142
+
143
+ return person
144
+ end
145
+
146
+ def to_history(row, rootmodel)
147
+ history = MoveToGo::History.new()
148
+
149
+ # *** TODO:
150
+ #
151
+ # Set history properties from the row.
152
+
153
+ history.organization = rootmodel.find_organization_by_integration_id(row['ID'])
154
+ history.created_by = rootmodel.find_coworker_by_integration_id(row['Skapad av'])
155
+ history.text = row['Text']
156
+ history.date = row['Skapad den']
157
+
158
+ return history
159
+ end
160
+
161
+ def to_file(row, rootmodel)
162
+ file = MoveToGo::File.new()
163
+
164
+ file.organization = rootmodel.find_organization_by_integration_id(row['Företag'])
165
+ file.created_by = rootmodel.find_coworker_by_integration_id(row['Skapad Av'])
166
+ file.name = row['Namn']
167
+ file.description = row['Kommentar']
168
+ file.path = row['Path']
169
+
170
+ return file
171
+ end
172
+
173
+ # HOOKS
174
+ #
175
+ # Sometimes you need to add exra information to the rootmodel, this can be done
176
+ # with hooks, below is an example of an organization hook that adds a comment to
177
+ # an organization if a field has a specific value
178
+ #def organization_hook(row, organization, rootmodel)
179
+ # if not row['fieldname'].empty?
180
+ # comment = MoveToGo::Comment.new
181
+ # comment.text = row['fieldname']
182
+ # comment.organization = organization
183
+ # comment.created_by = rootmodel.migrator_coworker
184
+ # rootmodel.add_comment(comment)
185
+ # end
186
+ #end
187
+
188
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,14 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+ # Ignore built gems
10
+ /*.gem
11
+ # Ignore all logfiles and tempfiles.
12
+ /tmp
13
+ /spec/tmp
14
+ pkg
@@ -0,0 +1,3 @@
1
+ The Excel Basic source should be used when we have a customer that has some unstructured data they want to import to LIME Go.
2
+
3
+ When the ask "do you have an excel tempate we can use?" we should create a project from this source and send them the 'Exempelfil.xslx'. When we get the excelfile back, copy it to the project folder and run 'move-to-go run'.
@@ -0,0 +1,139 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'move-to-go'
4
+ require 'roo'
5
+ require_relative("../converter")
6
+
7
+ def convert_source
8
+ puts "Trying to convert Excel source to LIME Go..."
9
+
10
+ converter = Converter.new
11
+
12
+ # First we read each sheet from the excel file into separate
13
+ # variables
14
+
15
+ if defined?(EXCEL_FILE) && !EXCEL_FILE.empty?()
16
+ if !::File.exists?(EXCEL_FILE)
17
+ puts "ERROR: Cant find excel file to import: '#{EXCEL_FILE}'."
18
+ raise
19
+ end
20
+ else
21
+ puts "ERROR: You must set EXCEL_FILE in converter.rb to point to the excel file that should be imported."
22
+ raise
23
+ end
24
+
25
+ excel_workbook = MoveToGo::ExcelHelper.Open(EXCEL_FILE)
26
+
27
+ if defined?(COWORKER_SHEET)
28
+ if excel_workbook.has_sheet?(COWORKER_SHEET)
29
+ coworker_rows = excel_workbook.rows_for_sheet COWORKER_SHEET
30
+ else
31
+ puts "WARNING: can't find sheet '#{COWORKER_SHEET}'"
32
+ end
33
+ end
34
+
35
+ if defined?(ORGANIZATION_SHEET)
36
+ if excel_workbook.has_sheet?(ORGANIZATION_SHEET)
37
+ organization_rows = excel_workbook.rows_for_sheet ORGANIZATION_SHEET
38
+ converter.organization_hook(row, organization, rootmodel) if defined? converter.organization_hook
39
+ else
40
+ puts "WARNING: can't find sheet '#{ORGANIZATION_SHEET}'"
41
+ end
42
+ end
43
+
44
+ if defined?(PERSON_SHEET)
45
+ if excel_workbook.has_sheet?(PERSON_SHEET)
46
+ person_rows = excel_workbook.rows_for_sheet PERSON_SHEET
47
+ else
48
+ puts "WARNING: can't find sheet '#{PERSON_SHEET}'"
49
+ end
50
+ end
51
+
52
+ if defined?(DEAL_SHEET)
53
+ if excel_workbook.has_sheet?(DEAL_SHEET)
54
+ deal_rows = excel_workbook.rows_for_sheet DEAL_SHEET
55
+ else
56
+ puts "WARNING: can't find sheet '#{DEAL_SHEET}'"
57
+ end
58
+ end
59
+
60
+ if defined?(HISTORY_SHEET)
61
+ if excel_workbook.has_sheet?(HISTORY_SHEET)
62
+ history_rows = excel_workbook.rows_for_sheet HISTORY_SHEET
63
+ else
64
+ puts "WARNING: can't find sheet '#{HISTORY_SHEET}'"
65
+ end
66
+ end
67
+
68
+ if defined?(FILE_SHEET)
69
+ if excel_workbook.has_sheet?(FILE_SHEET)
70
+ file_rows = excel_workbook.rows_for_sheet FILE_SHEET
71
+ else
72
+ puts "WARNING: can't find sheet '#{FILE_SHEET}'"
73
+ end
74
+ end
75
+
76
+ # Then we create a rootmodel that will contain all data that
77
+ # should be exported to LIME Go.
78
+ rootmodel = MoveToGo::RootModel.new
79
+
80
+ # And configure the model if we have any custom fields
81
+ converter.configure rootmodel
82
+
83
+ # Now start to read data from the excel file and add to the
84
+ # rootmodel. We begin with coworkers since they are referenced
85
+ # from everywhere (orgs, deals, histories)
86
+ if defined?(coworker_rows) && !coworker_rows.nil?
87
+ puts "Trying to convert coworkers..."
88
+ coworker_rows.each do |row|
89
+ rootmodel.add_coworker(converter.to_coworker(row))
90
+ end
91
+ end
92
+
93
+ # Then create organizations, they are only referenced by
94
+ # coworkers.
95
+ if defined?(organization_rows) && !organization_rows.nil?
96
+ puts "Trying to convert organizations..."
97
+ organization_rows.each do |row|
98
+ organization = converter.to_organization(row, rootmodel)
99
+ rootmodel.add_organization(organization)
100
+ end
101
+ end
102
+
103
+ # Add people and link them to their organizations
104
+ if defined?(person_rows) && !person_rows.nil?
105
+ puts "Trying to convert persons..."
106
+ person_rows.each do |row|
107
+ # People are special since they are not added directly to
108
+ # the root model
109
+ converter.import_person_to_organization(row, rootmodel)
110
+ end
111
+ end
112
+
113
+ # Deals can connected to coworkers, organizations and people.
114
+ if defined?(deal_rows) && !deal_rows.nil?
115
+ puts "Trying to convert deals..."
116
+ deal_rows.each do |row|
117
+ rootmodel.add_deal(converter.to_deal(row, rootmodel))
118
+ end
119
+ end
120
+
121
+ # histories must be owned by a coworker and the be added to
122
+ # organizations and histories and might refernce a person
123
+ if defined?(history_rows) && !history_rows.nil?
124
+ puts "Trying to convert history..."
125
+ history_rows.each do |row|
126
+ rootmodel.add_history(converter.to_history(row, rootmodel))
127
+ end
128
+ end
129
+
130
+ if defined?(file_rows) && !file_rows.nil?
131
+ puts "Trying to convert files..."
132
+ file_rows.each do |row|
133
+ rootmodel.add_file(converter.to_file(row, rootmodel))
134
+ end
135
+ end
136
+
137
+ return rootmodel
138
+ end
139
+
Binary file
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'roo', '~> 2.0'
5
+ gem 'thor'
6
+ gem 'move-to-go'
@@ -0,0 +1,175 @@
1
+ # encoding: UTF-8
2
+ require 'move-to-go'
3
+ require 'roo'
4
+
5
+ # This Converter will convert an Excel file to a XML file that can be
6
+ # imported into LIME Go.
7
+ #
8
+ # You need to customize this script to suit your Excel file.
9
+
10
+ # First set the name of the Excel file to convert. It is a filename
11
+ # relative to this folder.
12
+ EXCEL_FILE = "Exempelfil.xlsx"
13
+
14
+ COWORKER_SHEET = "Medarbetare"
15
+ ORGANIZATION_SHEET = "Företag"
16
+ PERSON_SHEET = "Kontaktperson"
17
+ HISTORY_SHEET = "Anteckningar"
18
+
19
+ # Then you need to modify the script below according to the TODO
20
+ # comments.
21
+
22
+ # To generate the xml-file that should be sent to LIME Go with the
23
+ # command:
24
+ # move-to-go run
25
+
26
+ class Converter
27
+ def configure(rootmodel)
28
+ # *** TODO: Add custom field to your rootmodel here. Custom fields
29
+ # can be added to organization, deal and person. Valid types
30
+ # are :String and :Link. If no type is specified :String is
31
+ # used as default.
32
+
33
+ # Organizastion
34
+ # rootmodel.settings.with_organization do |organization|
35
+ # organization.set_custom_field( { :integration_id => 'source', :title => 'Källa', :type => :Link } )
36
+ # end
37
+
38
+ #Person
39
+ #rootmodel.settings.with_person do |person|
40
+ # person.set_custom_field( { :integration_id => 'shoe_size', :title => 'Shoe Size', :type => :String} )
41
+ #end
42
+
43
+ end
44
+
45
+ def import_person_to_organization(row, rootmodel)
46
+ person = to_person(row, rootmodel)
47
+ organization = rootmodel.find_organization_by_integration_id(row['Kundnummer/FöretagsID'])
48
+
49
+ if !organization.nil?
50
+ organization.add_employee(person)
51
+ end
52
+ end
53
+
54
+ def to_coworker(row)
55
+ coworker = MoveToGo::Coworker.new()
56
+
57
+ # *** TODO:
58
+ #
59
+ # Set coworker properties from the row.
60
+
61
+ coworker.parse_name_to_firstname_lastname_se row['Namn/Titel']
62
+ coworker.integration_id = row['Namn/Titel']
63
+ if MoveToGo::EmailHelper.is_valid?(row['Email'])
64
+ coworker.email = row['Email']
65
+ end
66
+
67
+ return coworker
68
+ end
69
+
70
+ def to_organization(row, rootmodel)
71
+ organization = MoveToGo::Organization.new()
72
+
73
+ # Integrationid is typically the id in the system that we are
74
+ # getting the csv from. Must be set to be able to import the
75
+ # same file more than once without creating duplicates
76
+ organization.integration_id = row['Kundnummer/FöretagsID']
77
+
78
+ # Sets the organization's relation. Relation must be a value
79
+ # from MoveToGo::Relation.
80
+ organization.relation = MoveToGo::Relation::IsACustomer
81
+
82
+ # *** TODO:
83
+ #
84
+ # Set organization properties from the row.
85
+
86
+ organization.name = row['Namn']
87
+ organization.organization_number=row['Organisationsnummer']
88
+
89
+ # Postaladdress
90
+ organization.with_postal_address do |address|
91
+ address.street = row['Postadress']
92
+ address.zip_code = row['Postnummer']
93
+ address.city = row['Postnummer']
94
+ end
95
+
96
+ # Visitingaddress
97
+ organization.with_visit_address do |addr|
98
+ addr.street = row['Besöksadress']
99
+ addr.zip_code = row['Besökspostnummer']
100
+ addr.city = row['Besöksort']
101
+ end
102
+
103
+ # Set responsible such as
104
+ # organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(row['Ansvarig saljare'])
105
+
106
+ # Set categorytag
107
+ if row['Företagskategori']
108
+ category = row['Företagskategori'].split(',')
109
+ category.each do |categorytag|
110
+ organization.set_tag(categorytag.strip)
111
+ end
112
+ end
113
+
114
+ # Custom fields should be set like this.
115
+ # organization.set_custom_value("source", "internet")
116
+
117
+ ## LIME Go Relation.
118
+ # let's say that there is a option field in Easy called 'Customer relation'
119
+ # with the options '1.Customer', '2.Prospect' '3.Partner' and '4.Lost customer'
120
+
121
+ if row['Relation'] == 'Kund'
122
+ # We have made a deal with this organization.
123
+ organization.relation = MoveToGo::Relation::IsACustomer
124
+ elsif row['Relation'] == 'Prospekt'
125
+ # Something is happening with this organization, we might have
126
+ # booked a meeting with them or created a deal, etc.
127
+ organization.relation = MoveToGo::Relation::WorkingOnIt
128
+ elsif row['Relation'] == 'Tidigare kund'
129
+ organization.relation = MoveToGo::Relation::WasACustomer
130
+ # We had something going with this organization but we
131
+ # couldn't close the deal and we don't think they will be a
132
+ # customer to us in the foreseeable future.
133
+ # organization.relation = MoveToGo::Relation::BeenInTouch
134
+ else
135
+ organization.relation = MoveToGo::Relation::NoRelation
136
+ end
137
+
138
+ return organization
139
+ end
140
+
141
+ def to_person(row, rootmodel)
142
+ person = MoveToGo::Person.new()
143
+
144
+ # *** TODO:
145
+ #
146
+ # Set person properties from the row.
147
+
148
+ person.parse_name_to_firstname_lastname_se(row['Namn'])
149
+ if MoveToGo::EmailHelper.is_valid?(row['Email'])
150
+ person.email = row['Email']
151
+ end
152
+
153
+ person.direct_phone_number = row['Telefon']
154
+ person.mobile_phone_number = row['Mobiltelefon']
155
+
156
+ person.position = row['Titel']
157
+
158
+ return person
159
+ end
160
+
161
+ def to_history(row, rootmodel)
162
+ history = MoveToGo::History.new()
163
+
164
+ # *** TODO:
165
+ #
166
+ # Set history properties from the row.
167
+
168
+ history.organization = rootmodel.find_organization_by_integration_id(row['Kundnummer/FöretagsID'])
169
+ history.created_by = rootmodel.find_coworker_by_integration_id(row['Skapad av medarbetare'])
170
+ history.text = row['Textanteckningar/Historik']
171
+ history.date = row['Skapad den']
172
+
173
+ return history
174
+ end
175
+ end