go_import 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/bin/go-import +6 -2
  2. data/lib/go_import/model/deal_class_settings.rb +2 -0
  3. data/lib/go_import/model/rootmodel.rb +1 -1
  4. data/lib/go_import.rb +0 -1
  5. data/sources/VISMA/.gitignore +14 -0
  6. data/sources/VISMA/.go_import/runner.rb +77 -0
  7. data/sources/VISMA/Database/KONTAKT.DBF +0 -0
  8. data/sources/VISMA/Database/KUND.DBF +0 -0
  9. data/sources/VISMA/Gemfile +5 -0
  10. data/sources/VISMA/converter.rb +104 -0
  11. data/sources/VISMA/tomodel.rb +202 -0
  12. data/sources/csv/Gemfile +1 -1
  13. data/sources/custom/.gitignore +14 -0
  14. data/sources/custom/.go_import/runner.rb +30 -0
  15. data/sources/custom/Gemfile +4 -0
  16. data/sources/custom/converter.rb +29 -0
  17. data/sources/easy/.go_import/runner.rb +74 -86
  18. data/sources/easy/Gemfile +1 -1
  19. data/sources/easy/converter.rb +21 -147
  20. data/sources/excel/Gemfile +1 -1
  21. data/sources/excel/converter.rb +1 -1
  22. metadata +14 -18
  23. data/sources/csv/Rakefile.rb +0 -7
  24. data/sources/csv/spec/exporter_spec.rb +0 -17
  25. data/sources/csv/spec/sample_data/coworkers.csv +0 -2
  26. data/sources/csv/spec/sample_data/deals.csv +0 -2
  27. data/sources/csv/spec/sample_data/organizations.csv +0 -2
  28. data/sources/csv/spec/sample_data/persons.csv +0 -2
  29. data/sources/csv/spec/spec_helper.rb +0 -30
  30. data/sources/easy/Rakefile.rb +0 -7
  31. data/sources/easy/spec/exporter_spec.rb +0 -10
  32. data/sources/easy/spec/sample_data/Company.txt +0 -649
  33. data/sources/easy/spec/spec_helper.rb +0 -30
  34. data/sources/excel/Rakefile.rb +0 -7
  35. data/sources/excel/spec/sample_data/sample.xlsx +0 -0
  36. data/sources/excel/spec/spec_helper.rb +0 -26
  37. data/sources/excel/spec/tomodel_spec.rb +0 -18
  38. /data/sources/excel/{template.xlsx → sample-data.xlsx} +0 -0
data/bin/go-import CHANGED
@@ -43,7 +43,11 @@ class GoImportCommandLine < Thor
43
43
  end
44
44
  end
45
45
 
46
- desc "run", "Executes the current project and create a go-import.xml file. Existing go-import.xml will be overwritten, use -o to specify a different filename"
46
+ desc "run", "Executes the current project and create a go.xml file. Existing go.xml will be overwritten, use --output to specify a different filename"
47
+ option(:output,
48
+ :desc => "Name of the file where the converted source will be saved. This file should be sent to LIME Go. If the file already exist it will be replaced.",
49
+ :type => :string,
50
+ :required => false)
47
51
  def run_import()
48
52
  # run is a Thor reserved word and cant be used as a method name
49
53
 
@@ -66,7 +70,7 @@ class GoImportCommandLine < Thor
66
70
  # returns an instance of GoImport::RootModel
67
71
  model = convert_source()
68
72
 
69
- go_data_filename = "go.xml"
73
+ go_data_filename = options.output.nil? == true ? "go.xml" : options.output
70
74
 
71
75
  error = model.sanity_check
72
76
  if error.empty?
@@ -1,4 +1,6 @@
1
1
  # encoding: utf-8
2
+ require_relative 'class_settings'
3
+
2
4
  module GoImport
3
5
  class DealClassSettings < ClassSettings
4
6
  attr_reader :statuses
@@ -114,7 +114,7 @@ module GoImport
114
114
  organization = Organization.new(organization) if !organization.is_a?(Organization)
115
115
 
116
116
  if find_organization_by_integration_id(organization.integration_id) != nil
117
- raise AlreadyAddedError, "Already added an organization with integration_id #(organization.integration_id)"
117
+ raise AlreadyAddedError, "Already added an organization with integration_id #{organization.integration_id}"
118
118
  end
119
119
 
120
120
  @organizations.push(organization)
data/lib/go_import.rb CHANGED
@@ -7,7 +7,6 @@ module GoImport
7
7
  require 'go_import/errors'
8
8
  require 'go_import/serialize_helper'
9
9
  require 'go_import/model_helpers'
10
- #FruitToLime::require_all_in 'go_import/model/*.rb'
11
10
  GoImport::require_all_in 'go_import/model/*.rb'
12
11
  require 'go_import/csv_helper'
13
12
  require 'go_import/roo_helper'
@@ -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,77 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'go_import'
4
+ #require 'roo'
5
+ require 'dbf'
6
+ require_relative("../converter")
7
+
8
+ KUND_FILE = './database/KUND.DBF'
9
+ KONTAKT_FILE = './database/KONTAKT.DBF'
10
+
11
+ def convert_source
12
+ puts "Trying to convert VISMA source to LIME Go..."
13
+
14
+ # Verify that required files exists.
15
+ if !File.exists?(KUND_FILE)
16
+ puts "You MUST put KUND.DBF in the database folder."
17
+ raise
18
+ end
19
+
20
+ if !File.exists?(KONTAKT_FILE)
21
+ puts "You MUST put KONTAKT.DBF in the database folder."
22
+ raise
23
+ end
24
+
25
+ puts "Trying to read data from VISMA files..."
26
+ organization_rows = DBF::Table.new(KUND_FILE)
27
+ person_rows = DBF::Table.new(KONTAKT_FILE)
28
+
29
+ rootmodel = GoImport::RootModel.new
30
+ converter = Converter.new
31
+
32
+ converter.configure rootmodel
33
+
34
+ # Then create organizations, they are only referenced by
35
+ # coworkers.
36
+ puts "Trying to process Organization..."
37
+ organization_rows.each do |row|
38
+ if not row.nil?
39
+ if not row["NAMN"] == ""
40
+ rootmodel.add_organization(converter.to_organization(row, rootmodel))
41
+ end
42
+ end
43
+ end
44
+ puts "Processed #{rootmodel.organizations.length} Organizations."
45
+
46
+ # Add people and link them to their organizations
47
+ puts "Trying to process Persons..."
48
+ imported_person_count = 0
49
+ person_rows.each do |row|
50
+ # People are special since they are not added directly to
51
+ # the root model
52
+ if not row.nil?
53
+ if not row["KUNDNR"] == "" and not row["NAMN"] == ""
54
+ converter.import_person_to_organization(row, rootmodel)
55
+ imported_person_count = imported_person_count + 1
56
+ end
57
+ end
58
+ end
59
+ puts "Processed #{imported_person_count} Persons."
60
+
61
+ # Notes must be owned by a coworker and the be added to
62
+ # organizations and notes and might refernce a person
63
+ puts "Trying to process Notes..."
64
+ imported_note_count = 0
65
+ organization_rows.each do |row|
66
+ if not row.nil?
67
+ if row['ANTECK_1'].length > 0
68
+ rootmodel.add_note(converter.to_note(row))
69
+ imported_note_count = imported_note_count + 1
70
+ end
71
+ end
72
+ end
73
+ puts "Processed #{imported_note_count} Notes."
74
+
75
+ return rootmodel
76
+ end
77
+
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'go_import'
5
+ gem 'dbf'
@@ -0,0 +1,104 @@
1
+ require 'go_import'
2
+ require 'dbf'
3
+
4
+ # Customize this file to suit your input for a VISMA database.
5
+ #
6
+ # You must put KUND.DBS and KONTAKTER.DBS in the database folder.
7
+ #
8
+ # Documentation go_import can be found at
9
+ # http://rubygems.org/gems/go_import
10
+ #
11
+ # go_import contains all objects in LIME Go such as organizations,
12
+ # people, deals, etc. What properties each object has is described in
13
+ # the documentation.
14
+ #
15
+ # Generate the xml-file that should be sent to LIME Go with the command:
16
+ # go-import run
17
+
18
+ class Converter
19
+ def configure(rootmodel)
20
+ # Add custom field to your model here. Custom fields can be
21
+ # added to organization, deal and person. Valid types are
22
+ # :String and :Link. If no type is specified :String is used
23
+ # as default.
24
+
25
+ #Creates a custom field to add invoicing data
26
+ rootmodel.settings.with_organization do |org|
27
+ org.set_custom_field( { :integrationid => 'ackoms', :title => 'Fakturerat', :type => :String } )
28
+ end
29
+ end
30
+
31
+ def import_person_to_organization(row, rootmodel)
32
+ organization = rootmodel.find_organization_by_integration_id(row['KUNDNR'])
33
+
34
+ if !organization.nil?
35
+ organization.add_employee(to_person(row, rootmodel))
36
+ end
37
+ end
38
+
39
+ def to_organization(row, rootmodel)
40
+ organization = GoImport::Organization.new()
41
+
42
+ #Add tags:
43
+ organization.set_tag "Importerad"
44
+ organization.set_tag "Kund"
45
+
46
+ organization.name = row['NAMN']
47
+ # Integrationid must be set to be able to import the same file
48
+ # more than once without creating duplicates
49
+ organization.integration_id = row['KUNDNR']
50
+
51
+ #address
52
+ organization.with_postal_address do |address|
53
+ address.street = row['POSTADR']
54
+ address.zip_code = row['POSTNR']
55
+ address.city = row['ORT']
56
+ end
57
+
58
+ organization.email = row['EPOST']
59
+ organization.organization_number = row['ORGNR']
60
+ organization.central_phone_number = row['TEL']
61
+
62
+ # Sets the organization's relation. Relation must be a value
63
+ # from GoImport::Relation.
64
+ organization.relation = GoImport::Relation::IsACustomer
65
+
66
+ #Fill data to custom fields
67
+ organization.set_custom_field({:integration_id => "ackoms", :value => row["ACKOMS"]})
68
+
69
+ return organization
70
+ end
71
+
72
+ def to_note(row, rootmodel)
73
+ note = GoImport::Note.new()
74
+
75
+ # *** TODO:
76
+ #
77
+ # Set note properties from the row.
78
+ organization = rootmodel.find_organization_by_integration_id(row['KUNDNR'])
79
+ unless organization.nil?
80
+ note.organization = organization
81
+ end
82
+ note.created_by = rootmodel.import_coworker
83
+ note.text = row['ANTECK_1']
84
+
85
+ return note
86
+ end
87
+
88
+ def to_person(row, rootmodel)
89
+ person = GoImport::Person.new()
90
+
91
+ # *** TODO:
92
+ #
93
+ # Set person properties from the row.
94
+
95
+ person.parse_name_to_firstname_lastname_se(row['NAMN'])
96
+ if GoImport::EmailHelper.is_valid?(row['EPOST'])
97
+ person.email = row['EPOST']
98
+ end
99
+ person.mobile_phone_number = GoImport::PhoneHelper.parse_numbers(row['MBTEL'], [",", "/", "\\"])
100
+ person.direct_phone_number = GoImport::PhoneHelper.parse_numbers(row['TEL'], [",", "/", "\\"])
101
+
102
+ return person
103
+ end
104
+ end
@@ -0,0 +1,202 @@
1
+ require 'go_import'
2
+ require 'roo'
3
+ require 'dbf'
4
+
5
+ # Customize this file to suit your input for a VISMA database.
6
+ # You'll need KUND.DBS and KONTAKTER.DBS
7
+ #
8
+ # Documentation go_import can be found at
9
+ # http://rubygems.org/gems/go_import
10
+ #
11
+ # go_import contains all objects in LIME Go such as organization,
12
+ # people, deals, etc. What properties each object has is described in
13
+ # the documentation.
14
+
15
+ # *** TODO:
16
+ #
17
+ # This template will convert the files KUNDER.dbs and KONTAKTER.DBS to LIME Go. You
18
+ # should modify the Converted class suit your input file.
19
+ #
20
+ # Try this template with the template.xlsx file to generate a go.xml
21
+ #file:
22
+ # ruby convert.rb to_go lime-go.xml
23
+
24
+ class Converter
25
+ def configure(model)
26
+ # Add custom field to your model here. Custom fields can be
27
+ # added to organization, deal and person. Valid types are
28
+ # :String and :Link. If no type is specified :String is used
29
+ # as default.
30
+
31
+ #Creates a custom field to add invoicing data
32
+ model.settings.with_organization do |org|
33
+ org.set_custom_field( { :integrationid => 'ackoms', :title => 'Fakturerat', :type => :String } )
34
+ end
35
+ end
36
+
37
+ def import_person_to_organization(row)
38
+ person = to_person(row)
39
+ organization = @rootmodel.find_organization_by_integration_id(row['KUNDNR'])
40
+
41
+ if !organization.nil?
42
+ organization.add_employee(person)
43
+ end
44
+ end
45
+
46
+ def to_organization(row)
47
+ organization = GoImport::Organization.new()
48
+
49
+ #Add tags:
50
+ organization.set_tag "Importerad"
51
+ organization.set_tag "Kund"
52
+
53
+ organization.name = row['NAMN']
54
+ # Integrationid is typically the id in the system that we are
55
+ # getting the csv from. Must be set to be able to import the
56
+ # same file more than once without creating duplicates
57
+ organization.integration_id = row['KUNDNR']
58
+
59
+ #address
60
+ organization.with_postal_address do |address|
61
+ address.street = row['POSTADR']
62
+ address.zip_code = row['POSTNR']
63
+ address.city = row['ORT']
64
+ end
65
+
66
+ organization.email = row['EPOST']
67
+ organization.organization_number = row['ORGNR']
68
+ organization.central_phone_number = row['TEL']
69
+
70
+ # Sets the organization's relation. Relation must be a value
71
+ # from GoImport::Relation.
72
+ organization.relation = GoImport::Relation::IsACustomer
73
+
74
+ #Fill data to custom fields
75
+ organization.set_custom_field({:integration_id=>"ackoms", :value=>row["ACKOMS"]})
76
+
77
+ return organization
78
+ end
79
+
80
+ def to_note(row)
81
+ note = GoImport::Note.new()
82
+
83
+ # *** TODO:
84
+ #
85
+ # Set note properties from the row.
86
+ organization = @rootmodel.find_organization_by_integration_id(row['KUNDNR'])
87
+ unless organization.nil?
88
+ note.organization = organization
89
+ end
90
+ note.created_by = @rootmodel.import_coworker
91
+ note.text = row['ANTECK_1']
92
+
93
+ return note
94
+ end
95
+
96
+ def to_person(row)
97
+ person = GoImport::Person.new()
98
+
99
+ # *** TODO:
100
+ #
101
+ # Set person properties from the row.
102
+
103
+ person.parse_name_to_firstname_lastname_se(row['NAMN'])
104
+ if GoImport::EmailHelper.is_valid?(row['EPOST'])
105
+ person.email = row['EPOST']
106
+ end
107
+ person.mobile_phone_number = GoImport::PhoneHelper.parse_numbers(row['MBTEL'], [",", "/", "\\"])
108
+ person.direct_phone_number = GoImport::PhoneHelper.parse_numbers(row['TEL'], [",", "/", "\\"])
109
+
110
+ return person
111
+ end
112
+
113
+ def to_model()
114
+ # First we read each database into separate variables
115
+ puts "Reading data from './Databas/'"
116
+ organization_rows = DBF::Table.new("./Databas/KUND.DBF")
117
+ person_rows = DBF::Table.new("./Databas/KONTAKT.DBF")
118
+
119
+ # Then we create a rootmodel that should contain all data that
120
+ # should be exported to LIME Go.
121
+ @rootmodel = GoImport::RootModel.new
122
+
123
+ # And configure the model if we have any custom fields
124
+ puts "Adding custom fields to model"
125
+ configure @rootmodel
126
+
127
+ # Then create organizations, they are only referenced by
128
+ # coworkers.
129
+ puts "Importing Organization..."
130
+ organization_rows.each do |row|
131
+ if not row.nil?
132
+ if not row["NAMN"] == ""
133
+ @rootmodel.add_organization(to_organization(row))
134
+ end
135
+ end
136
+ end
137
+ puts "Imported #{@rootmodel.organizations.length} Organization"
138
+
139
+ # Add people and link them to their organizations
140
+ puts "Importing Persons..."
141
+ imported_person_count = 0
142
+ person_rows.each do |row|
143
+ # People are special since they are not added directly to
144
+ # the root model
145
+ if not row.nil?
146
+ if not row["KUNDNR"] == "" and not row["NAMN"] == ""
147
+ import_person_to_organization(row)
148
+ imported_person_count = nbrPersons + 1
149
+ end
150
+ end
151
+ end
152
+ puts "Imported #{imported_person_count} Persons"
153
+
154
+ # Deals can connected to coworkers, organizations and people.
155
+ # deal_rows.each do |row|
156
+ # @rootmodel.add_deal(to_deal(row))
157
+ # end
158
+
159
+ # Notes must be owned by a coworker and the be added to
160
+ # organizations and notes and might refernce a person
161
+ puts "Importing Notes..."
162
+ organization_rows.each do |row|
163
+ if not row.nil?
164
+ if row['ANTECK_1'].length > 0
165
+ @rootmodel.add_note(to_note(row))
166
+ end
167
+ end
168
+ end
169
+
170
+ return @rootmodel
171
+ end
172
+ end
173
+
174
+ # You don't need to change anything below this line.
175
+
176
+ require "thor"
177
+ require "fileutils"
178
+ require 'pathname'
179
+
180
+ class Cli < Thor
181
+ desc "to_go GO_DATA_FILENAME", "Converts VISMA 'KUND.DBS' and 'KONTAKTER.DBS' to Go xml format. Place the DBS-files in the folder 'Databas'. GO_DATA_FILENAME is output file where Go xml will go."
182
+ def to_go(go_data_filename = nil)
183
+ go_data_filename = 'go-data.xml' if go_data_filename == nil
184
+ converter = Converter.new()
185
+ model = converter.to_model()
186
+ error = model.sanity_check
187
+ if error.empty?
188
+ validation_errors = model.validate
189
+
190
+ if validation_errors.empty?
191
+ model.serialize_to_file(go_data_filename)
192
+ puts "VISMA data has been converted into '#{go_data_filename}'."
193
+ else
194
+ puts "VISMA database could not be converted due to"
195
+ puts validation_errors
196
+ end
197
+ else
198
+ puts "VISMA database could not be converted due to"
199
+ puts error
200
+ end
201
+ end
202
+ end
data/sources/csv/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'thor'
4
- #gem 'go_import'
4
+ gem 'go_import'
5
5
  gem 'rspec'
@@ -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,30 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'go_import'
4
+ require_relative("../converter")
5
+
6
+ def convert_source
7
+ puts "Trying to convert a custom source to LIME Go..."
8
+
9
+ converter = Converter.new
10
+
11
+ if !converter.respond_to?(:to_go)
12
+ puts "The converter must have a method called to_go that returns an instance of GoImport::RootModel."
13
+ raise "The converter must have a method called to_go that returns an instance of GoImport::RootModel."
14
+ end
15
+
16
+ rootmodel = converter.to_go
17
+
18
+ if rootmodel.nil?
19
+ puts "The returned rootmodel is nil. You must return a GoImport::RootModel."
20
+ raise "The returned rootmodel is nil. You must return a GoImport::RootModel."
21
+ end
22
+
23
+ if !rootmodel.is_a?(GoImport::RootModel)
24
+ puts "The returned object is not an instance of GoImport::RootModel."
25
+ raise "The returned object is not an instance of GoImport::RootModel."
26
+ end
27
+
28
+ return rootmodel
29
+ end
30
+
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'go_import'
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'go_import'
3
+
4
+ # This Converter will convert a generic source to a XML file that can
5
+ # be imported into LIME Go.
6
+ #
7
+ # You MUST customzie this script to read a source and return a
8
+ # RootModel.
9
+ #
10
+ # Reference documentation for go_import can be found at
11
+ # https://rubygems.org/gems/go_import (click Documentation)
12
+ #
13
+ # Generate the xml-file that should be sent to LIME Go with the
14
+ # command:
15
+ # go-import run
16
+ #
17
+ # Good luck.
18
+
19
+ class Converter
20
+ def to_go()
21
+ rootmodel = GoImport::RootModel.new
22
+
23
+ # *** TODO:
24
+ #
25
+ # Configure the model and then add coworkers, organizations, etc
26
+
27
+ return rootmodel
28
+ end
29
+ end