netsuite 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,59 +1,65 @@
1
1
  require 'set'
2
2
 
3
3
  require 'netsuite/version'
4
- require 'netsuite/configuration'
5
4
  require 'netsuite/errors'
6
- require 'netsuite/response'
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
- require 'netsuite/namespaces/setup_custom'
15
- require 'netsuite/namespaces/tran_cust'
16
-
17
- # SUPPORT
18
- require 'netsuite/support/attributes'
19
- require 'netsuite/support/fields'
20
- require 'netsuite/support/record_refs'
21
- require 'netsuite/support/records'
22
- require 'netsuite/support/requests'
23
-
24
- # ACTIONS
25
- require 'netsuite/actions/add'
26
- require 'netsuite/actions/get'
27
- require 'netsuite/actions/initialize'
28
- require 'netsuite/actions/update'
29
-
30
- # SUBRECORDS
31
- require 'netsuite/records/bill_address'
32
- require 'netsuite/records/custom_field'
33
- require 'netsuite/records/custom_field_list'
34
- require 'netsuite/records/customer_addressbook'
35
- require 'netsuite/records/customer_addressbook_list'
36
- require 'netsuite/records/ship_address'
37
- require 'netsuite/records/record_ref'
38
- require 'netsuite/records/invoice_item'
39
- require 'netsuite/records/invoice_item_list'
40
- require 'netsuite/records/custom_record_ref'
41
- require 'netsuite/records/duration'
42
-
43
- # RECORDS
44
- require 'netsuite/records/customer'
45
- require 'netsuite/records/invoice'
46
- require 'netsuite/records/non_inventory_sale_item'
47
- require 'netsuite/records/classification'
48
- require 'netsuite/records/custom_record'
49
- require 'netsuite/records/custom_record_type'
50
- require 'netsuite/records/job'
51
- require 'netsuite/records/customer_payment'
52
- require 'netsuite/records/payment_method'
53
- require 'netsuite/records/credit_memo'
54
- require 'netsuite/records/location'
55
5
 
56
6
  module NetSuite
7
+ autoload :Configuration, 'netsuite/configuration'
8
+ autoload :Response, 'netsuite/response'
9
+
10
+ module Namespaces
11
+ autoload :ListAcct, 'netsuite/namespaces/list_acct'
12
+ autoload :ListRel, 'netsuite/namespaces/list_rel'
13
+ autoload :PlatformCommon, 'netsuite/namespaces/platform_common'
14
+ autoload :PlatformCore, 'netsuite/namespaces/platform_core'
15
+ autoload :TranCust, 'netsuite/namespaces/tran_cust'
16
+ autoload :TranGeneral, 'netsuite/namespaces/tran_general'
17
+ autoload :TranSales, 'netsuite/namespaces/tran_sales'
18
+ autoload :SetupCustom, 'netsuite/namespaces/setup_custom'
19
+ end
20
+
21
+ module Support
22
+ autoload :Attributes, 'netsuite/support/attributes'
23
+ autoload :Fields, 'netsuite/support/fields'
24
+ autoload :RecordRefs, 'netsuite/support/record_refs'
25
+ autoload :Records, 'netsuite/support/records'
26
+ autoload :Requests, 'netsuite/support/requests'
27
+ end
28
+
29
+ module Actions
30
+ autoload :Add, 'netsuite/actions/add'
31
+ autoload :Get, 'netsuite/actions/get'
32
+ autoload :Initialize, 'netsuite/actions/initialize'
33
+ autoload :Update, 'netsuite/actions/update'
34
+ end
35
+
36
+ module Records
37
+ autoload :BillAddress, 'netsuite/records/bill_address'
38
+ autoload :Classification, 'netsuite/records/classification'
39
+ autoload :CreditMemo, 'netsuite/records/credit_memo'
40
+ autoload :CustomField, 'netsuite/records/custom_field'
41
+ autoload :CustomFieldList, 'netsuite/records/custom_field_list'
42
+ autoload :CustomRecord, 'netsuite/records/custom_record'
43
+ autoload :CustomRecordRef, 'netsuite/records/custom_record_ref'
44
+ autoload :CustomRecordType, 'netsuite/records/custom_record_type'
45
+ autoload :Customer, 'netsuite/records/customer'
46
+ autoload :CustomerAddressbook, 'netsuite/records/customer_addressbook'
47
+ autoload :CustomerAddressbookList, 'netsuite/records/customer_addressbook_list'
48
+ autoload :CustomerPayment, 'netsuite/records/customer_payment'
49
+ autoload :Duration, 'netsuite/records/duration'
50
+ autoload :Invoice, 'netsuite/records/invoice'
51
+ autoload :InvoiceItem, 'netsuite/records/invoice_item'
52
+ autoload :InvoiceItemList, 'netsuite/records/invoice_item_list'
53
+ autoload :Job, 'netsuite/records/job'
54
+ autoload :JournalEntry, 'netsuite/records/journal_entry'
55
+ autoload :JournalEntryLine, 'netsuite/records/journal_entry_line'
56
+ autoload :JournalEntryLineList, 'netsuite/records/journal_entry_line_list'
57
+ autoload :Location, 'netsuite/records/location'
58
+ autoload :NonInventorySaleItem, 'netsuite/records/non_inventory_sale_item'
59
+ autoload :PaymentMethod, 'netsuite/records/payment_method'
60
+ autoload :RecordRef, 'netsuite/records/record_ref'
61
+ autoload :ShipAddress, 'netsuite/records/ship_address'
62
+ end
57
63
 
58
64
  def self.configure(&block)
59
65
  NetSuite::Configuration.instance_eval(&block)
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module TranGeneral
4
+
5
+ def record_namespace
6
+ 'tranGeneral'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module NetSuite
2
+ module Records
3
+ class JournalEntry
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::TranGeneral
8
+
9
+ fields :approved, :created_date, :exchange_rate, :last_modified_date, :reversal_date, :reversal_defer, :reversal_entry,
10
+ :tran_date, :tran_id
11
+
12
+ field :custom_field_list, CustomFieldList
13
+ field :line_list, JournalEntryLineList
14
+
15
+ record_refs :created_from, :currency, :custom_form, :department, :klass, :location, :parent_expense_alloc,
16
+ :posting_period, :subsidiary, :to_subsidiary
17
+
18
+ def initialize(attributes = {})
19
+ initialize_from_attributes_hash(attributes)
20
+ end
21
+
22
+ def self.get(options = {})
23
+ response = Actions::Get.call(self, options)
24
+ if response.success?
25
+ new(response.body)
26
+ else
27
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
28
+ end
29
+ end
30
+
31
+ def add
32
+ response = Actions::Add.call(self)
33
+ response.success?
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module NetSuite
2
+ module Records
3
+ class JournalEntryLine
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::TranGeneral
8
+
9
+ fields :credit, :debit, :eliminate, :end_date, :gross_amt, :memo, :residual, :start_date, :tax1_amt, :tax_rate1
10
+ field :custom_field_list, CustomFieldList
11
+ record_refs :account, :department, :entity, :klass, :location, :schedule, :schedule_num, :tax1_acct, :tax_code
12
+
13
+ def initialize(attributes = {})
14
+ initialize_from_attributes_hash(attributes)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module NetSuite
2
+ module Records
3
+ class JournalEntryLineList
4
+ include Support::Fields
5
+ include Namespaces::TranGeneral
6
+
7
+ def initialize(attributes = {})
8
+ case attributes[:line]
9
+ when Hash
10
+ lines << JournalEntryLine.new(attributes[:line])
11
+ when Array
12
+ attributes[:line].each { |line| lines << JournalEntryLine.new(line) }
13
+ end
14
+ end
15
+
16
+ def lines
17
+ @lines ||= []
18
+ end
19
+
20
+ def to_record
21
+ lines.map do |line|
22
+ { "#{record_namespace}:line" => line.to_record }
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.21'
2
+ VERSION = '0.0.22'
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::JournalEntryLineList do
4
+ let(:list) { NetSuite::Records::JournalEntryLineList.new }
5
+
6
+ it 'has a custom_fields attribute' do
7
+ list.lines.should be_kind_of(Array)
8
+ end
9
+
10
+ describe '#to_record' do
11
+ before do
12
+ list.lines << NetSuite::Records::JournalEntryLine.new(:memo => 'This is a memo')
13
+ end
14
+
15
+ it 'can represent itself as a SOAP record' do
16
+ record = [
17
+ {
18
+ 'tranGeneral:line' => {
19
+ 'tranGeneral:memo' => 'This is a memo'
20
+ }
21
+ }
22
+ ]
23
+ list.to_record.should eql(record)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::JournalEntryLine do
4
+ let(:line) { NetSuite::Records::JournalEntryLine.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :credit, :debit, :eliminate, :end_date, :gross_amt, :memo, :residual, :start_date, :tax1_amt, :tax_rate1
9
+ ].each do |field|
10
+ line.should have_field(field)
11
+ end
12
+ end
13
+
14
+ it 'has all the right record refs' do
15
+ [
16
+ :account, :department, :entity, :klass, :location, :schedule, :schedule_num, :tax1_acct, :tax_code
17
+ ].each do |record_ref|
18
+ line.should have_record_ref(record_ref)
19
+ end
20
+ end
21
+
22
+ describe '#custom_field_list' do
23
+ it 'can be set from attributes' do
24
+ attributes = {
25
+ :custom_field => {
26
+ :amount => 10
27
+ }
28
+ }
29
+ line.custom_field_list = attributes
30
+ line.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
31
+ line.custom_field_list.custom_fields.length.should eql(1)
32
+ end
33
+
34
+ it 'can be set from a CustomFieldList object' do
35
+ custom_field_list = NetSuite::Records::CustomFieldList.new
36
+ line.custom_field_list = custom_field_list
37
+ line.custom_field_list.should eql(custom_field_list)
38
+ end
39
+ end
40
+
41
+ describe '#to_record' do
42
+ let(:line) { NetSuite::Records::JournalEntryLine.new(:memo => 'This is a memo', :eliminate => true) }
43
+
44
+ it 'returns a hash of attributes that can be used in a SOAP request' do
45
+ line.to_record.should eql({
46
+ 'tranGeneral:memo' => 'This is a memo',
47
+ 'tranGeneral:eliminate' => true
48
+ })
49
+ end
50
+ end
51
+
52
+ describe '#record_type' do
53
+ it 'returns a string type for the record to be used in a SOAP request' do
54
+ line.record_type.should eql('tranGeneral:JournalEntryLine')
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::JournalEntry do
4
+ let(:entry) { NetSuite::Records::JournalEntry.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :approved, :created_date, :exchange_rate, :last_modified_date, :reversal_date,
9
+ :reversal_defer, :reversal_entry, :tran_date, :tran_id
10
+ ].each do |field|
11
+ entry.should have_field(field)
12
+ end
13
+ end
14
+
15
+ it 'has all the right record refs' do
16
+ [
17
+ :created_from, :currency, :custom_form, :department, :klass, :location, :parent_expense_alloc, :posting_period,
18
+ :subsidiary, :to_subsidiary
19
+ ].each do |record_ref|
20
+ entry.should have_record_ref(record_ref)
21
+ end
22
+ end
23
+
24
+ describe '#custom_field_list' do
25
+ it 'can be set from attributes' do
26
+ attributes = {
27
+ :custom_field => {
28
+ :amount => 10
29
+ }
30
+ }
31
+ entry.custom_field_list = attributes
32
+ entry.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
33
+ entry.custom_field_list.custom_fields.length.should eql(1)
34
+ end
35
+
36
+ it 'can be set from a CustomFieldList object' do
37
+ custom_field_list = NetSuite::Records::CustomFieldList.new
38
+ entry.custom_field_list = custom_field_list
39
+ entry.custom_field_list.should eql(custom_field_list)
40
+ end
41
+ end
42
+
43
+ describe '#line_list' do
44
+ it 'can be set from attributes' do
45
+ attributes = {
46
+ :line => {
47
+
48
+ }
49
+ }
50
+ entry.line_list = attributes
51
+ entry.line_list.should be_kind_of(NetSuite::Records::JournalEntryLineList)
52
+ entry.line_list.lines.length.should eql(1)
53
+ end
54
+
55
+ it 'can be set from a JournalEntryLineList object' do
56
+ line_list = NetSuite::Records::JournalEntryLineList.new
57
+ entry.line_list = line_list
58
+ entry.line_list.should eql(line_list)
59
+ end
60
+ end
61
+
62
+ describe '.get' do
63
+ context 'when the response is successful' do
64
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :approved => true }) }
65
+
66
+ it 'returns a JournalEntry instance populated with the data from the response object' do
67
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::JournalEntry, :external_id => 1).and_return(response)
68
+ customer = NetSuite::Records::JournalEntry.get(:external_id => 1)
69
+ customer.should be_kind_of(NetSuite::Records::JournalEntry)
70
+ customer.approved.should be_true
71
+ end
72
+ end
73
+
74
+ context 'when the response is unsuccessful' do
75
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
76
+
77
+ it 'raises a RecordNotFound exception' do
78
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::JournalEntry, :external_id => 1).and_return(response)
79
+ lambda {
80
+ NetSuite::Records::JournalEntry.get(:external_id => 1)
81
+ }.should raise_error(NetSuite::RecordNotFound,
82
+ /NetSuite::Records::JournalEntry with OPTIONS=(.*) could not be found/)
83
+ end
84
+ end
85
+ end
86
+
87
+ describe '#add' do
88
+ let(:entry) { NetSuite::Records::JournalEntry.new(:approved => true) }
89
+
90
+ context 'when the response is successful' do
91
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
92
+
93
+ it 'returns true' do
94
+ NetSuite::Actions::Add.should_receive(:call).
95
+ with(entry).
96
+ and_return(response)
97
+ entry.add.should be_true
98
+ end
99
+ end
100
+
101
+ context 'when the response is unsuccessful' do
102
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
103
+
104
+ it 'returns false' do
105
+ NetSuite::Actions::Add.should_receive(:call).
106
+ with(entry).
107
+ and_return(response)
108
+ entry.add.should be_false
109
+ end
110
+ end
111
+ end
112
+
113
+ describe '#to_record' do
114
+ let(:entry) { NetSuite::Records::JournalEntry.new(:tran_id => '1234', :approved => true) }
115
+
116
+ it 'returns a hash of attributes that can be used in a SOAP request' do
117
+ entry.to_record.should eql({
118
+ 'tranGeneral:tranId' => '1234',
119
+ 'tranGeneral:approved' => true
120
+ })
121
+ end
122
+ end
123
+
124
+ describe '#record_type' do
125
+ it 'returns a string type for the record to be used in a SOAP request' do
126
+ entry.record_type.should eql('tranGeneral:JournalEntry')
127
+ end
128
+ end
129
+
130
+ 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: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 21
10
- version: 0.0.21
9
+ - 22
10
+ version: 0.0.22
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran
@@ -112,6 +112,7 @@ files:
112
112
  - lib/netsuite/namespaces/platform_core.rb
113
113
  - lib/netsuite/namespaces/setup_custom.rb
114
114
  - lib/netsuite/namespaces/tran_cust.rb
115
+ - lib/netsuite/namespaces/tran_general.rb
115
116
  - lib/netsuite/namespaces/tran_sales.rb
116
117
  - lib/netsuite/records/bill_address.rb
117
118
  - lib/netsuite/records/classification.rb
@@ -130,6 +131,9 @@ files:
130
131
  - lib/netsuite/records/invoice_item.rb
131
132
  - lib/netsuite/records/invoice_item_list.rb
132
133
  - lib/netsuite/records/job.rb
134
+ - lib/netsuite/records/journal_entry.rb
135
+ - lib/netsuite/records/journal_entry_line.rb
136
+ - lib/netsuite/records/journal_entry_line_list.rb
133
137
  - lib/netsuite/records/location.rb
134
138
  - lib/netsuite/records/non_inventory_sale_item.rb
135
139
  - lib/netsuite/records/payment_method.rb
@@ -165,6 +169,9 @@ files:
165
169
  - spec/netsuite/records/invoice_item_spec.rb
166
170
  - spec/netsuite/records/invoice_spec.rb
167
171
  - spec/netsuite/records/job_spec.rb
172
+ - spec/netsuite/records/journal_entry_line_list_spec.rb
173
+ - spec/netsuite/records/journal_entry_line_spec.rb
174
+ - spec/netsuite/records/journal_entry_spec.rb
168
175
  - spec/netsuite/records/location_spec.rb
169
176
  - spec/netsuite/records/non_inventory_sale_item_spec.rb
170
177
  - spec/netsuite/records/payment_method_spec.rb
@@ -247,6 +254,9 @@ test_files:
247
254
  - spec/netsuite/records/invoice_item_spec.rb
248
255
  - spec/netsuite/records/invoice_spec.rb
249
256
  - spec/netsuite/records/job_spec.rb
257
+ - spec/netsuite/records/journal_entry_line_list_spec.rb
258
+ - spec/netsuite/records/journal_entry_line_spec.rb
259
+ - spec/netsuite/records/journal_entry_spec.rb
250
260
  - spec/netsuite/records/location_spec.rb
251
261
  - spec/netsuite/records/non_inventory_sale_item_spec.rb
252
262
  - spec/netsuite/records/payment_method_spec.rb