netsuite 0.0.10 → 0.0.11

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.
Files changed (48) hide show
  1. data/lib/netsuite.rb +17 -6
  2. data/lib/netsuite/actions/add.rb +7 -4
  3. data/lib/netsuite/actions/get.rb +1 -1
  4. data/lib/netsuite/actions/initialize.rb +1 -1
  5. data/lib/netsuite/namespaces/list_acct.rb +11 -0
  6. data/lib/netsuite/namespaces/list_rel.rb +11 -0
  7. data/lib/netsuite/namespaces/platform_common.rb +11 -0
  8. data/lib/netsuite/namespaces/platform_core.rb +11 -0
  9. data/lib/netsuite/namespaces/tran_sales.rb +11 -0
  10. data/lib/netsuite/records/bill_address.rb +3 -1
  11. data/lib/netsuite/records/classification.rb +27 -0
  12. data/lib/netsuite/records/customer.rb +4 -3
  13. data/lib/netsuite/records/customer_addressbook_list.rb +3 -2
  14. data/lib/netsuite/records/invoice.rb +18 -15
  15. data/lib/netsuite/records/invoice_item.rb +34 -0
  16. data/lib/netsuite/records/invoice_item_list.rb +11 -12
  17. data/lib/netsuite/records/non_inventory_sale_item.rb +4 -2
  18. data/lib/netsuite/records/record_ref.rb +8 -2
  19. data/lib/netsuite/records/ship_address.rb +3 -1
  20. data/lib/netsuite/support/attributes.rb +22 -0
  21. data/lib/netsuite/support/fields.rb +54 -0
  22. data/lib/netsuite/support/record_refs.rb +33 -0
  23. data/lib/netsuite/support/records.rb +40 -0
  24. data/lib/netsuite/{savon_support.rb → support/requests.rb} +2 -2
  25. data/lib/netsuite/version.rb +1 -1
  26. data/spec/netsuite/records/bill_address_spec.rb +37 -0
  27. data/spec/netsuite/records/classification_spec.rb +37 -0
  28. data/spec/netsuite/records/customer_addressbook_list_spec.rb +53 -28
  29. data/spec/netsuite/records/invoice_item_list_spec.rb +13 -13
  30. data/spec/netsuite/records/invoice_item_spec.rb +58 -0
  31. data/spec/netsuite/records/invoice_spec.rb +33 -83
  32. data/spec/netsuite/records/non_inventory_sale_item_spec.rb +21 -0
  33. data/spec/netsuite/records/record_ref_spec.rb +26 -0
  34. data/spec/netsuite/records/ship_address_spec.rb +21 -0
  35. data/spec/netsuite/support/attributes_spec.rb +5 -0
  36. data/spec/netsuite/support/fields_spec.rb +60 -0
  37. data/spec/netsuite/support/record_refs_spec.rb +5 -0
  38. data/spec/netsuite/{record_support_spec.rb → support/records_spec.rb} +6 -5
  39. data/spec/netsuite/{savon_support_spec.rb → support/requests_spec.rb} +2 -2
  40. data/spec/support/read_only_field_matcher.rb +7 -0
  41. metadata +32 -19
  42. data/lib/netsuite/attribute_support.rb +0 -16
  43. data/lib/netsuite/field_support.rb +0 -36
  44. data/lib/netsuite/record_ref_support.rb +0 -31
  45. data/lib/netsuite/record_support.rb +0 -17
  46. data/spec/netsuite/attribute_support_spec.rb +0 -5
  47. data/spec/netsuite/field_support_spec.rb +0 -34
  48. data/spec/netsuite/record_ref_support_spec.rb +0 -5
data/lib/netsuite.rb CHANGED
@@ -1,14 +1,23 @@
1
1
  require 'set'
2
2
 
3
+ require 'netsuite/version'
3
4
  require 'netsuite/configuration'
4
5
  require 'netsuite/errors'
5
6
  require 'netsuite/response'
6
- require 'netsuite/version'
7
- require 'netsuite/attribute_support'
8
- require 'netsuite/field_support'
9
- require 'netsuite/record_support'
10
- require 'netsuite/savon_support'
11
- require 'netsuite/record_ref_support'
7
+
8
+ # NAMESPACES
9
+ require 'netsuite/namespaces/platform_core'
10
+ require 'netsuite/namespaces/platform_common'
11
+ require 'netsuite/namespaces/list_acct'
12
+ require 'netsuite/namespaces/list_rel'
13
+ require 'netsuite/namespaces/tran_sales'
14
+
15
+ # SUPPORT
16
+ require 'netsuite/support/attributes'
17
+ require 'netsuite/support/fields'
18
+ require 'netsuite/support/record_refs'
19
+ require 'netsuite/support/records'
20
+ require 'netsuite/support/requests'
12
21
 
13
22
  # ACTIONS
14
23
  require 'netsuite/actions/add'
@@ -23,7 +32,9 @@ require 'netsuite/records/invoice'
23
32
  require 'netsuite/records/record_ref'
24
33
  require 'netsuite/records/ship_address'
25
34
  require 'netsuite/records/non_inventory_sale_item'
35
+ require 'netsuite/records/invoice_item'
26
36
  require 'netsuite/records/invoice_item_list'
37
+ require 'netsuite/records/classification'
27
38
 
28
39
  module NetSuite
29
40
 
@@ -1,7 +1,7 @@
1
1
  module NetSuite
2
2
  module Actions
3
3
  class Add
4
- include SavonSupport
4
+ include Support::Requests
5
5
 
6
6
  def initialize(obj = nil)
7
7
  @obj = obj
@@ -11,9 +11,12 @@ module NetSuite
11
11
 
12
12
  def request
13
13
  connection.request :platformMsgs, :add do
14
- soap.namespaces['xmlns:platformMsgs'] = 'urn:messages_2011_2.platform.webservices.netsuite.com'
15
- soap.namespaces['xmlns:platformCore'] = 'urn:core_2011_2.platform.webservices.netsuite.com'
16
- soap.namespaces['xmlns:listRel'] = 'urn:relationships_2011_2.lists.webservices.netsuite.com'
14
+ soap.namespaces['xmlns:platformMsgs'] = 'urn:messages_2011_2.platform.webservices.netsuite.com'
15
+ soap.namespaces['xmlns:platformCore'] = 'urn:core_2011_2.platform.webservices.netsuite.com'
16
+ soap.namespaces['xmlns:listRel'] = 'urn:relationships_2011_2.lists.webservices.netsuite.com'
17
+ soap.namespaces['xmlns:tranSales'] = 'urn:sales_2011_2.transactions.webservices.netsuite.com'
18
+ soap.namespaces['xmlns:platformCommon'] = 'urn:common_2011_2.platform.webservices.netsuite.com'
19
+ soap.namespaces['xmlns:listAcct'] = 'urn:accounting_2011_2.lists.webservices.netsuite.com'
17
20
  soap.header = auth_header
18
21
  soap.body = request_body
19
22
  end
@@ -1,7 +1,7 @@
1
1
  module NetSuite
2
2
  module Actions
3
3
  class Get
4
- include SavonSupport
4
+ include Support::Requests
5
5
 
6
6
  def initialize(id, klass)
7
7
  @id = id
@@ -1,7 +1,7 @@
1
1
  module NetSuite
2
2
  module Actions
3
3
  class Initialize
4
- include SavonSupport
4
+ include Support::Requests
5
5
 
6
6
  def initialize(obj)
7
7
  @obj = obj
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module ListAcct
4
+
5
+ def record_namespace
6
+ 'listAcct'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module ListRel
4
+
5
+ def record_namespace
6
+ 'listRel'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module PlatformCommon
4
+
5
+ def record_namespace
6
+ 'platformCommon'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module PlatformCore
4
+
5
+ def record_namespace
6
+ 'platformCore'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module TranSales
4
+
5
+ def record_namespace
6
+ 'tranSales'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,9 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class BillAddress
4
- include FieldSupport
4
+ include Support::Fields
5
+ include Support::Records
6
+ include Namespaces::PlatformCommon
5
7
 
6
8
  fields :bill_attention, :bill_addressee, :bill_phone, :bill_addr1, :bill_addr2,
7
9
  :bill_addr3, :bill_city, :bill_state, :bill_zip, :bill_country
@@ -0,0 +1,27 @@
1
+ module NetSuite
2
+ module Records
3
+ class Classification
4
+ include Support::Fields
5
+
6
+ fields :name, :include_children, :is_inactive, :class_translation_list, :subsidiary_list, :custom_field_list
7
+
8
+ attr_reader :internal_id, :external_id
9
+
10
+ def initialize(attributes = {})
11
+ @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
12
+ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id)
13
+ initialize_from_attributes_hash(attributes)
14
+ end
15
+
16
+ def self.get(id)
17
+ response = Actions::Get.call(id, self)
18
+ if response.success?
19
+ new(response.body)
20
+ else
21
+ raise RecordNotFound, "#{self} with ID=#{id} could not be found"
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,10 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class Customer
4
- include FieldSupport
5
- include RecordSupport
6
- include RecordRefSupport
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::ListRel
7
8
 
8
9
  fields :access_role, :account_number, :addressbook_list, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
9
10
  :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
@@ -1,8 +1,9 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class CustomerAddressbookList
4
- include FieldSupport
5
- include RecordSupport
4
+ include Support::Fields
5
+ include Support::Records
6
+ include Namespaces::ListRel
6
7
 
7
8
  fields :default_shipping, :default_billing, :is_residential, :label, :attention, :addressee,
8
9
  :phone, :addr1, :addr2, :addr3, :city, :zip, :country, :addr_text, :override, :state
@@ -1,32 +1,35 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class Invoice
4
- include FieldSupport
5
- include RecordSupport
6
- include RecordRefSupport
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::TranSales
7
8
 
8
9
  fields :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :balance, :bill_address,
9
10
  :billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
10
11
  :deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
11
- :discount_total, :due_date, :email, :end_date, :est_gross_profit, :est_gross_profit_percent, :exchange_rate,
12
+ :due_date, :email, :end_date, :est_gross_profit, :est_gross_profit_percent, :exchange_rate,
12
13
  :exclude_commission, :exp_cost_disc_amount, :exp_cost_disc_print, :exp_cost_disc_rate, :exp_cost_disc_tax_1_amt,
13
14
  :exp_cost_disc_taxable, :exp_cost_discount, :exp_cost_list, :exp_cost_tax_code, :exp_cost_tax_rate_1,
14
15
  :exp_cost_tax_rate_2, :fax, :fob, :gift_cert_applied, :gift_cert_redemption_list, :handling_cost, :handling_tax_1_rate,
15
16
  :handling_tax_2_rate, :handling_tax_code, :is_taxable, :item_cost_disc_amount, :item_cost_disc_print,
16
17
  :item_cost_disc_rate, :item_cost_disc_tax_1_amt, :item_cost_disc_taxable, :item_cost_discount, :item_cost_list,
17
- :item_cost_tax_code, :item_cost_tax_rate_1, :item_cost_tax_rate_2, :item_list, :job, :klass, :last_modified_date,
18
+ :item_cost_tax_code, :item_cost_tax_rate_1, :item_cost_tax_rate_2, :job, :last_modified_date,
18
19
  :lead_source, :linked_tracking_numbers, :location, :memo, :message, :message_sel, :on_credit_hold, :opportunity,
19
20
  :other_ref_name, :partner, :partners_list, :promo_code, :recognized_revenue, :rev_rec_end_date,
20
21
  :rev_rec_on_rev_commitment, :rev_rec_schedule, :rev_rec_start_date, :revenue_status, :sales_effective_date,
21
22
  :sales_group, :sales_rep, :sales_team_list, :ship_address, :ship_date, :ship_group_list,
22
23
  :ship_method, :shipping_cost, :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :source, :start_date,
23
- :status, :sub_total, :subsidiary, :sync_partner_teams, :sync_sales_teams, :tax_2_total, :tax_item, :tax_rate,
24
+ :status, :subsidiary, :sync_partner_teams, :sync_sales_teams, :tax_2_total, :tax_item, :tax_rate,
24
25
  :tax_total, :terms, :time_disc_amount, :time_disc_print, :time_disc_rate, :time_disc_tax_1_amt, :time_disc_taxable,
25
26
  :time_discount, :time_list, :time_tax_code, :time_tax_rate_1, :time_tax_rate_2, :to_be_emailed, :to_be_faxed,
26
- :to_be_printed, :total, :total_cost_estimate, :tracking_numbers, :tran_date, :tran_id, :tran_is_vsoe_bundle,
27
+ :to_be_printed, :total_cost_estimate, :tracking_numbers, :tran_date, :tran_id, :tran_is_vsoe_bundle,
27
28
  :transaction_bill_address, :transaction_ship_address, :vat_reg_num, :vsoe_auto_calc
28
29
 
29
- record_refs :account, :bill_address_list, :custom_form, :entity, :posting_period, :ship_address_list
30
+ read_only_fields :sub_total, :discount_total, :total
31
+
32
+ record_refs :account, :bill_address_list, :custom_form, :entity, :klass, :posting_period, :ship_address_list
30
33
 
31
34
  attr_reader :internal_id, :external_id
32
35
 
@@ -44,13 +47,8 @@ module NetSuite
44
47
  attributes[:transaction_ship_address] = ShipAddress.new(attrs)
45
48
  end
46
49
 
47
- def item_list=(attrs)
48
- attributes[:item_list] = case attrs[:item]
49
- when Hash
50
- InvoiceItemList.new(attrs[:item])
51
- when Array
52
- attrs[:item].map { |item| InvoiceItemList.new(item) }
53
- end
50
+ def item_list
51
+ attributes[:item_list] ||= InvoiceItemList.new
54
52
  end
55
53
 
56
54
  def self.get(id)
@@ -76,6 +74,11 @@ module NetSuite
76
74
  response.success?
77
75
  end
78
76
 
77
+ def to_record
78
+ attributes.delete(:custom_field_list)
79
+ super
80
+ end
81
+
79
82
  end
80
83
  end
81
84
  end
@@ -0,0 +1,34 @@
1
+ module NetSuite
2
+ module Records
3
+ class InvoiceItem
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::TranSales
8
+
9
+ fields :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent, :custom_field_list,
10
+ :defer_rev_rec, :description, :gift_cert_from, :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email,
11
+ :gift_cert_recipient_name, :gross_amt, :inventory_detail, :is_taxable, :item_is_fulfilled, :license_code, :line,
12
+ :options, :order_line, :percent_complete, :quantity, :quantity_available, :quantity_fulfilled, :quantity_on_hand,
13
+ :quantity_ordered, :quantity_remaining, :rate, :rev_rec_end_date, :rev_rec_start_date, :serial_numbers, :ship_group,
14
+ :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered,
15
+ :vsoe_permit_discount, :vsoe_price
16
+
17
+ record_refs :department, :item, :job, :location, :price, :rev_rec_schedule, :ship_address, :ship_method, :tax_code, :units
18
+
19
+ def initialize(attributes_or_record = {})
20
+ case attributes_or_record
21
+ when Hash
22
+ initialize_from_attributes_hash(attributes_or_record)
23
+ when self.class
24
+ initialize_from_record(attributes_or_record)
25
+ end
26
+ end
27
+
28
+ def initialize_from_record(record)
29
+ self.attributes = record.send(:attributes)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -1,21 +1,20 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class InvoiceItemList
4
- include FieldSupport
5
- include RecordRefSupport
4
+ include Namespaces::TranSales
6
5
 
7
- fields :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent, :custom_field_list,
8
- :defer_rev_rec, :description, :gift_cert_from, :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email,
9
- :gift_cert_recipient_name, :gross_amt, :inventory_detail, :is_taxable, :item_is_fulfilled, :license_code, :line,
10
- :options, :order_line, :percent_complete, :quantity, :quantity_available, :quantity_fulfilled, :quantity_on_hand,
11
- :quantity_ordered, :quantity_remaining, :rate, :rev_rec_end_date, :rev_rec_start_date, :serial_numbers, :ship_group,
12
- :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered,
13
- :vsoe_permit_discount, :vsoe_price
6
+ def items
7
+ @items ||= []
8
+ end
9
+ private :items
14
10
 
15
- record_refs :department, :item, :job, :location, :price, :rev_rec_schedule, :ship_address, :ship_method, :tax_code, :units
11
+ def add_item(item, attributes = {})
12
+ attributes.merge!(:item => item)
13
+ items << InvoiceItem.new(attributes)
14
+ end
16
15
 
17
- def initialize(attributes = {})
18
- initialize_from_attributes_hash(attributes)
16
+ def to_record
17
+ { "#{record_namespace}:item" => items.map(&:to_record) }
19
18
  end
20
19
 
21
20
  end
@@ -1,8 +1,10 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class NonInventorySaleItem
4
- include FieldSupport
5
- include RecordRefSupport
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::ListAcct
6
8
 
7
9
  fields :available_to_partners, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :country_of_manufacture,
8
10
  :created_date, :custom_field_list, :display_name, :dont_show_price, :enforce_min_qty_internally, :exclude_from_sitemap,
@@ -1,16 +1,22 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class RecordRef
4
- include AttributeSupport
4
+ include Support::Fields
5
+ include Support::Records
6
+ include Namespaces::PlatformCore
5
7
 
6
- attr_reader :internal_id
8
+ attr_reader :internal_id, :type
7
9
 
8
10
  def initialize(attributes_or_record = {})
9
11
  case attributes_or_record
10
12
  when Hash
11
13
  attributes_or_record.delete(:"@xmlns:platform_core")
12
14
  @internal_id = attributes_or_record.delete(:internal_id) || attributes_or_record.delete(:@internal_id)
15
+ @type = attributes_or_record.delete(:type) || attributes_or_record.delete(:@type)
13
16
  @attributes = attributes_or_record
17
+ else
18
+ @internal_id = attributes_or_record.internal_id if attributes_or_record.respond_to?(:internal_id)
19
+ @type = attributes_or_record.class.to_s.split('::').last.lower_camelcase
14
20
  end
15
21
  end
16
22
 
@@ -1,7 +1,9 @@
1
1
  module NetSuite
2
2
  module Records
3
3
  class ShipAddress
4
- include FieldSupport
4
+ include Support::Fields
5
+ include Support::Records
6
+ include Namespaces::PlatformCommon
5
7
 
6
8
  fields :ship_attention, :ship_addressee, :ship_phone, :ship_addr1, :ship_addr2,
7
9
  :ship_addr3, :ship_city, :ship_state, :ship_zip, :ship_country, :ship_is_residential
@@ -0,0 +1,22 @@
1
+ module NetSuite
2
+ module Support
3
+ module Attributes
4
+
5
+ def attributes
6
+ @attributes ||= {}
7
+ end
8
+
9
+ def attributes=(attributes)
10
+ @attributes = attributes
11
+ end
12
+
13
+ def initialize_from_attributes_hash(attributes = {})
14
+ attributes.select { |k,v| self.class.fields.include?(k) }.each do |k,v|
15
+ send("#{k}=", v)
16
+ end
17
+ self.klass = attributes[:class] if attributes[:class]
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ module NetSuite
2
+ module Support
3
+ module Fields
4
+ include Attributes
5
+
6
+ def self.included(base)
7
+ base.send(:extend, ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def fields(*args)
13
+ if args.empty?
14
+ @fields ||= Set.new
15
+ else
16
+ args.each do |arg|
17
+ field arg
18
+ end
19
+ end
20
+ end
21
+
22
+ def field(name)
23
+ name_sym = name.to_sym
24
+ fields << name_sym
25
+ define_method(name_sym) do
26
+ attributes[name_sym]
27
+ end
28
+
29
+ define_method("#{name_sym}=") do |value|
30
+ attributes[name_sym] = value
31
+ end
32
+ end
33
+
34
+ def read_only_fields(*args)
35
+ if args.empty?
36
+ @read_only_fields ||= Set.new
37
+ else
38
+ args.each do |arg|
39
+ read_only_field arg
40
+ end
41
+ end
42
+ end
43
+
44
+ def read_only_field(name)
45
+ name_sym = name.to_sym
46
+ read_only_fields << name_sym
47
+ field name
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+ end