netsuite 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,15 +29,15 @@ Or install it yourself as:
29
29
  * Retrieves the customer by internalId.
30
30
 
31
31
  ```Ruby
32
- customer = NetSuite::Customer.get(4) # => #<NetSuite::Customer:0x1042f59b8>
33
- customer.is_person # => true
32
+ customer = NetSuite::Records::Customer.get(4) # => #<NetSuite::Records::Customer:0x1042f59b8>
33
+ customer.is_person # => true
34
34
  ```
35
35
 
36
36
  <a name='extending'>
37
37
  ## Additions
38
38
 
39
39
  * Please submit a pull request for any models or actions that you would like to be included. The API is quite large and so we will necessarily not cover all of it.
40
- * Models should go into the `lib/netsuite/models/` directory.
40
+ * Records should go into the `lib/netsuite/records/` directory.
41
41
  * Actions should be placed in their respective subdirectory under `lib/netsuite/actions`.
42
42
  * Example:
43
43
 
@@ -4,7 +4,9 @@ require 'netsuite/configuration'
4
4
  require 'netsuite/errors'
5
5
  require 'netsuite/response'
6
6
  require 'netsuite/version'
7
+ require 'netsuite/attribute_support'
7
8
  require 'netsuite/field_support'
9
+ require 'netsuite/record_support'
8
10
  require 'netsuite/savon_support'
9
11
 
10
12
  # ACTIONS
@@ -12,11 +14,10 @@ require 'netsuite/actions/add'
12
14
  require 'netsuite/actions/get'
13
15
  require 'netsuite/actions/initialize'
14
16
 
15
- # ENTITIES
16
- require 'netsuite/entities/customer'
17
-
18
- # TRANSACTIONS
19
- require 'netsuite/transactions/invoice'
17
+ # RECORDS
18
+ require 'netsuite/records/customer'
19
+ require 'netsuite/records/customer_addressbook_list'
20
+ require 'netsuite/records/invoice'
20
21
 
21
22
  module NetSuite
22
23
 
@@ -3,8 +3,8 @@ module NetSuite
3
3
  class Add
4
4
  include SavonSupport
5
5
 
6
- def initialize(attributes = {})
7
- @attributes = attributes
6
+ def initialize(obj = nil)
7
+ @obj = obj
8
8
  end
9
9
 
10
10
  private
@@ -29,13 +29,10 @@ module NetSuite
29
29
  # </soap:Body>
30
30
  def request_body
31
31
  {
32
- 'platformMsgs:record' => {
33
- 'listRel:entityId' => @attributes[:entity_id],
34
- 'listRel:companyName' => @attributes[:company_name]
35
- },
32
+ 'platformMsgs:record' => @obj.to_record,
36
33
  :attributes! => {
37
34
  'platformMsgs:record' => {
38
- 'xsi:type' => 'listRel:Customer'
35
+ 'xsi:type' => @obj.record_type
39
36
  }
40
37
  }
41
38
  }
@@ -0,0 +1,16 @@
1
+ module NetSuite
2
+ module AttributeSupport
3
+
4
+ def attributes
5
+ @attributes ||= {}
6
+ end
7
+ private :attributes
8
+
9
+ def initialize_from_attributes_hash(attributes = {})
10
+ Hash[attributes.select { |k,v| self.class.fields.include?(k) }].each do |k,v|
11
+ send("#{k}=", v)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -45,7 +45,7 @@ module NetSuite
45
45
  self.email = email
46
46
  else
47
47
  attributes[:email] ||
48
- raise(NetSuite::ConfigurationError,
48
+ raise(ConfigurationError,
49
49
  '#email is a required configuration value. Please set it by calling NetSuite::Configuration.email = "me@example.com"')
50
50
  end
51
51
  end
@@ -59,7 +59,7 @@ module NetSuite
59
59
  self.password = password
60
60
  else
61
61
  attributes[:password] ||
62
- raise(NetSuite::ConfigurationError,
62
+ raise(ConfigurationError,
63
63
  '#password is a required configuration value. Please set it by calling NetSuite::Configuration.password = "my_pass"')
64
64
  end
65
65
  end
@@ -73,7 +73,7 @@ module NetSuite
73
73
  self.account = account
74
74
  else
75
75
  attributes[:account] ||
76
- raise(NetSuite::ConfigurationError,
76
+ raise(ConfigurationError,
77
77
  '#account is a required configuration value. Please set it by calling NetSuite::Configuration.account = 1234')
78
78
  end
79
79
  end
@@ -1,34 +1,16 @@
1
1
  module NetSuite
2
2
  module FieldSupport
3
+ include AttributeSupport
3
4
 
4
5
  def self.included(base)
5
6
  base.send(:extend, ClassMethods)
6
7
  end
7
8
 
8
- def initialize(attributes = {})
9
- attributes = attributes.inject({}) do |hash, (k,v)|
10
- if k.to_s.match(/@.+/)
11
- hash.store(k.to_s.delete('@').to_sym, attributes[k])
12
- else
13
- hash.store(k,v)
14
- end
15
- hash
16
- end
17
- Hash[attributes.select { |k,v| self.class.fields.include?(k) }].each do |k,v|
18
- send("#{k}=", v)
19
- end
20
- end
21
-
22
- def attributes
23
- @attributes ||= {}
24
- end
25
- private :attributes
26
-
27
9
  module ClassMethods
28
10
 
29
11
  def fields(*args)
30
12
  if args.empty?
31
- @fields
13
+ @fields ||= {}
32
14
  else
33
15
  args.each do |arg|
34
16
  field arg
@@ -0,0 +1,17 @@
1
+ module NetSuite
2
+ module RecordSupport
3
+ include AttributeSupport
4
+
5
+ def to_record
6
+ attributes.inject({}) do |hash, (k,v)|
7
+ hash.store("listRel:#{k.to_s.lower_camelcase}", v)
8
+ hash
9
+ end
10
+ end
11
+
12
+ def record_type
13
+ "listRel:#{self.class.to_s.split('::').last}"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ module NetSuite
2
+ module Records
3
+ class Customer
4
+ include FieldSupport
5
+ include RecordSupport
6
+
7
+ fields :access_role, :account_number, :addressbook_list, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
8
+ :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
9
+ :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
10
+ :consol_unbilled_orders, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
11
+ :currency, :currency_list, :custom_field_list, :custom_form, :date_created, :days_overdue, :default_address,
12
+ :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id, :entity_status,
13
+ :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
14
+ :group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
15
+ :language, :last_modified, :last_name, :last_page_visited, :last_visit, :lead_source, :middle_name, :mobile_phone,
16
+ :opening_balance, :opening_balance_account, :opening_balance_date, :overdue_balance, :parent, :partner, :partners_list,
17
+ :password, :password_2, :phone, :phonetic_name, :pref_cc_processor, :price_level, :print_on_check_as,
18
+ :print_transactions, :referrer, :reminder_days, :representing_subsidiary, :require_pwd_change, :resale_number,
19
+ :sales_group, :sales_readiness, :sales_rep, :sales_team_list, :salutation, :send_email, :ship_complete, :shipping_item,
20
+ :stage, :start_date, :subscriptions_list, :subsidiary, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, :terms,
21
+ :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :unbilled_orders, :url,
22
+ :vat_reg_number, :visits, :web_lead
23
+
24
+ attr_reader :internal_id, :external_id
25
+
26
+ def initialize(attributes = {})
27
+ @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
28
+ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id)
29
+ initialize_from_attributes_hash(attributes)
30
+ end
31
+
32
+ def addressbook_list=(attributes_or_record)
33
+ attributes[:addressbook_list] = NetSuite::Records::CustomerAddressbookList.new(attributes_or_record)
34
+ end
35
+
36
+ def self.get(id)
37
+ response = Actions::Get.call(id)
38
+ if response.success?
39
+ new(response.body)
40
+ else
41
+ raise RecordNotFound, "#{self} with ID=#{id} could not be found"
42
+ end
43
+ end
44
+
45
+ def add
46
+ response = Actions::Add.call(self)
47
+ response.success?
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ module NetSuite
2
+ module Records
3
+ class CustomerAddressbookList
4
+ include FieldSupport
5
+ include RecordSupport
6
+
7
+ fields :default_shipping, :default_billing, :is_residential, :label, :attention, :addressee,
8
+ :phone, :addr1, :addr2, :addr3, :city, :zip, :country, :addr_text, :override, :state
9
+
10
+ attr_reader :internal_id
11
+
12
+ def initialize(attributes_or_record = {})
13
+ case attributes_or_record
14
+ when self.class
15
+ initialize_from_record(attributes_or_record)
16
+ when Hash
17
+ attributes_or_record = attributes_or_record[:addressbook] if attributes_or_record[:addressbook]
18
+ @internal_id = attributes_or_record.delete(:internal_id)
19
+ initialize_from_attributes_hash(attributes_or_record)
20
+ end
21
+ end
22
+
23
+ def initialize_from_record(obj)
24
+ self.default_shipping = obj.default_shipping
25
+ self.default_billing = obj.default_billing
26
+ self.is_residential = obj.is_residential
27
+ self.label = obj.label
28
+ self.attention = obj.attention
29
+ self.addressee = obj.addressee
30
+ self.phone = obj.phone
31
+ self.addr1 = obj.addr1
32
+ self.addr2 = obj.addr2
33
+ self.addr3 = obj.addr3
34
+ self.city = obj.city
35
+ self.zip = obj.zip
36
+ self.country = obj.country
37
+ self.addr_text = obj.addr_text
38
+ self.override = obj.override
39
+ self.state = obj.state
40
+ @internal_id = obj.internal_id
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ module NetSuite
2
+ module Records
3
+ class Invoice
4
+ include FieldSupport
5
+ include RecordSupport
6
+
7
+ fields :account, :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :balance, :bill_address,
8
+ :bill_address_list, :billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
9
+ :custom_form, :deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
10
+ :discount_total, :due_date, :email, :end_date, :entity, :est_gross_profit, :est_gross_profit_percent, :exchange_rate,
11
+ :exclude_commission, :exp_cost_disc_amount, :exp_cost_disc_print, :exp_cost_disc_rate, :exp_cost_disc_tax_1_amt,
12
+ :exp_cost_disc_taxable, :exp_cost_discount, :exp_cost_list, :exp_cost_tax_code, :exp_cost_tax_rate_1,
13
+ :exp_cost_tax_rate_2, :fax, :fob, :gift_cert_applied, :gift_cert_redemption_list, :handling_cost, :handling_tax_1_rate,
14
+ :handling_tax_2_rate, :handling_tax_code, :is_taxable, :item_cost_disc_amount, :item_cost_disc_print,
15
+ :item_cost_disc_rate, :item_cost_disc_tax_1_amt, :item_cost_disc_taxable, :item_cost_discount, :item_cost_list,
16
+ :item_cost_tax_code, :item_cost_tax_rate_1, :item_cost_tax_rate_2, :item_list, :job, :klass, :last_modified_date,
17
+ :lead_source, :linked_tracking_numbers, :location, :memo, :message, :message_sel, :on_credit_hold, :opportunity,
18
+ :other_ref_name, :partner, :partners_list, :posting_period, :promo_code, :recognized_revenue, :rev_rec_end_date,
19
+ :rev_rec_on_rev_commitment, :rev_rec_schedule, :rev_rec_start_date, :revenue_status, :sales_effective_date,
20
+ :sales_group, :sales_rep, :sales_team_list, :ship_address, :ship_address_list, :ship_date, :ship_group_list,
21
+ :ship_method, :shipping_cost, :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :source, :start_date,
22
+ :status, :sub_total, :subsidiary, :sync_partner_teams, :sync_sales_teams, :tax_2_total, :tax_item, :tax_rate,
23
+ :tax_total, :terms, :time_disc_amount, :time_disc_print, :time_disc_rate, :time_disc_tax_1_amt, :time_disc_taxable,
24
+ :time_discount, :time_list, :time_tax_code, :time_tax_rate_1, :time_tax_rate_2, :to_be_emailed, :to_be_faxed,
25
+ :to_be_printed, :total, :total_cost_estimate, :tracking_numbers, :tran_date, :tran_id, :tran_is_vsoe_bundle,
26
+ :transaction_bill_address, :transaction_ship_address, :vat_reg_num, :vsoe_auto_calc
27
+
28
+ def initialize(attributes = {})
29
+ @internal_id = attributes.delete(:internal_id)
30
+ @external_id = attributes.delete(:external_id)
31
+ initialize_from_attributes_hash(attributes)
32
+ end
33
+
34
+ def self.initialize(customer)
35
+ response = Actions::Initialize.call(customer)
36
+ if response.success?
37
+ new(response.body)
38
+ else
39
+ raise RecordNotFound, "#{self} with ID=#{id} could not be found"
40
+ end
41
+ end
42
+
43
+ def add
44
+ response = Actions::Add.call(self)
45
+ response.success?
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -26,15 +26,15 @@ module NetSuite
26
26
  end
27
27
 
28
28
  def connection
29
- NetSuite::Configuration.connection
29
+ Configuration.connection
30
30
  end
31
31
 
32
32
  def auth_header
33
- NetSuite::Configuration.auth_header
33
+ Configuration.auth_header
34
34
  end
35
35
 
36
36
  def build_response
37
- NetSuite::Response.new(:success => success?, :body => response_body)
37
+ Response.new(:success => success?, :body => response_body)
38
38
  end
39
39
 
40
40
  def success?
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -3,11 +3,8 @@ require 'spec_helper'
3
3
  describe NetSuite::Actions::Add do
4
4
 
5
5
  context 'Customer' do
6
- let(:attributes) do
7
- {
8
- :entity_id => 'Shutter Fly',
9
- :company_name => 'Shutter Fly, Inc.'
10
- }
6
+ let(:customer) do
7
+ NetSuite::Records::Customer.new(:entity_id => 'Shutter Fly', :company_name => 'Shutter Fly, Inc.')
11
8
  end
12
9
 
13
10
  before do
@@ -25,11 +22,41 @@ describe NetSuite::Actions::Add do
25
22
  end
26
23
 
27
24
  it 'makes a valid request to the NetSuite API' do
28
- NetSuite::Actions::Add.call(attributes)
25
+ NetSuite::Actions::Add.call(customer)
29
26
  end
30
27
 
31
28
  it 'returns a valid Response object' do
32
- response = NetSuite::Actions::Add.call(attributes)
29
+ response = NetSuite::Actions::Add.call(customer)
30
+ response.should be_kind_of(NetSuite::Response)
31
+ response.should be_success
32
+ end
33
+ end
34
+
35
+ context 'Invoice' do
36
+ let(:invoice) do
37
+ NetSuite::Records::Invoice.new(:source => 'Google', :total => 100.0)
38
+ end
39
+
40
+ before do
41
+ savon.expects(:add).with({
42
+ 'platformMsgs:record' => {
43
+ 'listRel:source' => 'Google',
44
+ 'listRel:total' => 100.0
45
+ },
46
+ :attributes! => {
47
+ 'platformMsgs:baseRef' => {
48
+ 'xsi:type' => 'listRel:Invoice'
49
+ }
50
+ }
51
+ }).returns(:add_invoice)
52
+ end
53
+
54
+ it 'makes a valid request to the NetSuite API' do
55
+ NetSuite::Actions::Add.call(invoice)
56
+ end
57
+
58
+ it 'returns a valid Response object' do
59
+ response = NetSuite::Actions::Add.call(invoice)
33
60
  response.should be_kind_of(NetSuite::Response)
34
61
  response.should be_success
35
62
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NetSuite::Actions::Initialize do
4
- let(:customer) { NetSuite::Entities::Customer.new(:internal_id => 1) }
4
+ let(:customer) { NetSuite::Records::Customer.new(:internal_id => 1) }
5
5
 
6
6
  before do
7
7
  savon.expects(:initialize).with({
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::AttributeSupport do
4
+ pending
5
+ end
@@ -4,24 +4,6 @@ describe NetSuite::FieldSupport do
4
4
  let(:klass) { Class.new.send(:include, NetSuite::FieldSupport) }
5
5
  let(:instance) { klass.new }
6
6
 
7
- describe '#initialize' do
8
- before do
9
- klass.field(:banana)
10
- end
11
-
12
- it 'stores the passed in attributes into the attributes instance variable' do
13
- instance = klass.new(:banana => 'for a monkey')
14
- instance.send(:attributes).should eql(:banana => 'for a monkey')
15
- end
16
-
17
- it 'ignores passed in attributes that are not in the fields set' do
18
- instance = klass.new(:apple => 'for a horse', :banana => 'for a monkey')
19
- instance.send(:attributes).should eql(:banana => 'for a monkey')
20
- end
21
-
22
- it 'renames attributes with swirlies'
23
- end
24
-
25
7
  describe '.fields' do
26
8
  context 'with arguments' do
27
9
  it 'calls .field with each argument passed to it' do
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Foo
4
+ module Bar
5
+ class Baz
6
+ include NetSuite::RecordSupport
7
+
8
+ def attributes
9
+ { :source => 'Google', :total => 100.0 }
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ describe NetSuite::RecordSupport do
16
+ let(:instance) { Foo::Bar::Baz.new }
17
+
18
+ describe '#record_type' do
19
+ it 'returns a hash of attributes to be used in a SOAP request' do
20
+ instance.to_record.should eql({
21
+ 'listRel:source' => 'Google',
22
+ 'listRel:total' => 100.0
23
+ })
24
+ end
25
+ end
26
+
27
+ describe '#record_type' do
28
+ it 'returns a string of the record type to be used in a SOAP request' do
29
+ instance.record_type.should eql('listRel:Baz')
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::CustomerAddressbookList do
4
+ let(:attributes) do
5
+ {
6
+ :addressbook => {
7
+ :addr1 => '123 Happy Lane',
8
+ :addr_text => "123 Happy Lane\nLos Angeles CA 90007",
9
+ :city => 'Los Angeles',
10
+ :country => '_unitedStates',
11
+ :default_billing => true,
12
+ :default_shipping => true,
13
+ :internal_id => '567',
14
+ :is_residential => false,
15
+ :label => '123 Happy Lane',
16
+ :override => false,
17
+ :state => 'CA',
18
+ :zip => '90007'
19
+ }
20
+ }
21
+ end
22
+ let(:record) { NetSuite::Records::CustomerAddressbookList.new(attributes) }
23
+
24
+ it 'has all the right fields' do
25
+ [
26
+ :default_shipping, :default_billing, :is_residential, :label, :attention, :addressee,
27
+ :phone, :addr1, :addr2, :addr3, :city, :zip, :country, :addr_text, :override, :state
28
+ ].each do |field|
29
+ record.should have_field(field)
30
+ end
31
+ end
32
+
33
+ describe '#initialize' do
34
+ context 'when taking in a hash of attributes' do
35
+ it 'sets the attributes for the object given the attributes hash' do
36
+ record.addr1.should eql('123 Happy Lane')
37
+ record.addr_text.should eql("123 Happy Lane\nLos Angeles CA 90007")
38
+ record.city.should eql('Los Angeles')
39
+ record.country.should eql('_unitedStates')
40
+ record.default_billing.should be_true
41
+ record.default_shipping.should be_true
42
+ record.is_residential.should be_false
43
+ record.label.should eql('123 Happy Lane')
44
+ record.override.should be_false
45
+ record.state.should eql('CA')
46
+ record.zip.should eql('90007')
47
+ record.internal_id.should eql('567')
48
+ end
49
+ end
50
+
51
+ context 'when taking in a CustomerAddressbookList instance' do
52
+ it 'sets the attributes for the object given the record attributes' do
53
+ old_record = NetSuite::Records::CustomerAddressbookList.new(attributes)
54
+ record = NetSuite::Records::CustomerAddressbookList.new(old_record)
55
+ record.addr1.should eql('123 Happy Lane')
56
+ record.addr_text.should eql("123 Happy Lane\nLos Angeles CA 90007")
57
+ record.city.should eql('Los Angeles')
58
+ record.country.should eql('_unitedStates')
59
+ record.default_billing.should be_true
60
+ record.default_shipping.should be_true
61
+ record.is_residential.should be_false
62
+ record.label.should eql('123 Happy Lane')
63
+ record.override.should be_false
64
+ record.state.should eql('CA')
65
+ record.zip.should eql('90007')
66
+ record.internal_id.should eql('567')
67
+ end
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Customer do
4
+ let(:customer) { NetSuite::Records::Customer.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :access_role, :account_number, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
9
+ :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
10
+ :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
11
+ :consol_unbilled_orders, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
12
+ :currency, :currency_list, :custom_field_list, :custom_form, :date_created, :days_overdue, :default_address,
13
+ :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id, :entity_status,
14
+ :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
15
+ :group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
16
+ :language, :last_modified, :last_name, :last_page_visited, :last_visit, :lead_source, :middle_name, :mobile_phone,
17
+ :opening_balance, :opening_balance_account, :opening_balance_date, :overdue_balance, :parent, :partner, :partners_list,
18
+ :password, :password_2, :phone, :phonetic_name, :pref_cc_processor, :price_level, :print_on_check_as,
19
+ :print_transactions, :referrer, :reminder_days, :representing_subsidiary, :require_pwd_change, :resale_number,
20
+ :sales_group, :sales_readiness, :sales_rep, :sales_team_list, :salutation, :send_email, :ship_complete, :shipping_item,
21
+ :stage, :start_date, :subscriptions_list, :subsidiary, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, :terms,
22
+ :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :unbilled_orders, :url,
23
+ :vat_reg_number, :visits, :web_lead
24
+ ].each do |field|
25
+ customer.should have_field(field)
26
+ end
27
+ end
28
+
29
+ it 'has an addressbook_list field that builds a CustomerAddressbookList object' do
30
+ customer.addressbook_list = {
31
+ :addressbook => {
32
+ :addr1 => '123 Happy Lane',
33
+ :addr_text => "123 Happy Lane\nLos Angeles CA 90007",
34
+ :city => 'Los Angeles',
35
+ :country => '_unitedStates',
36
+ :default_billing => true,
37
+ :default_shipping => true,
38
+ :internal_id => '567',
39
+ :is_residential => false,
40
+ :label => '123 Happy Lane',
41
+ :override => false,
42
+ :state => 'CA',
43
+ :zip => '90007'
44
+ }
45
+ }
46
+ customer.addressbook_list.should be_kind_of(NetSuite::Records::CustomerAddressbookList)
47
+ end
48
+
49
+ describe '.get' do
50
+ context 'when the response is successful' do
51
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :is_person => true }) }
52
+
53
+ it 'returns a Customer instance populated with the data from the response object' do
54
+ NetSuite::Actions::Get.should_receive(:call).with(1).and_return(response)
55
+ customer = NetSuite::Records::Customer.get(1)
56
+ customer.should be_kind_of(NetSuite::Records::Customer)
57
+ customer.is_person.should be_true
58
+ end
59
+ end
60
+
61
+ context 'when the response is unsuccessful' do
62
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
63
+
64
+ it 'returns a Customer instance populated with the data from the response object' do
65
+ NetSuite::Actions::Get.should_receive(:call).with(1).and_return(response)
66
+ lambda {
67
+ NetSuite::Records::Customer.get(1)
68
+ }.should raise_error(NetSuite::RecordNotFound, 'NetSuite::Records::Customer with ID=1 could not be found')
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#add' do
74
+ let(:customer) { NetSuite::Records::Customer.new(:entity_id => 'TEST CUSTOMER', :is_person => true) }
75
+
76
+ context 'when the response is successful' do
77
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
78
+
79
+ it 'returns true' do
80
+ NetSuite::Actions::Add.should_receive(:call).
81
+ with(customer).
82
+ and_return(response)
83
+ customer.add.should be_true
84
+ end
85
+ end
86
+
87
+ context 'when the response is unsuccessful' do
88
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
89
+
90
+ it 'returns false' do
91
+ NetSuite::Actions::Add.should_receive(:call).
92
+ with(customer).
93
+ and_return(response)
94
+ customer.add.should be_false
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '#to_record' do
100
+ let(:customer) { NetSuite::Records::Customer.new(:entity_id => 'TEST CUSTOMER', :is_person => true) }
101
+
102
+ it 'returns a hash of attributes that can be used in a SOAP request' do
103
+ customer.to_record.should eql({
104
+ 'listRel:entityId' => 'TEST CUSTOMER',
105
+ 'listRel:isPerson' => true
106
+ })
107
+ end
108
+ end
109
+
110
+ describe '#record_type' do
111
+ it 'returns a string type for the record to be used in a SOAP request' do
112
+ customer.record_type.should eql('listRel:Customer')
113
+ end
114
+ end
115
+
116
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Invoice do
4
+ let(:invoice) { NetSuite::Records::Invoice.new }
5
+ let(:customer) { NetSuite::Records::Customer.new }
6
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
7
+
8
+ it 'has all the right fields' do
9
+ [
10
+ :created_date, :last_modified_date, :custom_form, :entity, :tran_date, :tran_id, :source, :created_from, :posting_period,
11
+ :opportunity, :department, :klass, :terms, :location, :subsidiary, :due_date, :discount_date, :discount_amount, :sales_rep,
12
+ :contrib_pct, :partner, :lead_source, :start_date, :end_date, :other_ref_name, :memo, :sales_effective_date,
13
+ :exclude_commission, :total_cost_estimate, :est_gross_profit, :est_gross_profit_percent, :rev_rec_schedule,
14
+ :rev_rec_start_date, :rev_rec_end_date, :amount_paid, :amount_remaining, :balance, :account, :on_credit_hold,
15
+ :exchange_rate, :currency_name, :promo_code, :discount_item, :discount_rate, :is_taxable, :tax_item, :tax_rate,
16
+ :to_be_printed, :to_be_emailed, :to_be_faxed, :fax, :message_sel, :message, :transaction_bill_address, :bill_address_list,
17
+ :bill_address, :transaction_ship_address, :ship_address_list, :ship_address, :fob, :ship_date, :ship_method, :shipping_cost,
18
+ :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :handling_tax_code, :handling_tax_1_rate, :handling_cost,
19
+ :handling_tax_2_rate, :tracking_numbers, :linked_tracking_numbers, :sales_group, :sub_total, :revenue_status,
20
+ :recognized_revenue, :deferred_revenue, :rev_rec_on_rev_commitment, :sync_sales_teams, :discount_total, :tax_total,
21
+ :alt_shipping_cost, :alt_handling_cost, :total, :status, :job, :billing_schedule, :email, :tax_2_total, :vat_reg_num,
22
+ :exp_cost_discount, :item_cost_discount, :time_discount, :exp_cost_disc_rate, :item_cost_disc_rate, :time_disc_rate,
23
+ :exp_cost_disc_amount, :exp_cost_tax_rate_1, :exp_cost_tax_rate_2, :item_cost_disc_amount, :exp_cost_tax_code,
24
+ :exp_cost_disc_tax_1_amt, :item_cost_tax_rate_1, :time_disc_amount, :item_cost_tax_code, :exp_cost_disc_taxable,
25
+ :item_cost_disc_taxable, :item_cost_tax_rate_2, :item_cost_disc_tax_1_amt, :item_cost_disc_print, :time_disc_taxable,
26
+ :time_tax_rate_1, :exp_cost_disc_print, :time_tax_code, :time_disc_print, :gift_cert_applied, :time_disc_tax_1_amt,
27
+ :tran_is_vsoe_bundle, :time_tax_rate_2, :vsoe_auto_calc, :sync_partner_teams, :sales_team_list, :partners_list, :item_list,
28
+ :item_cost_list, :gift_cert_redemption_list, :exp_cost_list, :time_list, :ship_group_list, :custom_field_list
29
+ ].each do |field|
30
+ invoice.should have_field(field)
31
+ end
32
+ end
33
+
34
+ it 'handles the "klass" field correctly'
35
+ # This field maps to 'class' but cannot be set as such in Ruby as it will cause runtime errors.
36
+
37
+ describe '.initialize' do
38
+ context 'when the request is successful' do
39
+ it 'returns an initialized invoice from the customer entity' do
40
+ NetSuite::Actions::Initialize.should_receive(:call).with(customer).and_return(response)
41
+ invoice = NetSuite::Records::Invoice.initialize(customer)
42
+ invoice.should be_kind_of(NetSuite::Records::Invoice)
43
+ end
44
+ end
45
+
46
+ context 'when the response is unsuccessful' do
47
+ pending
48
+ end
49
+ end
50
+
51
+ describe '#add' do
52
+ let(:test_data) { { :email => 'test@example.com', :fax => '1234567890' } }
53
+
54
+ context 'when the response is successful' do
55
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
56
+
57
+ it 'returns true' do
58
+ invoice = NetSuite::Records::Invoice.new(test_data)
59
+ NetSuite::Actions::Add.should_receive(:call).
60
+ with(invoice).
61
+ and_return(response)
62
+ invoice.add.should be_true
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 'returns false' do
70
+ invoice = NetSuite::Records::Invoice.new(test_data)
71
+ NetSuite::Actions::Add.should_receive(:call).
72
+ with(invoice).
73
+ and_return(response)
74
+ invoice.add.should be_false
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Header>
4
+ <platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2011_2.platform.webservices.netsuite.com">
5
+ <platformMsgs:nsId>WEBSERVICES_3392464_1220201115821392011296470399_67055c545d0</platformMsgs:nsId>
6
+ </platformMsgs:documentInfo>
7
+ </soapenv:Header>
8
+ <soapenv:Body>
9
+ <addResponse xmlns="urn:messages_2_5.platform.webservices.netsuite.com">
10
+ <writeResponse xmlns="urn:messages_2_5.platform.webservices.netsuite.com">
11
+ <ns1:status isSuccess="true" xmlns:ns1="urn:core_2_5.platform.webservices.netsuite.com"/>
12
+ <baseRef internalId="999" type="invoice" xsi:type="ns2:RecordRef" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:core_2_5.platform.webservices.netsuite.com"/>
13
+ </writeResponse>
14
+ </addResponse>
15
+ </soapenv:Body>
16
+ </soapenv:Envelope>
@@ -11,10 +11,10 @@
11
11
  <platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com"/>
12
12
  <record xsi:type="tranSales:Invoice" xmlns:tranSales="urn:sales_2011_2.transactions.webservices.netsuite.com">
13
13
  <tranSales:customForm internalId="101" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com">
14
- <platformCore:name>RP Test Product Invoice</platformCore:name>
14
+ <platformCore:name>Test Product Invoice</platformCore:name>
15
15
  </tranSales:customForm>
16
16
  <tranSales:entity internalId="988" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com">
17
- <platformCore:name>100157 200 Black Men of Chicago</platformCore:name>
17
+ <platformCore:name>100157 Shutter Fly</platformCore:name>
18
18
  </tranSales:entity>
19
19
  <tranSales:tranDate>2012-01-02T00:00:00.000-08:00</tranSales:tranDate>
20
20
  <tranSales:tranId>2582003</tranSales:tranId>
@@ -27,28 +27,28 @@
27
27
  <platformCore:name>1100 Accounts Receivable</platformCore:name>
28
28
  </tranSales:account>
29
29
  <tranSales:transactionBillAddress xmlns:platformCommon="urn:common_2011_2.platform.webservices.netsuite.com">
30
- <platformCommon:billAddr1>3473 S Martin Luther King Dr, Ste 206</platformCommon:billAddr1>
31
- <platformCommon:billCity>Chicago</platformCommon:billCity>
32
- <platformCommon:billState>IL</platformCommon:billState>
33
- <platformCommon:billZip>60616</platformCommon:billZip>
30
+ <platformCommon:billAddr1>123 Happy Lane</platformCommon:billAddr1>
31
+ <platformCommon:billCity>Los Angeles</platformCommon:billCity>
32
+ <platformCommon:billState>CA</platformCommon:billState>
33
+ <platformCommon:billZip>90007</platformCommon:billZip>
34
34
  <platformCommon:billCountry>_unitedStates</platformCommon:billCountry>
35
35
  </tranSales:transactionBillAddress>
36
36
  <tranSales:billAddressList internalId="567" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com">
37
- <platformCore:name>3473 S Martin Luther King Dr, Ste 206</platformCore:name>
37
+ <platformCore:name>123 Happy Lane</platformCore:name>
38
38
  </tranSales:billAddressList>
39
- <tranSales:billAddress>3473 S Martin Luther King Dr, Ste 206 Chicago IL 60616</tranSales:billAddress>
39
+ <tranSales:billAddress>123 Happy Lane, Los Angeles, CA 90007</tranSales:billAddress>
40
40
  <tranSales:transactionShipAddress xmlns:platformCommon="urn:common_2011_2.platform.webservices.netsuite.com">
41
- <platformCommon:shipAddr1>3473 S Martin Luther King Dr, Ste 206</platformCommon:shipAddr1>
42
- <platformCommon:shipCity>Chicago</platformCommon:shipCity>
43
- <platformCommon:shipState>IL</platformCommon:shipState>
44
- <platformCommon:shipZip>60616</platformCommon:shipZip>
41
+ <platformCommon:shipAddr1>123 Happy Lane</platformCommon:shipAddr1>
42
+ <platformCommon:shipCity>Los Angeles</platformCommon:shipCity>
43
+ <platformCommon:shipState>CA</platformCommon:shipState>
44
+ <platformCommon:shipZip>90007</platformCommon:shipZip>
45
45
  <platformCommon:shipCountry>_unitedStates</platformCommon:shipCountry>
46
46
  <platformCommon:shipIsResidential>false</platformCommon:shipIsResidential>
47
47
  </tranSales:transactionShipAddress>
48
48
  <tranSales:shipAddressList internalId="567" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com">
49
- <platformCore:name>3473 S Martin Luther King Dr, Ste 206</platformCore:name>
49
+ <platformCore:name>123 Happy Lane</platformCore:name>
50
50
  </tranSales:shipAddressList>
51
- <tranSales:shipAddress>3473 S Martin Luther King Dr, Ste 206 Chicago IL 60616</tranSales:shipAddress>
51
+ <tranSales:shipAddress>123 Happy Lane, Los Angeles, CA 90007</tranSales:shipAddress>
52
52
  <tranSales:shipDate>2012-01-02T00:00:00.000-08:00</tranSales:shipDate>
53
53
  <tranSales:subTotal>0.0</tranSales:subTotal>
54
54
  <tranSales:syncSalesTeams>false</tranSales:syncSalesTeams>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-02 00:00:00 -08:00
19
- default_executable:
18
+ date: 2012-01-04 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: savon
@@ -104,34 +103,40 @@ files:
104
103
  - lib/netsuite/actions/add.rb
105
104
  - lib/netsuite/actions/get.rb
106
105
  - lib/netsuite/actions/initialize.rb
106
+ - lib/netsuite/attribute_support.rb
107
107
  - lib/netsuite/configuration.rb
108
- - lib/netsuite/entities/customer.rb
109
108
  - lib/netsuite/errors.rb
110
109
  - lib/netsuite/field_support.rb
110
+ - lib/netsuite/record_support.rb
111
+ - lib/netsuite/records/customer.rb
112
+ - lib/netsuite/records/customer_addressbook_list.rb
113
+ - lib/netsuite/records/invoice.rb
111
114
  - lib/netsuite/response.rb
112
115
  - lib/netsuite/savon_support.rb
113
- - lib/netsuite/transactions/invoice.rb
114
116
  - lib/netsuite/version.rb
115
117
  - netsuite.gemspec
116
118
  - spec/netsuite/actions/add_spec.rb
117
119
  - spec/netsuite/actions/get_spec.rb
118
120
  - spec/netsuite/actions/initialize_spec.rb
121
+ - spec/netsuite/attribute_support_spec.rb
119
122
  - spec/netsuite/configuration_spec.rb
120
- - spec/netsuite/entities/customer_spec.rb
121
123
  - spec/netsuite/field_support_spec.rb
124
+ - spec/netsuite/record_support_spec.rb
125
+ - spec/netsuite/records/customer_addressbook_list_spec.rb
126
+ - spec/netsuite/records/customer_spec.rb
127
+ - spec/netsuite/records/invoice_spec.rb
122
128
  - spec/netsuite/response_spec.rb
123
129
  - spec/netsuite/savon_support_spec.rb
124
- - spec/netsuite/transactions/invoice_spec.rb
125
130
  - spec/netsuite_spec.rb
126
131
  - spec/spec_helper.rb
127
132
  - spec/support/configuration.rb
128
133
  - spec/support/field_matcher.rb
129
134
  - spec/support/fixtures/add/add_customer.xml
135
+ - spec/support/fixtures/add/add_invoice.xml
130
136
  - spec/support/fixtures/get/get_customer.xml
131
137
  - spec/support/fixtures/initialize/initialize_invoice_from_customer.xml
132
138
  - spec/support/savon.rb
133
139
  - wsdl/2011_02.wsdl
134
- has_rdoc: true
135
140
  homepage: https://github.com/RevolutionPrep/netsuite
136
141
  licenses: []
137
142
 
@@ -161,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
166
  requirements: []
162
167
 
163
168
  rubyforge_project:
164
- rubygems_version: 1.4.2
169
+ rubygems_version: 1.8.13
165
170
  signing_key:
166
171
  specification_version: 3
167
172
  summary: NetSuite SuiteTalk API Wrapper
@@ -169,17 +174,21 @@ test_files:
169
174
  - spec/netsuite/actions/add_spec.rb
170
175
  - spec/netsuite/actions/get_spec.rb
171
176
  - spec/netsuite/actions/initialize_spec.rb
177
+ - spec/netsuite/attribute_support_spec.rb
172
178
  - spec/netsuite/configuration_spec.rb
173
- - spec/netsuite/entities/customer_spec.rb
174
179
  - spec/netsuite/field_support_spec.rb
180
+ - spec/netsuite/record_support_spec.rb
181
+ - spec/netsuite/records/customer_addressbook_list_spec.rb
182
+ - spec/netsuite/records/customer_spec.rb
183
+ - spec/netsuite/records/invoice_spec.rb
175
184
  - spec/netsuite/response_spec.rb
176
185
  - spec/netsuite/savon_support_spec.rb
177
- - spec/netsuite/transactions/invoice_spec.rb
178
186
  - spec/netsuite_spec.rb
179
187
  - spec/spec_helper.rb
180
188
  - spec/support/configuration.rb
181
189
  - spec/support/field_matcher.rb
182
190
  - spec/support/fixtures/add/add_customer.xml
191
+ - spec/support/fixtures/add/add_invoice.xml
183
192
  - spec/support/fixtures/get/get_customer.xml
184
193
  - spec/support/fixtures/initialize/initialize_invoice_from_customer.xml
185
194
  - spec/support/savon.rb
@@ -1,41 +0,0 @@
1
- module NetSuite
2
- module Entities
3
- class Customer
4
- include FieldSupport
5
-
6
- fields :internal_id, :external_id, :custom_form, :entity_id, :alt_name, :is_person, :phonetic_name,
7
- :salutation, :first_name, :middle_name, :last_name, :company_name, :entity_status, :parent, :phone,
8
- :fax, :email, :url, :default_address, :is_inactive, :category, :title, :print_on_check_as, :alt_phone,
9
- :home_phone, :mobile_phone, :alt_email, :language, :comments, :date_created, :image, :email_preference,
10
- :subsidiary, :representing_subsidiary, :sales_rep, :territory, :contrib_pct, :partner, :sales_group,
11
- :vat_reg_number, :account_number, :tax_exempt, :terms, :credit_limit, :credit_hold_override, :balance,
12
- :overdue_balance, :days_overdue, :unbilled_orders, :consol_unbilled_orders, :consol_overdue_balance,
13
- :consol_deposit_balance, :consol_balance, :consol_aging, :consol_days_overdue, :price_level, :currency,
14
- :pref_cc_processor, :deposit_balance, :ship_complete, :taxable, :tax_item, :resale_number, :aging,
15
- :start_date, :end_date, :reminder_days, :shipping_item, :third_party_acct, :third_party_zipcode,
16
- :third_party_country, :give_access, :estimated_budget, :access_role, :send_email, :password, :password_2,
17
- :require_pwd_change, :campaign_category, :lead_source, :web_lead, :referrer, :keywords, :click_stream,
18
- :last_page_visited, :visits, :first_visit, :last_visit, :bill_pay, :opening_balance, :last_modified,
19
- :opening_balance_date, :opening_balance_account, :stage, :email_transactions, :print_transactions,
20
- :fax_transactions, :sync_partner_teams, :is_budget_approved, :global_subscription_status, :sales_readiness,
21
- :sales_team_list, :buying_reason, :download_list, :buying_time_frame, :addressbook_list, :subscriptions_list,
22
- :contact_roles_list, :currency_list, :credit_cards_list, :partners_list, :group_pricing_list,
23
- :item_pricing_list, :custom_field_list
24
-
25
- def self.get(id)
26
- response = NetSuite::Actions::Get.call(id)
27
- if response.success?
28
- new(response.body)
29
- else
30
- raise RecordNotFound, "#{self} with ID=#{id} could not be found"
31
- end
32
- end
33
-
34
- def add
35
- response = NetSuite::Actions::Add.call(@attributes)
36
- response.success?
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,38 +0,0 @@
1
- module NetSuite
2
- module Transactions
3
- class Invoice
4
- include FieldSupport
5
-
6
- fields :internal_id, :external_id, :created_date, :last_modified_date, :custom_form, :entity, :tran_date, :tran_id,
7
- :source, :created_from, :posting_period, :opportunity, :department, :klass, :terms, :location, :subsidiary, :due_date,
8
- :discount_date, :discount_amount, :sales_rep, :contrib_pct, :partner, :lead_source, :start_date, :end_date,
9
- :other_ref_name, :memo, :sales_effective_date, :exclude_commission, :total_cost_estimate, :est_gross_profit,
10
- :est_gross_profit_percent, :rev_rec_schedule, :rev_rec_start_date, :rev_rec_end_date, :amount_paid, :amount_remaining,
11
- :balance, :account, :on_credit_hold, :exchange_rate, :currency_name, :promo_code, :discount_item, :discount_rate,
12
- :is_taxable, :tax_item, :tax_rate, :to_be_printed, :to_be_emailed, :to_be_faxed, :fax, :message_sel, :message,
13
- :transaction_bill_address, :bill_address_list, :bill_address, :transaction_ship_address, :ship_address_list,
14
- :ship_address, :fob, :ship_date, :ship_method, :shipping_cost, :shipping_tax_1_rate, :shipping_tax_2_rate,
15
- :shipping_tax_code, :handling_tax_code, :handling_tax_1_rate, :handling_cost, :handling_tax_2_rate, :tracking_numbers,
16
- :linked_tracking_numbers, :sales_group, :sub_total, :revenue_status, :recognized_revenue, :deferred_revenue,
17
- :rev_rec_on_rev_commitment, :sync_sales_teams, :discount_total, :tax_total, :alt_shipping_cost, :alt_handling_cost,
18
- :total, :status, :job, :billing_schedule, :email, :tax_2_total, :vat_reg_num, :exp_cost_discount, :item_cost_discount,
19
- :time_discount, :exp_cost_disc_rate, :item_cost_disc_rate, :time_disc_rate, :exp_cost_disc_amount, :exp_cost_tax_rate_1,
20
- :exp_cost_tax_rate_2, :item_cost_disc_amount, :exp_cost_tax_code, :exp_cost_disc_tax_1_amt, :item_cost_tax_rate_1,
21
- :time_disc_amount, :item_cost_tax_code, :exp_cost_disc_taxable, :item_cost_disc_taxable, :item_cost_tax_rate_2,
22
- :item_cost_disc_tax_1_amt, :item_cost_disc_print, :time_disc_taxable, :time_tax_rate_1, :exp_cost_disc_print,
23
- :time_tax_code, :time_disc_print, :gift_cert_applied, :time_disc_tax_1_amt, :tran_is_vsoe_bundle, :time_tax_rate_2,
24
- :vsoe_auto_calc, :sync_partner_teams, :sales_team_list, :partners_list, :item_list, :item_cost_list,
25
- :gift_cert_redemption_list, :exp_cost_list, :time_list, :ship_group_list, :custom_field_list
26
-
27
- def self.initialize(customer)
28
- response = NetSuite::Actions::Initialize.call(customer)
29
- if response.success?
30
- new(response.body)
31
- else
32
- raise RecordNotFound, "#{self} with ID=#{id} could not be found"
33
- end
34
- end
35
-
36
- end
37
- end
38
- end
@@ -1,83 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe NetSuite::Entities::Customer do
4
- let(:customer) { NetSuite::Entities::Customer.new }
5
-
6
- it 'has all the right fields' do
7
- [
8
- :internal_id, :external_id, :custom_form, :entity_id, :alt_name, :is_person, :phonetic_name,
9
- :salutation, :first_name, :middle_name, :last_name, :company_name, :entity_status, :parent,
10
- :phone, :fax, :email, :url, :default_address, :is_inactive, :category, :title, :print_on_check_as,
11
- :alt_phone, :home_phone, :mobile_phone, :alt_email, :language, :comments, :date_created, :image,
12
- :email_preference, :subsidiary, :representing_subsidiary, :sales_rep, :territory, :contrib_pct,
13
- :partner, :sales_group, :vat_reg_number, :account_number, :tax_exempt, :terms, :credit_limit,
14
- :credit_hold_override, :balance, :overdue_balance, :days_overdue, :unbilled_orders,
15
- :consol_unbilled_orders, :consol_overdue_balance, :consol_deposit_balance, :consol_balance,
16
- :consol_aging, :consol_days_overdue, :price_level, :currency, :pref_cc_processor, :deposit_balance,
17
- :ship_complete, :taxable, :tax_item, :resale_number, :aging, :start_date, :end_date, :reminder_days,
18
- :shipping_item, :third_party_acct, :third_party_zipcode, :third_party_country, :give_access,
19
- :estimated_budget, :access_role, :send_email, :password, :password_2, :require_pwd_change,
20
- :campaign_category, :lead_source, :web_lead, :referrer, :keywords, :click_stream,
21
- :last_page_visited, :visits, :first_visit, :last_visit, :bill_pay, :opening_balance, :last_modified,
22
- :opening_balance_date, :opening_balance_account, :stage, :email_transactions, :print_transactions,
23
- :fax_transactions, :sync_partner_teams, :is_budget_approved, :global_subscription_status,
24
- :sales_readiness, :sales_team_list, :buying_reason, :download_list, :buying_time_frame,
25
- :addressbook_list, :subscriptions_list, :contact_roles_list, :currency_list, :credit_cards_list,
26
- :partners_list, :group_pricing_list, :item_pricing_list, :custom_field_list
27
- ].each do |field|
28
- customer.should have_field(field)
29
- end
30
- end
31
-
32
- describe '.get' do
33
- context 'when the response is successful' do
34
- let(:response) { NetSuite::Response.new(:success => true, :body => { :is_person => true }) }
35
-
36
- it 'returns a Customer instance populated with the data from the response object' do
37
- NetSuite::Actions::Get.should_receive(:call).with(1).and_return(response)
38
- customer = NetSuite::Entities::Customer.get(1)
39
- customer.should be_kind_of(NetSuite::Entities::Customer)
40
- customer.is_person.should be_true
41
- end
42
- end
43
-
44
- context 'when the response is unsuccessful' do
45
- let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
46
-
47
- it 'returns a Customer instance populated with the data from the response object' do
48
- NetSuite::Actions::Get.should_receive(:call).with(1).and_return(response)
49
- lambda {
50
- NetSuite::Entities::Customer.get(1)
51
- }.should raise_error(NetSuite::RecordNotFound, 'NetSuite::Entities::Customer with ID=1 could not be found')
52
- end
53
- end
54
- end
55
-
56
- describe '#add' do
57
- let(:test_data) { { :entity_id => 'TEST CUSTOMER', :is_person => true } }
58
-
59
- context 'when the response is successful' do
60
- let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
61
-
62
- it 'returns true' do
63
- NetSuite::Actions::Add.should_receive(:call).
64
- with(test_data).
65
- and_return(response)
66
- customer = NetSuite::Entities::Customer.new(test_data)
67
- customer.add.should be_true
68
- end
69
- end
70
-
71
- context 'when the response is unsuccessful' do
72
- let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
73
- it 'returns false' do
74
- NetSuite::Actions::Add.should_receive(:call).
75
- with(test_data).
76
- and_return(response)
77
- customer = NetSuite::Entities::Customer.new(test_data)
78
- customer.add.should be_false
79
- end
80
- end
81
- end
82
-
83
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe NetSuite::Transactions::Invoice do
4
- let(:invoice) { NetSuite::Transactions::Invoice.new }
5
- let(:customer) { NetSuite::Entities::Customer.new }
6
- let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
7
-
8
- it 'has all the right fields' do
9
- [
10
- :internal_id, :external_id, :created_date, :last_modified_date, :custom_form, :entity, :tran_date, :tran_id,
11
- :source, :created_from, :posting_period, :opportunity, :department, :klass, :terms, :location, :subsidiary,
12
- :due_date, :discount_date, :discount_amount, :sales_rep, :contrib_pct, :partner, :lead_source, :start_date,
13
- :end_date, :other_ref_name, :memo, :sales_effective_date, :exclude_commission, :total_cost_estimate,
14
- :est_gross_profit, :est_gross_profit_percent, :rev_rec_schedule, :rev_rec_start_date, :rev_rec_end_date,
15
- :amount_paid, :amount_remaining, :balance, :account, :on_credit_hold, :exchange_rate, :currency_name,
16
- :promo_code, :discount_item, :discount_rate, :is_taxable, :tax_item, :tax_rate, :to_be_printed, :to_be_emailed,
17
- :to_be_faxed, :fax, :message_sel, :message, :transaction_bill_address, :bill_address_list, :bill_address,
18
- :transaction_ship_address, :ship_address_list, :ship_address, :fob, :ship_date, :ship_method, :shipping_cost,
19
- :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :handling_tax_code, :handling_tax_1_rate,
20
- :handling_cost, :handling_tax_2_rate, :tracking_numbers, :linked_tracking_numbers, :sales_group, :sub_total,
21
- :revenue_status, :recognized_revenue, :deferred_revenue, :rev_rec_on_rev_commitment, :sync_sales_teams,
22
- :discount_total, :tax_total, :alt_shipping_cost, :alt_handling_cost, :total, :status, :job, :billing_schedule,
23
- :email, :tax_2_total, :vat_reg_num, :exp_cost_discount, :item_cost_discount, :time_discount, :exp_cost_disc_rate,
24
- :item_cost_disc_rate, :time_disc_rate, :exp_cost_disc_amount, :exp_cost_tax_rate_1, :exp_cost_tax_rate_2,
25
- :item_cost_disc_amount, :exp_cost_tax_code, :exp_cost_disc_tax_1_amt, :item_cost_tax_rate_1, :time_disc_amount,
26
- :item_cost_tax_code, :exp_cost_disc_taxable, :item_cost_disc_taxable, :item_cost_tax_rate_2, :item_cost_disc_tax_1_amt,
27
- :item_cost_disc_print, :time_disc_taxable, :time_tax_rate_1, :exp_cost_disc_print, :time_tax_code, :time_disc_print,
28
- :gift_cert_applied, :time_disc_tax_1_amt, :tran_is_vsoe_bundle, :time_tax_rate_2, :vsoe_auto_calc, :sync_partner_teams,
29
- :sales_team_list, :partners_list, :item_list, :item_cost_list, :gift_cert_redemption_list, :exp_cost_list, :time_list,
30
- :ship_group_list, :custom_field_list
31
- ].each do |field|
32
- invoice.should have_field(field)
33
- end
34
- end
35
-
36
- it 'handles the "klass" field correctly'
37
- # This field maps to 'class' but cannot be set as such in Ruby as it will cause runtime errors.
38
-
39
- describe '.initialize' do
40
- context 'when the request is successful' do
41
- it 'returns an initialized invoice from the customer entity' do
42
- NetSuite::Actions::Initialize.should_receive(:call).with(customer).and_return(response)
43
- invoice = NetSuite::Transactions::Invoice.initialize(customer)
44
- invoice.should be_kind_of(NetSuite::Transactions::Invoice)
45
- end
46
- end
47
-
48
- context 'when the response is unsuccessful' do
49
- pending
50
- end
51
- end
52
-
53
- end