netsuite_rails 0.3.4 → 0.3.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2f2197544aa8884365eda94c0b6d23069430e0e
4
- data.tar.gz: 65012b398bc868048b9de452df38820ac102f383
3
+ metadata.gz: e4bc78784fc838d1ba5ca38b3d83ce0f0007bde4
4
+ data.tar.gz: dbdf80d06619156e86871566b1b4e7e728d8571b
5
5
  SHA512:
6
- metadata.gz: c486c007a6d97f0633e82a2d37a7b57321de8115e0a99c80331978b86137b649820bc7bd28c17c6223adfaca23ccf11c1df2fcf2cc1dca4f8409362cdce2b6f2
7
- data.tar.gz: 87ef0a329e7ed7af87244d1b058dde0f390e5d887628dc200ee0f49c8d79f4aec525c879da73111003ced628549294d35261315adf0c453e0c0d27264b073423
6
+ metadata.gz: b246f111c66ac0c86d53c4b7164ace112a2fc22fe15ba664efd13063d59d149ba01824e484664995c28431e14fc0133c451b3389550fe0a9a7c1541cf962b08e
7
+ data.tar.gz: 60923ddc839b756f3a563e00e65138d5b4bd9003b200edc30111289f8ed75150b5164bdc9bbc00e5c6897c09195d19257ff5a521f52e4317ecb5c39b9a5bbc3f
@@ -252,7 +252,7 @@ module NetSuiteRails
252
252
  end
253
253
 
254
254
  def is_active_record_model?(local_record)
255
- local_record.class.ancestors.include?(ActiveRecord::Base)
255
+ defined?(::ActiveRecord::Base) && local_record.class.ancestors.include?(ActiveRecord::Base)
256
256
  end
257
257
 
258
258
  end
@@ -200,7 +200,7 @@ module NetSuiteRails
200
200
  netsuite_record.send(netsuite_field)
201
201
  end
202
202
 
203
- if field_value.blank?
203
+ if field_value.nil?
204
204
  # TODO possibly nil out the local value?
205
205
  next
206
206
  end
@@ -218,7 +218,7 @@ module NetSuiteRails
218
218
 
219
219
  # TODO should we just check for nil? vs present?
220
220
 
221
- if field_hints.has_key?(local_field) && field_value.present?
221
+ if field_hints.has_key?(local_field) && !field_value.nil?
222
222
  field_value = NetSuiteRails::Transformations.transform(field_hints[local_field], field_value, :pull)
223
223
  end
224
224
 
@@ -3,8 +3,7 @@ module NetSuiteRails
3
3
  module CompanyContactMatch
4
4
  extend self
5
5
 
6
- def match(company_customer, contact_data)
7
- # TODO set page size to a large number for this search
6
+ def match(company_customer, contact_data, update_contact_name: false, update_contact_email: false)
8
7
  search = NetSuite::Records::Contact.search({
9
8
  customerJoin: [
10
9
  {
@@ -14,13 +13,17 @@ module NetSuiteRails
14
13
  NetSuite::Records::Customer.new(internal_id: company_customer.internal_id)
15
14
  ]
16
15
  }
17
- ]
16
+ ],
17
+
18
+ preferences: {
19
+ page_size: 1_000
20
+ }
18
21
  })
19
22
 
20
23
  match_data = {
21
- email: contact_data[:email].dup,
22
- first_name: contact_data[:first_name].dup,
23
- last_name: contact_data[:last_name].dup
24
+ email: (contact_data[:email] || '').dup,
25
+ first_name: (contact_data[:first_name] || '').dup,
26
+ last_name: (contact_data[:last_name] || '').dup
24
27
  }
25
28
 
26
29
  match_data.
@@ -38,6 +41,13 @@ module NetSuiteRails
38
41
  # if no email match & name data is present try fuzzy matching
39
42
  if match_data[:first_name] && match_data[:last_name] && !contact_first_name.empty? && !contact_last_name.empty?
40
43
 
44
+ # TODO add logging for these interactions with NetSuite
45
+ if update_contact_email && order_payload[:email].present? && contact.email != order_payload[:email]
46
+ if !result.update(email: order_payload[:email])
47
+ raise "error updating email on contact"
48
+ end
49
+ end
50
+
41
51
  # TODO consider `self.fuzzy_name_matches?(contact_first_name, contact_last_name, match_data[:first_name], match_data[:last_name])`
42
52
  if contact_first_name == match_data[:first_name] && contact_last_name == match_data[:last_name]
43
53
  return contact
@@ -46,29 +56,31 @@ module NetSuiteRails
46
56
  end
47
57
 
48
58
  # try email match second
49
- # search.results.each do |contact|
50
- # contact_first_name = contact.first_name.downcase.strip rescue ''
51
- # contact_last_name = contact.last_name.downcase.strip rescue ''
52
-
53
- # # match on email
54
- # if match_data[:email] && contact.email && contact.email.downcase.strip == match_data[:email]
55
- # if match_data[:first_name] != contact_first_name || match_data[:last_name] != contact_last_name
56
- # # first name and/or last name did not match the input, update contact information
57
-
58
- # result = contact.update(
59
- # # use the first & last name from the payload; the match_data versions have been transformed
60
- # first_name: order_payload[:shipping_address][:firstname],
61
- # last_name: order_payload[:shipping_address][:lastname]
62
- # )
63
-
64
- # unless result
65
- # raise 'error updating name on contact placing order'
66
- # end
67
- # end
68
-
69
- # return contact
70
- # end
71
- # end
59
+ search.results.each do |contact|
60
+ contact_first_name = contact.first_name.downcase.strip rescue ''
61
+ contact_last_name = contact.last_name.downcase.strip rescue ''
62
+
63
+ # match on email
64
+ if match_data[:email] && contact.email && contact.email.downcase.strip == match_data[:email]
65
+ if match_data[:first_name] != contact_first_name || match_data[:last_name] != contact_last_name
66
+ # first name and/or last name did not match the input, update contact information
67
+
68
+ if update_contact_name
69
+ result = contact.update(
70
+ # use the first & last name from the payload; the match_data versions have been transformed
71
+ first_name: order_payload[:shipping_address][:firstname],
72
+ last_name: order_payload[:shipping_address][:lastname]
73
+ )
74
+
75
+ unless result
76
+ raise 'error updating name on contact placing order'
77
+ end
78
+ end
79
+ end
80
+
81
+ return contact
82
+ end
83
+ end
72
84
 
73
85
  nil
74
86
  end
@@ -30,6 +30,11 @@ module NetSuiteRails
30
30
  # eliminate the extension if the number is still too long
31
31
  formatted_phone.gsub!(/x.*$/, '') if formatted_phone.size > 22
32
32
 
33
+ # phone numbers less than 7 digits throw a fatal error
34
+ if formatted_phone.size < 7
35
+ return nil
36
+ end
37
+
33
38
  formatted_phone
34
39
  else
35
40
  phone
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "netsuite_rails"
7
- s.version = "0.3.4"
7
+ s.version = "0.3.5"
8
8
  s.authors = ["Michael Bianco"]
9
9
  s.email = ["mike@cliffsidemedia.com"]
10
10
  s.summary = %q{Write Rails applications that integrate with NetSuite}
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe NetSuiteRails::RecordSync do
4
4
  include ExampleModels
5
-
5
+
6
6
  context 'custom records' do
7
7
  it "should properly pull the NS rep" do
8
8
  allow(NetSuite::Records::CustomRecord).to receive(:get).with(hash_including(:internal_id => 234, type_id: 123))
@@ -13,4 +13,24 @@ describe NetSuiteRails::RecordSync do
13
13
  expect(NetSuite::Records::CustomRecord).to have_received(:get)
14
14
  end
15
15
  end
16
+
17
+ it 'properly extracts common record types' do
18
+ fake_customer_data = {
19
+ :is_inactive => false,
20
+ :phone => "123 456 7891",
21
+ :company_name => "Great Company",
22
+ :email => nil
23
+ }
24
+
25
+ expect(NetSuite::Records::Customer).to receive(:get)
26
+ .and_return(NetSuite::Records::Customer.new(fake_customer_data))
27
+
28
+ standard_record = StandardRecord.new netsuite_id: 123
29
+ standard_record.netsuite_pull
30
+
31
+ expect(standard_record.is_deleted).to eq(false)
32
+ expect(standard_record.phone).to eq(fake_customer_data[:phone])
33
+ expect(standard_record.company).to eq(fake_customer_data[:company_name])
34
+ expect(standard_record.email).to eq(fake_customer_data[:email])
35
+ end
16
36
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO https://github.com/NetSweet/netsuite_rails/issues/16
4
+ # there are still some unresolved issues with NS datetime/date conversions
5
+ # the tests + implementation may still not be correct.
6
+
7
+ describe NetSuiteRails::Routines do
8
+ describe '#company_contact_match' do
9
+ it "matches on first and last name first" do
10
+
11
+ end
12
+
13
+ it "matches on email if no name match is found" do
14
+
15
+ end
16
+
17
+ it "returns nil if no match is found" do
18
+
19
+ end
20
+
21
+ # TODO also handle updating contact information
22
+ end
23
+ end
@@ -13,6 +13,12 @@ describe NetSuiteRails::Transformations do
13
13
  NetSuiteRails::Configuration.netsuite_instance_time_zone_offset -6
14
14
  end
15
15
 
16
+ it 'nils out short phone numbers' do
17
+ short_phone_number = ' 301908 '
18
+
19
+ expect(NetSuiteRails::Transformations.phone(short_phone_number)).to be_nil
20
+ end
21
+
16
22
  it 'handles very long phone numbers' do
17
23
  long_phone_number = '+1 (549)-880-4834 ext. 51077'
18
24
 
@@ -4,18 +4,20 @@ module ExampleModels
4
4
  example_group.class_eval do
5
5
  before do
6
6
 
7
- define_model :standard_record, phone: :string, netsuite_id: :integer do
7
+ define_model :standard_record, email: :string, company: :string, phone: :string, netsuite_id: :integer, is_deleted: :boolean do
8
8
  include NetSuiteRails::RecordSync
9
9
 
10
10
  netsuite_record_class NetSuite::Records::Customer
11
11
  netsuite_sync :read_write
12
12
  netsuite_field_map({
13
+ :is_deleted => :is_inactive,
13
14
  :phone => :phone,
14
15
  :company => Proc.new do |local, netsuite, direction|
16
+ # NOTE this could be done by a simple mapping!
15
17
  if direction == :push
16
-
18
+ netsuite.company_name = local.company
17
19
  else
18
-
20
+ local.company = netsuite.company_name
19
21
  end
20
22
  end
21
23
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bianco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netsuite
@@ -122,6 +122,7 @@ files:
122
122
  - spec/models/poll_trigger_spec.rb
123
123
  - spec/models/record_sync/push_manager_spec.rb
124
124
  - spec/models/record_sync_spec.rb
125
+ - spec/models/routines_spec.rb
125
126
  - spec/models/spec_helper_spec.rb
126
127
  - spec/models/sync_trigger_spec.rb
127
128
  - spec/models/transformations_spec.rb
@@ -162,6 +163,7 @@ test_files:
162
163
  - spec/models/poll_trigger_spec.rb
163
164
  - spec/models/record_sync/push_manager_spec.rb
164
165
  - spec/models/record_sync_spec.rb
166
+ - spec/models/routines_spec.rb
165
167
  - spec/models/spec_helper_spec.rb
166
168
  - spec/models/sync_trigger_spec.rb
167
169
  - spec/models/transformations_spec.rb