netsuite 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -124,25 +124,23 @@ task.update :message => 'New Message'
124
124
 
125
125
  task.delete
126
126
 
127
- # using get_select_value with a custom record
128
- NetSuite::Records::BaseRefList.get_select_value(
129
- field: 'custrecord_something',
130
- customRecordType: {
131
- '@internalId' => 10,
132
- '@xsi:type' => 'customRecord'
133
- }
134
- )
135
-
136
127
  # using get_select_value with a standard record
137
128
  NetSuite::Records::BaseRefList.get_select_value(
138
129
  recordType: 'serviceSaleItem',
139
130
  field: 'taxSchedule'
140
131
  )
141
132
 
142
- # updating a custom field list
133
+ ```
134
+
135
+ #### Custom Records & Fields
136
+
137
+ ```ruby
138
+ # updating a custom field list on a record
139
+
143
140
  # you need to push ALL the values of ALL of the custom fields that you want set on the record
144
141
  # you can't just push the values of the fields that you want to update: all of the values of
145
142
  # other fields will then fall back to their default values
143
+
146
144
  contact = NetSuite::Records::Contact.get(12345)
147
145
  contact.custom_field_list.custentity_alistfield = { internal_id: 1 }
148
146
  contact.custom_field_list.custentity_abooleanfield = true
@@ -175,6 +173,14 @@ record = NetSuite::Records::CustomRecord.new(internal_id: 100)
175
173
  record.custom_field_list.custrecord_locationstate = "New Jersey"
176
174
  record.update(custom_field_list: record.custom_field_list, rec_type: NetSuite::Records::CustomRecord.new(internal_id: 10))
177
175
 
176
+ # using get_select_value with a custom record
177
+ NetSuite::Records::BaseRefList.get_select_value(
178
+ field: 'custrecord_something',
179
+ customRecordType: {
180
+ '@internalId' => 10,
181
+ '@xsi:type' => 'customRecord'
182
+ }
183
+ )
178
184
  ```
179
185
 
180
186
  #### Searching
@@ -3,6 +3,8 @@ module NetSuite
3
3
  extend self
4
4
 
5
5
  def reset!
6
+ NetSuite::Utilities.clear_cache!
7
+
6
8
  attributes.clear
7
9
  end
8
10
 
@@ -286,13 +288,17 @@ module NetSuite
286
288
  end
287
289
 
288
290
  def logger(value = nil)
289
- attributes[:logger] = if value.nil?
290
- ::Logger.new((log && !log.empty?) ? log : $stdout)
291
+ if value.nil?
292
+ attributes[:logger] ||= ::Logger.new((log && !log.empty?) ? log : $stdout)
291
293
  else
292
- value
294
+ attributes[:logger] = value
293
295
  end
294
296
  end
295
297
 
298
+ def logger=(value)
299
+ attributes[:logger] = value
300
+ end
301
+
296
302
  def silent(value=nil)
297
303
  self.silent = value if !value.nil?
298
304
  attributes[:silent]
@@ -20,11 +20,16 @@ module NetSuite
20
20
  :vsoe_auto_calc
21
21
 
22
22
  field :custom_field_list, CustomFieldList
23
- field :transaction_bill_address, BillAddress
24
23
  field :item_list, CreditMemoItemList
25
24
  field :apply_list, CreditMemoApplyList
26
25
  field :ship_group_list, SalesOrderShipGroupList
27
26
 
27
+ # field :bill_address_list,
28
+ field :transaction_bill_address, BillAddress
29
+
30
+ # NOTE only available on API > 2014_1
31
+ field :billing_address, Address
32
+
28
33
  read_only_fields :applied, :discount_total, :sub_total, :tax_total, :total, :unapplied
29
34
 
30
35
  record_refs :account, :bill_address_list, :created_from, :custom_form, :department, :discount_item, :entity, :gift_cert,
@@ -44,7 +44,7 @@ module NetSuite
44
44
 
45
45
  record_refs :account, :bill_address_list, :custom_form, :department, :entity, :klass, :partner,
46
46
  :posting_period, :ship_address_list, :terms, :location, :sales_rep, :tax_item, :created_from,
47
- :ship_method, :lead_source, :promo_code, :subsidiary, :currency
47
+ :ship_method, :lead_source, :promo_code, :subsidiary, :currency, :approval_status
48
48
 
49
49
  attr_reader :internal_id
50
50
  attr_accessor :external_id
@@ -1,23 +1,11 @@
1
1
  module NetSuite
2
2
  module Records
3
- class PricingMatrix
3
+ class PricingMatrix < Support::Sublist
4
4
  include Namespaces::PlatformCore
5
5
 
6
- def initialize(attributes = {})
7
- attributes[:pricing] = [attributes[:pricing]] unless
8
- attributes[:pricing].is_a? Array
9
- attributes[:pricing].each do |pricing|
10
- prices << RecordRef.new(pricing)
11
- end if attributes[:pricing]
12
- end
6
+ sublist :pricing, RecordRef
13
7
 
14
- def prices
15
- @prices ||= []
16
- end
17
-
18
- def to_record
19
- { "#{record_namespace}:item" => prices.map(&:to_record) }
20
- end
8
+ alias :prices :pricing
21
9
  end
22
10
  end
23
11
  end
@@ -32,8 +32,15 @@ module NetSuite
32
32
 
33
33
  http = Net::HTTP.new(uri.hostname, uri.port)
34
34
  http.use_ssl = USE_SSL
35
+ http.ssl_version = :TLSv1_2
35
36
  http.read_timeout = DEFAULT_TIMEOUT
36
- http.start {|http| http.request(method)}
37
+
38
+ # TODO username + password will be outputted to STDOUT if this is enabled
39
+ # if !NetSuite::Configuration.silent
40
+ # http.set_debug_output(NetSuite::Configuration.logger)
41
+ # end
42
+
43
+ http.start { |http| http.request(method) }
37
44
  end
38
45
 
39
46
  def auth_header(email, signature)
@@ -45,10 +52,7 @@ module NetSuite
45
52
  end
46
53
 
47
54
  def encode(unencoded_string)
48
- URI.escape(
49
- unencoded_string,
50
- /[#{URI::PATTERN::RESERVED}]/
51
- )
55
+ CGI.escape(unencoded_string)
52
56
  end
53
57
 
54
58
  end
@@ -4,6 +4,11 @@ module NetSuite
4
4
 
5
5
  # TODO need structured logger for various statements
6
6
 
7
+ def clear_cache!
8
+ @netsuite_get_record_cache = {}
9
+ @netsuite_find_record_cache = {}
10
+ end
11
+
7
12
  def append_memo(ns_record, added_memo, opts = {})
8
13
  opts[:skip_if_exists] ||= false
9
14
 
@@ -83,14 +88,29 @@ module NetSuite
83
88
  def get_record(record_klass, id, opts = {})
84
89
  opts[:external_id] ||= false
85
90
 
91
+ if opts[:cache]
92
+ @netsuite_get_record_cache ||= {}
93
+ @netsuite_get_record_cache[record_klass.to_s] ||= {}
94
+
95
+ if cached_record = @netsuite_get_record_cache[record_klass.to_s][id.to_i]
96
+ return cached_record
97
+ end
98
+ end
99
+
86
100
  begin
87
101
  # log.debug("get record", netsuite_record_type: record_klass.name, netsuite_record_id: id)
88
102
 
89
- if opts[:external_id]
90
- return backoff { record_klass.get(external_id: id) }
103
+ ns_record = if opts[:external_id]
104
+ backoff { record_klass.get(external_id: id) }
91
105
  else
92
- return backoff { record_klass.get(id) }
106
+ backoff { record_klass.get(id) }
107
+ end
108
+
109
+ if opts[:cache]
110
+ @netsuite_get_record_cache[record_klass.to_s][id.to_i] = ns_record
93
111
  end
112
+
113
+ return ns_record
94
114
  rescue ::NetSuite::RecordNotFound
95
115
  # log.warn("record not found", ns_record_type: record_klass.name, ns_record_id: id)
96
116
  return nil
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.5'
3
3
  end
@@ -261,4 +261,16 @@ describe NetSuite::Configuration do
261
261
  expect(config.wsdl_domain).to eq('webservices.sandbox.netsuite.com')
262
262
  end
263
263
 
264
+ describe '#logger=' do
265
+ let(:logger) { Logger.new(nil) }
266
+
267
+ before do
268
+ config.logger = logger
269
+ end
270
+
271
+ it 'sets logger' do
272
+ expect(config.logger).to eql(logger)
273
+ end
274
+ end
275
+
264
276
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Utilities do
4
+ describe '#get_record' do
5
+ it 'does not hit the netsuite API when caching is enabled' do
6
+ ns_account_id = 123
7
+ allow(NetSuite::Records::Account).to receive(:get).with(ns_account_id).once.and_return(
8
+ NetSuite::Records::Account.new(internal_id: ns_account_id)
9
+ )
10
+
11
+ ns_account = NetSuite::Utilities.get_record(NetSuite::Records::Account, ns_account_id, cache: true)
12
+ expect(ns_account.internal_id).to eq(ns_account_id)
13
+
14
+ ns_account = NetSuite::Utilities.get_record(NetSuite::Records::Account, ns_account_id, cache: true)
15
+ expect(ns_account.internal_id).to eq(ns_account_id)
16
+ end
17
+
18
+ it 'pulls a record by internal id' do
19
+ ns_account_id = 123
20
+ ns_account_external_id = "abc"
21
+ allow(NetSuite::Records::Account).to receive(:get).with({ external_id: ns_account_external_id }).once.and_return(
22
+ NetSuite::Records::Account.new(internal_id: ns_account_id)
23
+ )
24
+
25
+ ns_account = NetSuite::Utilities.get_record(NetSuite::Records::Account, ns_account_external_id, external_id: true)
26
+ expect(ns_account.internal_id).to eq(ns_account_id)
27
+ end
28
+
29
+ it 'pulls a record by external id' do
30
+ ns_account_id = 123
31
+ allow(NetSuite::Records::Account).to receive(:get).with(ns_account_id).once.and_return(
32
+ NetSuite::Records::Account.new(internal_id: ns_account_id)
33
+ )
34
+
35
+ ns_account = NetSuite::Utilities.get_record(NetSuite::Records::Account, ns_account_id)
36
+ expect(ns_account.internal_id).to eq(ns_account_id)
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-01 00:00:00.000000000 Z
13
+ date: 2016-11-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: savon
@@ -423,6 +423,7 @@ files:
423
423
  - spec/netsuite/support/sublist_spec.rb
424
424
  - spec/netsuite/utilities/request_spec.rb
425
425
  - spec/netsuite/utilities/roles_spec.rb
426
+ - spec/netsuite/utilities_spec.rb
426
427
  - spec/netsuite_spec.rb
427
428
  - spec/spec_helper.rb
428
429
  - spec/support/2015.wsdl
@@ -612,6 +613,7 @@ test_files:
612
613
  - spec/netsuite/support/sublist_spec.rb
613
614
  - spec/netsuite/utilities/request_spec.rb
614
615
  - spec/netsuite/utilities/roles_spec.rb
616
+ - spec/netsuite/utilities_spec.rb
615
617
  - spec/netsuite_spec.rb
616
618
  - spec/spec_helper.rb
617
619
  - spec/support/2015.wsdl