netsuite 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -167,6 +167,7 @@ module NetSuite
167
167
  autoload :UnitsType, 'netsuite/records/units_type'
168
168
  autoload :UnitsTypeUomList, 'netsuite/records/units_type_uom_list'
169
169
  autoload :UnitsTypeUom, 'netsuite/records/units_type_uom'
170
+ autoload :Vendor, 'netsuite/records/vendor'
170
171
  autoload :WorkOrder, 'netsuite/records/work_order'
171
172
  autoload :WorkOrderItem, 'netsuite/records/work_order_item'
172
173
  autoload :WorkOrderItemList, 'netsuite/records/work_order_item_list'
@@ -176,4 +177,21 @@ module NetSuite
176
177
  NetSuite::Configuration.instance_eval(&block)
177
178
  end
178
179
 
180
+ def self.configure_from_env
181
+ NetSuite.configure do
182
+ reset!
183
+
184
+ email ENV['NETSUITE_EMAIL'] unless ENV['NETSUITE_EMAIL'].nil?
185
+ password ENV['NETSUITE_PASSWORD'] unless ENV['NETSUITE_PASSWORD'].nil?
186
+ account ENV['NETSUITE_ACCOUNT'] unless ENV['NETSUITE_ACCOUNT'].nil?
187
+ role ENV['NETSUITE_ROLE'] unless ENV['NETSUITE_ROLE'].nil?
188
+ api_version ENV['NETSUITE_API'] unless ENV['NETSUITE_API'].nil?
189
+ sandbox (ENV['NETSUITE_PRODUCTION'].nil? || ENV['NETSUITE_PRODUCTION'] != 'true')
190
+ wsdl ENV['NETSUITE_WSDL'] unless ENV['NETSUITE_WSDL'].nil?
191
+ silent (ENV['NETSUITE_SILENT'] || false)
192
+
193
+ read_timeout 100_000
194
+ end
195
+ end
196
+
179
197
  end
@@ -30,7 +30,7 @@ module NetSuite
30
30
  )
31
31
 
32
32
  NetSuite::Configuration
33
- .connection(soap_header: preferences)
33
+ .connection({ soap_header: preferences }, credentials)
34
34
  .call (@options.has_key?(:search_id)? :search_more_with_id : :search), :message => request_body
35
35
  end
36
36
 
@@ -11,9 +11,9 @@ module NetSuite
11
11
 
12
12
  fields :amount, :bin_numbers, :cost_estimate, :cost_estimate_type, :defer_rev_rec, :description, :gift_cert_from,
13
13
  :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email, :gift_cert_recipient_name, :gross_amt, :is_taxable,
14
- :line, :order_line, :quantity, :rate, :rev_rec_end_date, :rev_rec_start_date, :rev_rec_term_in_months, :serial_numbers,
15
- :shipping_cost, :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered,
16
- :vsoe_permit_discount, :vsoe_price, :is_closed
14
+ :line, :order_line, :po_currency, :quantity, :rate, :rev_rec_end_date, :rev_rec_start_date, :rev_rec_term_in_months,
15
+ :serial_numbers, :shipping_cost, :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral,
16
+ :vsoe_delivered, :vsoe_permit_discount, :vsoe_price, :is_closed
17
17
 
18
18
  field :custom_field_list, CustomFieldList
19
19
 
@@ -0,0 +1,42 @@
1
+ module NetSuite
2
+ module Records
3
+ class Vendor
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Support::Actions
8
+ include Namespaces::ListRel
9
+
10
+ actions :get, :get_list, :add, :update, :delete, :search
11
+
12
+ fields :account_number, :alt_email, :alt_name, :alt_phone, :balance,
13
+ :balance_primary, :bcn, :bill_pay, :comments, :company_name, :credit_limit,
14
+ :currency_list, :date_created, :default_address, :eligible_for_commission,
15
+ :email, :email_preference, :email_transactions, :entity_id, :fax, :fax_transactions,
16
+ :first_name, :give_access, :global_subscription_status, :home_phone, :is1099_eligible,
17
+ :is_accountant, :is_inactive, :is_job_resource_vend, :is_person, :labor_cost,
18
+ :last_modified_date, :last_name, :legal_name, :middle_name, :mobile_phone, :opening_balance,
19
+ :opening_balance_date, :password, :password2, :phone, :phonetic_name, :pricing_schedule_list,
20
+ :print_on_check_as, :print_transactions, :require_pwd_change, :roles_list, :salutation,
21
+ :send_email, :subscriptions_list, :tax_id_num, :title, :unbilled_orders, :unbilled_orders_primary,
22
+ :url, :vat_reg_number
23
+
24
+ field :custom_field_list, CustomFieldList
25
+ # TODO should change name to VendorAddressBookList
26
+ field :addressbook_list, CustomerAddressbookList
27
+
28
+ record_refs :custom_form, :category, :image, :subsidiary, :representing_subsidiary,
29
+ :expense_account, :payables_account, :terms, :opening_balance_account, :currency, :work_calendar,
30
+ :tax_item
31
+
32
+ attr_reader :internal_id
33
+ attr_accessor :external_id
34
+
35
+ def initialize(attributes = {})
36
+ @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
37
+ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id)
38
+ initialize_from_attributes_hash(attributes)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -7,10 +7,11 @@ describe NetSuite::Actions::Search do
7
7
  it "handles custom auth credentials" do
8
8
  allow(NetSuite::Configuration).to receive(:connection).and_return(double().as_null_object)
9
9
 
10
- NetSuite::Records::Customer.search({}, {
10
+ credentials = {
11
11
  email: 'fake@domain.com',
12
12
  password: 'fake'
13
- })
13
+ }
14
+ NetSuite::Records::Customer.search({}, credentials)
14
15
 
15
16
  expect(NetSuite::Configuration).to have_received(:connection).with({:soap_header=>{
16
17
  "platformMsgs:passport"=>{
@@ -18,7 +19,7 @@ describe NetSuite::Actions::Search do
18
19
  "platformCore:password"=>"fake",
19
20
  "platformCore:account"=>"1234",
20
21
  "platformCore:role"=>{:@internalId=>"3"}
21
- }, "platformMsgs:SearchPreferences"=>{}}}
22
+ }, "platformMsgs:SearchPreferences"=>{}}}, credentials
22
23
  )
23
24
  end
24
25
 
@@ -7,9 +7,9 @@ describe NetSuite::Records::SalesOrderItem do
7
7
  [
8
8
  :amount, :bin_numbers, :cost_estimate, :cost_estimate_type, :defer_rev_rec, :description, :gift_cert_from,
9
9
  :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email, :gift_cert_recipient_name, :gross_amt, :is_taxable,
10
- :line, :order_line, :quantity, :rate, :rev_rec_end_date, :rev_rec_start_date, :rev_rec_term_in_months, :serial_numbers,
11
- :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount,
12
- :vsoe_price
10
+ :line, :order_line, :po_currency, :quantity, :rate, :rev_rec_end_date, :rev_rec_start_date, :rev_rec_term_in_months,
11
+ :serial_numbers, :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered,
12
+ :vsoe_permit_discount, :vsoe_price
13
13
  ].each do |field|
14
14
  expect(item).to have_field(field)
15
15
  end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Vendor do
4
+ let(:vendor) { NetSuite::Records::Vendor.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :account_number, :alt_email, :alt_name, :alt_phone, :balance,
9
+ :balance_primary, :bcn, :bill_pay, :comments, :company_name, :credit_limit,
10
+ :currency_list, :date_created, :default_address, :eligible_for_commission,
11
+ :email, :email_preference, :email_transactions, :entity_id, :fax, :fax_transactions,
12
+ :first_name, :give_access, :global_subscription_status, :home_phone, :is1099_eligible,
13
+ :is_accountant, :is_inactive, :is_job_resource_vend, :is_person, :labor_cost,
14
+ :last_modified_date, :last_name, :legal_name, :middle_name, :mobile_phone, :opening_balance,
15
+ :opening_balance_date, :password, :password2, :phone, :phonetic_name, :pricing_schedule_list,
16
+ :print_on_check_as, :print_transactions, :require_pwd_change, :roles_list, :salutation,
17
+ :send_email, :subscriptions_list, :tax_id_num, :title, :unbilled_orders, :unbilled_orders_primary,
18
+ :url, :vat_reg_number
19
+ ].each do |field|
20
+ vendor.should have_field(field)
21
+ end
22
+ end
23
+
24
+ it 'has the right record_refs' do
25
+ [
26
+ :custom_form, :category, :image, :subsidiary, :representing_subsidiary,
27
+ :expense_account, :payables_account, :terms, :opening_balance_account, :currency, :work_calendar,
28
+ :tax_item
29
+ ].each do |record_ref|
30
+ vendor.should have_record_ref(record_ref)
31
+ end
32
+ end
33
+
34
+ describe '#custom_field_list' do
35
+ it 'can be set from attributes' do
36
+ attributes = {
37
+ :custom_field => {
38
+ :value => 10,
39
+ :internal_id => 'custfield_something'
40
+ }
41
+ }
42
+ vendor.custom_field_list = attributes
43
+ vendor.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
44
+ vendor.custom_field_list.custom_fields.length.should eql(1)
45
+ end
46
+
47
+ it 'can be set from a CustomFieldList object' do
48
+ custom_field_list = NetSuite::Records::CustomFieldList.new
49
+ vendor.custom_field_list = custom_field_list
50
+ vendor.custom_field_list.should eql(custom_field_list)
51
+ end
52
+ end
53
+
54
+ describe '.get' do
55
+ context 'when the response is successful' do
56
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :is_person => true }) }
57
+
58
+ it 'returns a Vendor instance populated with the data from the response object' do
59
+ NetSuite::Actions::Get.should_receive(:call).with([NetSuite::Records::Vendor, { :external_id => 1 }], {}).and_return(response)
60
+ vendor = NetSuite::Records::Vendor.get(:external_id => 1)
61
+ vendor.should be_kind_of(NetSuite::Records::Vendor)
62
+ vendor.is_person.should be_truthy
63
+ end
64
+ end
65
+
66
+ context 'when the response is unsuccessful' do
67
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
68
+
69
+ it 'raises a RecordNotFound exception' do
70
+ NetSuite::Actions::Get.should_receive(:call).with([NetSuite::Records::Vendor, { :external_id => 1 }], {}).and_return(response)
71
+ lambda {
72
+ NetSuite::Records::Vendor.get(:external_id => 1)
73
+ }.should raise_error(NetSuite::RecordNotFound,
74
+ /NetSuite::Records::Vendor with OPTIONS=(.*) could not be found/)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#add' do
80
+ let(:vendor) { NetSuite::Records::Vendor.new(:entity_id => 'TEST VENDOR', :is_person => true) }
81
+
82
+ context 'when the response is successful' do
83
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
84
+
85
+ it 'returns true' do
86
+ NetSuite::Actions::Add.should_receive(:call).
87
+ with([vendor], {}).
88
+ and_return(response)
89
+ vendor.add.should be_truthy
90
+ end
91
+ end
92
+
93
+ context 'when the response is unsuccessful' do
94
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
95
+
96
+ it 'returns false' do
97
+ NetSuite::Actions::Add.should_receive(:call).
98
+ with([vendor], {}).
99
+ and_return(response)
100
+ vendor.add.should be_falsey
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#delete' do
106
+ context 'when the response is successful' do
107
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
108
+
109
+ it 'returns true' do
110
+ NetSuite::Actions::Delete.should_receive(:call).
111
+ with([vendor], {}).
112
+ and_return(response)
113
+ vendor.delete.should be_truthy
114
+ end
115
+ end
116
+
117
+ context 'when the response is unsuccessful' do
118
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
119
+
120
+ it 'returns false' do
121
+ NetSuite::Actions::Delete.should_receive(:call).
122
+ with([vendor], {}).
123
+ and_return(response)
124
+ vendor.delete.should be_falsey
125
+ end
126
+ end
127
+ end
128
+
129
+ describe '#to_record' do
130
+ let(:vendor) { NetSuite::Records::Vendor.new(:entity_id => 'TEST VENDOR', :is_person => true) }
131
+
132
+ it 'returns a hash of attributes that can be used in a SOAP request' do
133
+ vendor.to_record.should eql({
134
+ 'listRel:entityId' => 'TEST VENDOR',
135
+ 'listRel:isPerson' => true
136
+ })
137
+ end
138
+ end
139
+
140
+ describe '#record_type' do
141
+ it 'returns a string type for the record to be used in a SOAP request' do
142
+ vendor.record_type.should eql('listRel:Vendor')
143
+ end
144
+ end
145
+ end
@@ -4,6 +4,8 @@ require 'rspec'
4
4
  require 'netsuite'
5
5
  require 'pry'
6
6
 
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
7
9
  Dir['spec/support/**/*.rb'].each { |f| require f }
8
10
 
9
11
  RSpec.configure do |config|
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.3.2
4
+ version: 0.3.3
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: 2014-12-30 00:00:00.000000000 Z
13
+ date: 2015-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: savon
@@ -201,6 +201,7 @@ files:
201
201
  - lib/netsuite/records/units_type.rb
202
202
  - lib/netsuite/records/units_type_uom.rb
203
203
  - lib/netsuite/records/units_type_uom_list.rb
204
+ - lib/netsuite/records/vendor.rb
204
205
  - lib/netsuite/records/work_order.rb
205
206
  - lib/netsuite/records/work_order_item.rb
206
207
  - lib/netsuite/records/work_order_item_list.rb
@@ -299,6 +300,7 @@ files:
299
300
  - spec/netsuite/records/units_type_spec.rb
300
301
  - spec/netsuite/records/units_type_uom_list_spec.rb
301
302
  - spec/netsuite/records/units_type_uom_spec.rb
303
+ - spec/netsuite/records/vendor_spec.rb
302
304
  - spec/netsuite/records/work_order_item_list_spec.rb
303
305
  - spec/netsuite/records/work_order_item_spec.rb
304
306
  - spec/netsuite/records/work_order_spec.rb
@@ -446,6 +448,7 @@ test_files:
446
448
  - spec/netsuite/records/units_type_spec.rb
447
449
  - spec/netsuite/records/units_type_uom_list_spec.rb
448
450
  - spec/netsuite/records/units_type_uom_spec.rb
451
+ - spec/netsuite/records/vendor_spec.rb
449
452
  - spec/netsuite/records/work_order_item_list_spec.rb
450
453
  - spec/netsuite/records/work_order_item_spec.rb
451
454
  - spec/netsuite/records/work_order_spec.rb