netsuite 0.0.18 → 0.0.19

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.
data/lib/netsuite.rb CHANGED
@@ -26,23 +26,26 @@ require 'netsuite/actions/get'
26
26
  require 'netsuite/actions/initialize'
27
27
  require 'netsuite/actions/update'
28
28
 
29
- # RECORDS
29
+ # SUBRECORDS
30
30
  require 'netsuite/records/bill_address'
31
31
  require 'netsuite/records/custom_field'
32
32
  require 'netsuite/records/custom_field_list'
33
- require 'netsuite/records/customer'
34
33
  require 'netsuite/records/customer_addressbook'
35
34
  require 'netsuite/records/customer_addressbook_list'
36
- require 'netsuite/records/invoice'
37
- require 'netsuite/records/record_ref'
38
35
  require 'netsuite/records/ship_address'
39
- require 'netsuite/records/non_inventory_sale_item'
36
+ require 'netsuite/records/record_ref'
40
37
  require 'netsuite/records/invoice_item'
41
38
  require 'netsuite/records/invoice_item_list'
39
+ require 'netsuite/records/custom_record_ref'
40
+ require 'netsuite/records/duration'
41
+
42
+ # RECORDS
43
+ require 'netsuite/records/customer'
44
+ require 'netsuite/records/invoice'
45
+ require 'netsuite/records/non_inventory_sale_item'
42
46
  require 'netsuite/records/classification'
43
47
  require 'netsuite/records/custom_record'
44
48
  require 'netsuite/records/custom_record_type'
45
- require 'netsuite/records/custom_record_ref'
46
49
  require 'netsuite/records/job'
47
50
 
48
51
  module NetSuite
@@ -17,7 +17,6 @@ module NetSuite
17
17
  soap.namespaces['xmlns:tranSales'] = 'urn:sales_2011_2.transactions.webservices.netsuite.com'
18
18
  soap.namespaces['xmlns:platformCommon'] = 'urn:common_2011_2.platform.webservices.netsuite.com'
19
19
  soap.namespaces['xmlns:listAcct'] = 'urn:accounting_2011_2.lists.webservices.netsuite.com'
20
- soap.namespaces['xmlns:setupCustom'] = 'urn:customization_2011_2.setup.webservices.netsuite.com'
21
20
  soap.header = auth_header
22
21
  soap.body = request_body
23
22
  end
@@ -32,20 +31,21 @@ module NetSuite
32
31
  # </platformMsgs:add>
33
32
  # </soap:Body>
34
33
  def request_body
35
- body = {
34
+ hash = {
36
35
  'platformMsgs:record' => @obj.to_record,
37
36
  :attributes! => {
38
- 'platformMsgs:record' => {}
37
+ 'platformMsgs:record' => {
38
+ 'xsi:type' => @obj.record_type
39
+ }
39
40
  }
40
41
  }
41
- body[:attributes!]['platformMsgs:record']['externalId'] = @obj.external_id if @obj.respond_to?(:external_id) && @obj.external_id
42
- body[:attributes!]['platformMsgs:record']['internalId'] = @obj.internal_id if @obj.respond_to?(:internal_id) && @obj.internal_id
43
- body[:attributes!]['platformMsgs:record']['xsi:type'] = @obj.kind_of?(NetSuite::Records::CustomRecord) ? @obj.record_type : soap_type
44
- body
45
- end
46
-
47
- def soap_type
48
- @obj.class.to_s.split('::').last.lower_camelcase
42
+ if @obj.respond_to?(:internal_id) && @obj.internal_id
43
+ hash[:attributes!]['platformMsgs:record']['platformMsgs:internalId'] = @obj.internal_id
44
+ end
45
+ if @obj.respond_to?(:external_id) && @obj.external_id
46
+ hash[:attributes!]['platformMsgs:record']['platformMsgs:externalId'] = @obj.external_id
47
+ end
48
+ hash
49
49
  end
50
50
 
51
51
  def success?
@@ -7,12 +7,14 @@ module NetSuite
7
7
  include Namespaces::SetupCustom
8
8
 
9
9
  fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :created,
10
- :custom_field_list, :custom_record_id, :description, :disclaimer, :enabl_email_merge, :enable_numbering,
11
- :include_name, :is_available_offline, :is_inactive, :is_numbering_updateable, :is_ordered, :last_modified, :name,
10
+ :custom_record_id, :description, :disclaimer, :enabl_email_merge, :enable_numbering, :include_name,
11
+ :is_available_offline, :is_inactive, :is_numbering_updateable, :is_ordered, :last_modified, :name,
12
12
  :numbering_current_number, :numbering_init, :numbering_min_digits, :numbering_prefix, :numbering_suffix,
13
13
  :record_name, :script_id, :show_creation_date, :show_creation_date_on_list, :show_id, :show_last_modified_on_list,
14
14
  :show_last_modified, :show_notes, :show_owner, :show_owner_allow_change, :show_owner_on_list, :use_permissions
15
15
 
16
+ field :custom_field_list, CustomFieldList
17
+
16
18
  record_refs :custom_form, :owner, :rec_type
17
19
 
18
20
  attr_reader :internal_id
@@ -24,14 +26,6 @@ module NetSuite
24
26
  initialize_from_attributes_hash(attributes)
25
27
  end
26
28
 
27
- def custom_field_list
28
- attributes[:custom_field_list] ||= CustomFieldList.new
29
- end
30
-
31
- def custom_field_list=(attrs)
32
- attributes[:custom_field_list] = attrs.kind_of?(CustomFieldList) ? attrs : CustomFieldList.new(attrs)
33
- end
34
-
35
29
  def self.get(options = {})
36
30
  options.merge!(:type_id => type_id) unless options[:type_id]
37
31
  response = Actions::Get.call(self, options.merge!(:custom => true))
@@ -2,8 +2,16 @@ module NetSuite
2
2
  module Records
3
3
  class CustomRecordType
4
4
  include Support::Fields
5
+ include Support::RecordRefs
5
6
 
6
- fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :description, :disclaimer, :enable_mail_merge, :enable_numbering, :include_name, :is_available_offline, :is_inactive, :is_numbering_updateable, :is_ordered, :numbering_current_number, :numbering_init, :numbering_min_digits, :numbering_prefix, :numbering_suffix, :record_name, :script_id, :show_creation_date, :show_creation_date_on_list, :show_id, :show_last_modified, :show_last_modified_on_list, :show_notes, :show_owner, :show_owner_allow_change, :show_owner_on_list, :use_permissions
7
+ fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :description,
8
+ :disclaimer, :enable_mail_merge, :enable_numbering, :include_name, :is_available_offline, :is_inactive,
9
+ :is_numbering_updateable, :is_ordered, :numbering_current_number, :numbering_init, :numbering_min_digits,
10
+ :numbering_prefix, :numbering_suffix, :record_name, :script_id, :show_creation_date, :show_creation_date_on_list,
11
+ :show_id, :show_last_modified, :show_last_modified_on_list, :show_notes, :show_owner, :show_owner_allow_change,
12
+ :show_owner_on_list, :use_permissions
13
+
14
+ record_ref :owner
7
15
 
8
16
  attr_reader :internal_id
9
17
  attr_accessor :external_id
@@ -6,11 +6,10 @@ module NetSuite
6
6
  include Support::Records
7
7
  include Namespaces::ListRel
8
8
 
9
- fields :access_role, :account_number, :addressbook_list, :aging, :alt_email, :alt_name, :alt_phone, :bill_pay,
9
+ fields :access_role, :account_number, :aging, :alt_email, :alt_name, :alt_phone, :bill_pay,
10
10
  :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
11
- :consol_aging, :consol_days_overdue,
12
- :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
13
- :currency, :currency_list, :custom_field_list, :date_created, :days_overdue, :default_address,
11
+ :consol_aging, :consol_days_overdue, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override,
12
+ :credit_limit, :currency, :currency_list, :custom_field_list, :date_created, :days_overdue, :default_address,
14
13
  :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id,
15
14
  :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
16
15
  :group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
@@ -23,6 +22,8 @@ module NetSuite
23
22
  :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :url,
24
23
  :vat_reg_number, :visits, :web_lead
25
24
 
25
+ field :addressbook_list, CustomerAddressbookList
26
+
26
27
  read_only_fields :balance, :consol_balance, :deposit_balance, :consol_deposit_balance, :overdue_balance,
27
28
  :consol_overdue_balance, :unbilled_orders, :consol_unbilled_orders
28
29
 
@@ -37,14 +38,6 @@ module NetSuite
37
38
  initialize_from_attributes_hash(attributes)
38
39
  end
39
40
 
40
- def addressbook_list=(attrs)
41
- attributes[:addressbook_list] = CustomerAddressbookList.new(attrs)
42
- end
43
-
44
- def addressbook_list
45
- attributes[:addressbook_list] ||= CustomerAddressbookList.new
46
- end
47
-
48
41
  def self.get(options = {})
49
42
  response = Actions::Get.call(self, options)
50
43
  if response.success?
@@ -0,0 +1,14 @@
1
+ module NetSuite
2
+ module Records
3
+ class Duration
4
+ include Support::Fields
5
+
6
+ fields :time_span, :unit
7
+
8
+ def initialize(attributes = {})
9
+ initialize_from_attributes_hash(attributes)
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -27,6 +27,11 @@ module NetSuite
27
27
  :to_be_printed, :total_cost_estimate, :tracking_numbers, :tran_date, :tran_id, :tran_is_vsoe_bundle,
28
28
  :transaction_bill_address, :transaction_ship_address, :vat_reg_num, :vsoe_auto_calc
29
29
 
30
+ field :transaction_bill_address, BillAddress
31
+ field :transaction_ship_address, ShipAddress
32
+ field :item_list, InvoiceItemList
33
+ field :custom_field_list, CustomFieldList
34
+
30
35
  read_only_fields :sub_total, :discount_total, :total, :recognized_revenue, :amount_remaining, :amount_paid
31
36
 
32
37
  record_refs :account, :bill_address_list, :custom_form, :entity, :klass, :posting_period, :ship_address_list
@@ -40,38 +45,6 @@ module NetSuite
40
45
  initialize_from_attributes_hash(attributes)
41
46
  end
42
47
 
43
- def transaction_bill_address=(attrs)
44
- attributes[:transaction_bill_address] = attrs.kind_of?(BillAddress) ? attrs : BillAddress.new(attrs)
45
- end
46
-
47
- def transaction_bill_address
48
- attributes[:transaction_bill_address] ||= BillAddress.new
49
- end
50
-
51
- def transaction_ship_address=(attrs)
52
- attributes[:transaction_ship_address] = attrs.kind_of?(ShipAddress) ? attrs : ShipAddress.new(attrs)
53
- end
54
-
55
- def transaction_ship_address
56
- attributes[:transaction_ship_address] ||= ShipAddress.new
57
- end
58
-
59
- def item_list
60
- attributes[:item_list] ||= InvoiceItemList.new
61
- end
62
-
63
- def item_list=(attrs)
64
- attributes[:item_list] = InvoiceItemList.new(attrs)
65
- end
66
-
67
- def custom_field_list
68
- attributes[:custom_field_list] ||= CustomFieldList.new
69
- end
70
-
71
- def custom_field_list=(attrs)
72
- attributes[:custom_field_list] = attrs.kind_of?(CustomFieldList) ? attrs : CustomFieldList.new(attrs)
73
- end
74
-
75
48
  def self.get(options = {})
76
49
  response = Actions::Get.call(self, options)
77
50
  if response.success?
@@ -2,21 +2,45 @@ module NetSuite
2
2
  module Records
3
3
  class Job
4
4
  include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::ListRel
5
8
 
6
9
  fields :account_number, :allocate_payroll_expenses, :allow_all_resources_for_tasks, :allow_expenses, :allow_time,
7
10
  :alt_name, :alt_phone, :bill_pay, :calculated_end_date, :calculated_end_date_baseline, :comments, :company_name,
8
- :date_created, :default_address, :email, :end_date, :entity_id, :estimated_cost, :estimated_gross_profit,
9
- :estimated_gross_profit_percent, :estimated_labor_cost, :estimated_labor_cost_baseline, :estimated_labor_revenue,
10
- :estimated_revenue, :estimated_time, :fax, :fx_rate, :include_crm_tasks_in_totals, :is_exempt_time, :is_inactive,
11
- :is_productive_time, :is_utilized_time, :job_price, :last_baseline_date, :last_modified_date, :limit_time_to_assignees,
12
- :materialize_time, :opening_balance, :opening_balance_account, :opening_balance_date, :percent_complete,
13
- :percent_time_complete, :phone, :phonetic_name, :projected_end_date, :projected_end_date_baseline, :start_date,
14
- :start_date_baseline
11
+ :date_created, :default_address, :email, :email_preference, :end_date, :entity_id, :estimated_cost,
12
+ :estimated_gross_profit, :estimated_gross_profit_percent, :estimated_labor_cost, :estimated_labor_cost_baseline,
13
+ :estimated_labor_revenue, :estimated_revenue, :estimated_time, :fax, :fx_rate, :global_subscription_status,
14
+ :include_crm_tasks_in_totals, :is_exempt_time, :is_inactive, :is_productive_time, :is_utilized_time, :job_billing_type,
15
+ :job_price, :last_baseline_date, :last_modified_date, :limit_time_to_assignees, :materialize_time, :opening_balance,
16
+ :opening_balance_account, :opening_balance_date, :percent_complete, :percent_time_complete, :phone, :phonetic_name,
17
+ :projected_end_date, :projected_end_date_baseline, :start_date, :start_date_baseline
18
+
19
+ field :estimated_time_override, Duration
20
+ field :actual_time, Duration
21
+ field :time_remaining, Duration
22
+
23
+ record_refs :billing_schedule, :category, :currency, :custom_form, :entity_status, :estimate_rev_rec_template, :job_item,
24
+ :job_type, :language, :parent, :subsidiary, :workplace
15
25
 
16
26
  def initialize(attributes = {})
17
27
  initialize_from_attributes_hash(attributes)
18
28
  end
19
29
 
30
+ def self.get(options = {})
31
+ response = Actions::Get.call(self, options)
32
+ if response.success?
33
+ new(response.body)
34
+ else
35
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
36
+ end
37
+ end
38
+
39
+ def add
40
+ response = Actions::Add.call(self)
41
+ response.success?
42
+ end
43
+
20
44
  end
21
45
  end
22
46
  end
@@ -19,15 +19,25 @@ module NetSuite
19
19
  end
20
20
  end
21
21
 
22
- def field(name)
22
+ def field(name, klass = nil)
23
23
  name_sym = name.to_sym
24
24
  fields << name_sym
25
- define_method(name_sym) do
26
- attributes[name_sym]
27
- end
25
+ if klass
26
+ define_method(name_sym) do
27
+ attributes[name_sym] ||= klass.new
28
+ end
28
29
 
29
- define_method("#{name_sym}=") do |value|
30
- attributes[name_sym] = value
30
+ define_method("#{name_sym}=") do |value|
31
+ attributes[name_sym] = value.kind_of?(klass) ? value : klass.new(value)
32
+ end
33
+ else
34
+ define_method(name_sym) do
35
+ attributes[name_sym]
36
+ end
37
+
38
+ define_method("#{name_sym}=") do |value|
39
+ attributes[name_sym] = value
40
+ end
31
41
  end
32
42
  end
33
43
 
@@ -15,15 +15,7 @@ module NetSuite
15
15
  end
16
16
 
17
17
  def record_ref(name)
18
- name_sym = name.to_sym
19
- fields << name_sym
20
- define_method "#{name}=" do |attrs|
21
- attributes[name_sym] = NetSuite::Records::RecordRef.new(attrs)
22
- end
23
-
24
- define_method name_sym do
25
- attributes[name_sym]
26
- end
18
+ field name, NetSuite::Records::RecordRef
27
19
  end
28
20
 
29
21
  end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.18'
2
+ VERSION = '0.0.19'
3
3
  end
@@ -24,8 +24,23 @@ describe NetSuite::Records::CustomRecord do
24
24
  end
25
25
  end
26
26
 
27
- it 'has a custom_field_list' do
28
- record.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
27
+ describe '#custom_field_list' do
28
+ it 'can be set from attributes' do
29
+ attributes = {
30
+ :custom_field => {
31
+ :amount => 10
32
+ }
33
+ }
34
+ record.custom_field_list = attributes
35
+ record.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
36
+ record.custom_field_list.custom_fields.length.should eql(1)
37
+ end
38
+
39
+ it 'can be set from a CustomFieldList object' do
40
+ custom_field_list = NetSuite::Records::CustomFieldList.new
41
+ record.custom_field_list = custom_field_list
42
+ record.custom_field_list.should eql(custom_field_list)
43
+ end
29
44
  end
30
45
 
31
46
  describe '.get' do
@@ -3,8 +3,6 @@ require 'spec_helper'
3
3
  describe NetSuite::Records::CustomRecordType do
4
4
  let(:record_type) { NetSuite::Records::CustomRecordType.new }
5
5
 
6
- # <element name="owner" type="platformCore:RecordRef" minOccurs="0"/>
7
-
8
6
  # <element name="fieldList" type="setupCustom:CustomRecordTypeFieldList" minOccurs="0"/>
9
7
  # <element name="tabsList" type="setupCustom:CustomRecordTypeTabsList" minOccurs="0"/>
10
8
  # <element name="sublistsList" type="setupCustom:CustomRecordTypeSublistsList" minOccurs="0"/>
@@ -28,6 +26,14 @@ describe NetSuite::Records::CustomRecordType do
28
26
  end
29
27
  end
30
28
 
29
+ it 'has all the right record refs' do
30
+ [
31
+ :owner
32
+ ].each do |record_ref|
33
+ record_type.should have_record_ref(record_ref)
34
+ end
35
+ end
36
+
31
37
  describe '.get' do
32
38
  context 'when the response is successful' do
33
39
  let(:response) { NetSuite::Response.new(:success => true, :body => { :allow_attachments => true }) }
@@ -34,24 +34,33 @@ describe NetSuite::Records::Customer do
34
34
  end
35
35
  end
36
36
 
37
- it 'has an addressbook_list field that builds a CustomerAddressbookList object' do
38
- customer.addressbook_list = {
39
- :addressbook => {
40
- :addr1 => '123 Happy Lane',
41
- :addr_text => "123 Happy Lane\nLos Angeles CA 90007",
42
- :city => 'Los Angeles',
43
- :country => '_unitedStates',
44
- :default_billing => true,
45
- :default_shipping => true,
46
- :internal_id => '567',
47
- :is_residential => false,
48
- :label => '123 Happy Lane',
49
- :override => false,
50
- :state => 'CA',
51
- :zip => '90007'
37
+ describe '#addressbook_list' do
38
+ it 'can be set from attributes' do
39
+ customer.addressbook_list = {
40
+ :addressbook => {
41
+ :addr1 => '123 Happy Lane',
42
+ :addr_text => "123 Happy Lane\nLos Angeles CA 90007",
43
+ :city => 'Los Angeles',
44
+ :country => '_unitedStates',
45
+ :default_billing => true,
46
+ :default_shipping => true,
47
+ :internal_id => '567',
48
+ :is_residential => false,
49
+ :label => '123 Happy Lane',
50
+ :override => false,
51
+ :state => 'CA',
52
+ :zip => '90007'
53
+ }
52
54
  }
53
- }
54
- customer.addressbook_list.should be_kind_of(NetSuite::Records::CustomerAddressbookList)
55
+ customer.addressbook_list.should be_kind_of(NetSuite::Records::CustomerAddressbookList)
56
+ customer.addressbook_list.addressbooks.length.should eql(1)
57
+ end
58
+
59
+ it 'can be set from a CustomerAddressbookList object' do
60
+ customer_addressbook_list = NetSuite::Records::CustomerAddressbookList.new
61
+ customer.addressbook_list = customer_addressbook_list
62
+ customer.addressbook_list.should eql(customer_addressbook_list)
63
+ end
55
64
  end
56
65
 
57
66
  describe '.get' do
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Duration do
4
+ let(:duration) { NetSuite::Records::Duration.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :time_span, :unit
9
+ ].each do |field|
10
+ duration.should have_field(field)
11
+ end
12
+ end
13
+
14
+ end
@@ -49,16 +49,83 @@ describe NetSuite::Records::Invoice do
49
49
  end
50
50
 
51
51
  describe '#custom_field_list' do
52
- it 'returns a CustomFieldList object that contains many CustomFields' do
52
+ it 'can be set from attributes' do
53
+ attributes = {
54
+ :custom_field => {
55
+ :amount => 10
56
+ }
57
+ }
58
+ invoice.custom_field_list = attributes
53
59
  invoice.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
60
+ invoice.custom_field_list.custom_fields.length.should eql(1)
61
+ end
62
+
63
+ it 'can be set from a CustomFieldList object' do
64
+ custom_field_list = NetSuite::Records::CustomFieldList.new
65
+ invoice.custom_field_list = custom_field_list
66
+ invoice.custom_field_list.should eql(custom_field_list)
54
67
  end
55
68
  end
56
69
 
57
- describe 'item_list' do
58
- context 'when the attributes constitute an Array of items' do
59
- it 'builds an InvoiceItemList for each list item_list field' do
60
- invoice.item_list.should be_kind_of(NetSuite::Records::InvoiceItemList)
61
- end
70
+ describe '#item_list' do
71
+ it 'can be set from attributes' do
72
+ attributes = {
73
+ :item => {
74
+ :amount => 10
75
+ }
76
+ }
77
+ invoice.item_list = attributes
78
+ invoice.item_list.should be_kind_of(NetSuite::Records::InvoiceItemList)
79
+ invoice.item_list.items.length.should eql(1)
80
+ end
81
+
82
+ it 'can be set from a CustomFieldList object' do
83
+ item_list = NetSuite::Records::InvoiceItemList.new
84
+ invoice.item_list = item_list
85
+ invoice.item_list.should eql(item_list)
86
+ end
87
+ end
88
+
89
+ describe '#transaction_bill_address' do
90
+ it 'has a transaction_bill_address field that builds a BillAddress object from attributes' do
91
+ invoice.transaction_bill_address = {
92
+ :"@xmlns:platform_common" => 'urn:common_2011_2.platform.webservices.netsuite.com',
93
+ :bill_addr1 => '123 Happy Lane',
94
+ :bill_city => 'Los Angeles',
95
+ :bill_country => '_unitedStates',
96
+ :bill_state => 'CA',
97
+ :bill_zip => '90007'
98
+ }
99
+ invoice.transaction_bill_address.should be_kind_of(NetSuite::Records::BillAddress)
100
+ invoice.transaction_bill_address.bill_city.should eql('Los Angeles')
101
+ end
102
+
103
+ it 'can be set with a BillAddress object' do
104
+ bill_address = NetSuite::Records::BillAddress.new
105
+ invoice.transaction_bill_address = bill_address
106
+ invoice.transaction_bill_address.should eql(bill_address)
107
+ end
108
+ end
109
+
110
+ describe '#transaction_ship_address' do
111
+ it 'has a transaction_ship_address field that builds a ShipAddress object from attributes' do
112
+ invoice.transaction_ship_address = {
113
+ :"@xmlns:platform_common" => 'urn:common_2011_2.platform.webservices.netsuite.com',
114
+ :ship_addr1 => '123 Happy Lane',
115
+ :ship_city => 'Los Angeles',
116
+ :ship_country => '_unitedStates',
117
+ :ship_is_residential => false,
118
+ :ship_state => 'CA',
119
+ :ship_zip => '90007'
120
+ }
121
+ invoice.transaction_ship_address.should be_kind_of(NetSuite::Records::ShipAddress)
122
+ invoice.transaction_ship_address.ship_addr1.should eql('123 Happy Lane')
123
+ end
124
+
125
+ it 'can be set with a ShipAddress object' do
126
+ ship_address = NetSuite::Records::ShipAddress.new
127
+ invoice.transaction_ship_address = ship_address
128
+ invoice.transaction_ship_address.should eql(ship_address)
62
129
  end
63
130
  end
64
131
 
@@ -100,35 +167,6 @@ describe NetSuite::Records::Invoice do
100
167
  end
101
168
  end
102
169
 
103
- describe '#add' do
104
- pending
105
- end
106
-
107
- it 'has a transaction_bill_address field that builds a BillAddress object' do
108
- invoice.transaction_bill_address = {
109
- :"@xmlns:platform_common" => 'urn:common_2011_2.platform.webservices.netsuite.com',
110
- :bill_addr1 => '123 Happy Lane',
111
- :bill_city => 'Los Angeles',
112
- :bill_country => '_unitedStates',
113
- :bill_state => 'CA',
114
- :bill_zip => '90007'
115
- }
116
- invoice.transaction_bill_address.should be_kind_of(NetSuite::Records::BillAddress)
117
- end
118
-
119
- it 'has a transaction_ship_address field that builds a ShipAddress object' do
120
- invoice.transaction_ship_address = {
121
- :"@xmlns:platform_common" => 'urn:common_2011_2.platform.webservices.netsuite.com',
122
- :ship_addr1 => '123 Happy Lane',
123
- :ship_city => 'Los Angeles',
124
- :ship_country => '_unitedStates',
125
- :ship_is_residential => false,
126
- :ship_state => 'CA',
127
- :ship_zip => '90007'
128
- }
129
- invoice.transaction_ship_address.should be_kind_of(NetSuite::Records::ShipAddress)
130
- end
131
-
132
170
  describe '#add' do
133
171
  let(:test_data) { { :email => 'test@example.com', :fax => '1234567890' } }
134
172
 
@@ -3,24 +3,6 @@ require 'spec_helper'
3
3
  describe NetSuite::Records::Job do
4
4
  let(:job) { NetSuite::Records::Job.new }
5
5
 
6
- #<element name="customForm" type="platformCore:RecordRef" minOccurs="0"/>
7
- #<element name="entityStatus" type="platformCore:RecordRef" minOccurs="0"/>
8
- #<element name="parent" type="platformCore:RecordRef" minOccurs="0"/>
9
- #<element name="category" type="platformCore:RecordRef" minOccurs="0"/>
10
- #<element name="workplace" type="platformCore:RecordRef" minOccurs="0"/>
11
- #<element name="language" type="platformCore:RecordRef" minOccurs="0"/>
12
- #<element name="currency" type="platformCore:RecordRef" minOccurs="0"/>
13
- #<element name="jobType" type="platformCore:RecordRef" minOccurs="0"/>
14
- #<element name="estimatedTimeOverride" type="platformCore:Duration" minOccurs="0"/>
15
- #<element name="emailPreference" type="listRelTyp:EmailPreference" minOccurs="0"/>
16
- #<element name="subsidiary" type="platformCore:RecordRef" minOccurs="0"/>
17
- #<element name="jobBillingType" type="listRelTyp:JobBillingType" minOccurs="0"/>
18
- #<element name="billingSchedule" type="platformCore:RecordRef" minOccurs="0"/>
19
- #<element name="jobItem" type="platformCore:RecordRef" minOccurs="0"/>
20
- #<element name="actualTime" type="platformCore:Duration" minOccurs="0"/>
21
- #<element name="timeRemaining" type="platformCore:Duration" minOccurs="0"/>
22
- #<element name="estimateRevRecTemplate" type="platformCore:RecordRef" minOccurs="0"/>
23
- #<element name="globalSubscriptionStatus" type="platformCommonTyp:GlobalSubscriptionStatus" minOccurs="0"/>
24
6
  #<element name="jobResourcesList" type="listRel:JobResourcesList" minOccurs="0"/>
25
7
  #<element name="addressbookList" type="listRel:JobAddressbookList" minOccurs="0"/>
26
8
  #<element name="milestonesList" type="listRel:JobMilestonesList" minOccurs="0"/>
@@ -31,15 +13,143 @@ describe NetSuite::Records::Job do
31
13
  [
32
14
  :account_number, :allocate_payroll_expenses, :allow_all_resources_for_tasks, :allow_expenses, :allow_time, :alt_name,
33
15
  :alt_phone, :bill_pay, :calculated_end_date, :calculated_end_date_baseline, :comments, :company_name, :date_created,
34
- :default_address, :email, :end_date, :entity_id, :estimated_cost, :estimated_gross_profit, :estimated_gross_profit_percent,
35
- :estimated_labor_cost, :estimated_labor_cost_baseline, :estimated_labor_revenue, :estimated_revenue, :estimated_time, :fax,
36
- :fx_rate, :include_crm_tasks_in_totals, :is_exempt_time, :is_inactive, :is_productive_time, :is_utilized_time, :job_price,
37
- :last_baseline_date, :last_modified_date, :limit_time_to_assignees, :materialize_time, :opening_balance,
38
- :opening_balance_account, :opening_balance_date, :percent_complete, :percent_time_complete, :phone, :phonetic_name,
39
- :projected_end_date, :projected_end_date_baseline, :start_date, :start_date_baseline
16
+ :default_address, :email, :email_preference, :end_date, :entity_id, :estimated_cost, :estimated_gross_profit,
17
+ :estimated_gross_profit_percent, :estimated_labor_cost, :estimated_labor_cost_baseline, :estimated_labor_revenue,
18
+ :estimated_revenue, :estimated_time, :fax, :fx_rate, :global_subscription_status, :include_crm_tasks_in_totals,
19
+ :is_exempt_time, :is_inactive, :is_productive_time, :is_utilized_time, :job_billing_type, :job_price, :last_baseline_date,
20
+ :last_modified_date, :limit_time_to_assignees, :materialize_time, :opening_balance, :opening_balance_account,
21
+ :opening_balance_date, :percent_complete, :percent_time_complete, :phone, :phonetic_name, :projected_end_date,
22
+ :projected_end_date_baseline, :start_date, :start_date_baseline
40
23
  ].each do |field|
41
24
  job.should have_field(field)
42
25
  end
43
26
  end
44
27
 
28
+ it 'has all the right record refs' do
29
+ [
30
+ :billing_schedule, :category, :currency, :custom_form, :entity_status, :estimate_rev_rec_template, :job_item, :job_type, :language, :parent, :subsidiary, :workplace
31
+ ].each do |record_ref|
32
+ job.should have_record_ref(record_ref)
33
+ end
34
+ end
35
+
36
+ describe '#estimated_time_override' do
37
+ it 'can be set from attributes' do
38
+ attributes = {
39
+ :time_span => 10
40
+ }
41
+ job.estimated_time_override = attributes
42
+ job.estimated_time_override.should be_kind_of(NetSuite::Records::Duration)
43
+ job.estimated_time_override.time_span.should eql(10)
44
+ end
45
+
46
+ it 'can be set from a Duration object' do
47
+ duration = NetSuite::Records::Duration.new
48
+ job.estimated_time_override = duration
49
+ job.estimated_time_override.should eql(duration)
50
+ end
51
+ end
52
+
53
+ describe '#actual_time' do
54
+ it 'can be set from attributes' do
55
+ attributes = {
56
+ :time_span => 20
57
+ }
58
+ job.actual_time = attributes
59
+ job.actual_time.should be_kind_of(NetSuite::Records::Duration)
60
+ job.actual_time.time_span.should eql(20)
61
+ end
62
+
63
+ it 'can be set from a Duration object' do
64
+ duration = NetSuite::Records::Duration.new
65
+ job.actual_time = duration
66
+ job.actual_time.should eql(duration)
67
+ end
68
+ end
69
+
70
+ describe '#time_remaining' do
71
+ it 'can be set from attributes' do
72
+ attributes = {
73
+ :time_span => 30
74
+ }
75
+ job.time_remaining = attributes
76
+ job.time_remaining.should be_kind_of(NetSuite::Records::Duration)
77
+ job.time_remaining.time_span.should eql(30)
78
+ end
79
+
80
+ it 'can be set from a Duration object' do
81
+ duration = NetSuite::Records::Duration.new
82
+ job.time_remaining = duration
83
+ job.time_remaining.should eql(duration)
84
+ end
85
+ end
86
+
87
+ describe '.get' do
88
+ context 'when the response is successful' do
89
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :account_number => 7 }) }
90
+
91
+ it 'returns a Job instance populated with the data from the response object' do
92
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::Job, :external_id => 1).and_return(response)
93
+ job = NetSuite::Records::Job.get(:external_id => 1)
94
+ job.should be_kind_of(NetSuite::Records::Job)
95
+ job.account_number.should be_true
96
+ end
97
+ end
98
+
99
+ context 'when the response is unsuccessful' do
100
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
101
+
102
+ it 'raises a RecordNotFound exception' do
103
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::Job, :external_id => 1).and_return(response)
104
+ lambda {
105
+ NetSuite::Records::Job.get(:external_id => 1)
106
+ }.should raise_error(NetSuite::RecordNotFound,
107
+ /NetSuite::Records::Job with OPTIONS=(.*) could not be found/)
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#add' do
113
+ let(:job) { NetSuite::Records::Job.new(:account_number => 7, :job_price => 10) }
114
+
115
+ context 'when the response is successful' do
116
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
117
+
118
+ it 'returns true' do
119
+ NetSuite::Actions::Add.should_receive(:call).
120
+ with(job).
121
+ and_return(response)
122
+ job.add.should be_true
123
+ end
124
+ end
125
+
126
+ context 'when the response is unsuccessful' do
127
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
128
+
129
+ it 'returns false' do
130
+ NetSuite::Actions::Add.should_receive(:call).
131
+ with(job).
132
+ and_return(response)
133
+ job.add.should be_false
134
+ end
135
+ end
136
+ end
137
+
138
+ describe '#to_record' do
139
+ let(:job) { NetSuite::Records::Job.new(:entity_id => 'TEST JOB', :account_number => 7) }
140
+
141
+ it 'returns a hash of attributes that can be used in a SOAP request' do
142
+ job.to_record.should eql({
143
+ 'listRel:entityId' => 'TEST JOB',
144
+ 'listRel:accountNumber' => 7
145
+ })
146
+ end
147
+ end
148
+
149
+ describe '#record_type' do
150
+ it 'returns a string type for the record to be used in a SOAP request' do
151
+ job.record_type.should eql('listRel:Job')
152
+ end
153
+ end
154
+
45
155
  end
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: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 18
10
- version: 0.0.18
9
+ - 19
10
+ version: 0.0.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran
@@ -122,6 +122,7 @@ files:
122
122
  - lib/netsuite/records/customer.rb
123
123
  - lib/netsuite/records/customer_addressbook.rb
124
124
  - lib/netsuite/records/customer_addressbook_list.rb
125
+ - lib/netsuite/records/duration.rb
125
126
  - lib/netsuite/records/invoice.rb
126
127
  - lib/netsuite/records/invoice_item.rb
127
128
  - lib/netsuite/records/invoice_item_list.rb
@@ -152,6 +153,7 @@ files:
152
153
  - spec/netsuite/records/customer_addressbook_list_spec.rb
153
154
  - spec/netsuite/records/customer_addressbook_spec.rb
154
155
  - spec/netsuite/records/customer_spec.rb
156
+ - spec/netsuite/records/duration_spec.rb
155
157
  - spec/netsuite/records/invoice_item_list_spec.rb
156
158
  - spec/netsuite/records/invoice_item_spec.rb
157
159
  - spec/netsuite/records/invoice_spec.rb
@@ -229,6 +231,7 @@ test_files:
229
231
  - spec/netsuite/records/customer_addressbook_list_spec.rb
230
232
  - spec/netsuite/records/customer_addressbook_spec.rb
231
233
  - spec/netsuite/records/customer_spec.rb
234
+ - spec/netsuite/records/duration_spec.rb
232
235
  - spec/netsuite/records/invoice_item_list_spec.rb
233
236
  - spec/netsuite/records/invoice_item_spec.rb
234
237
  - spec/netsuite/records/invoice_spec.rb