netsuite 0.0.34 → 0.0.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,13 +59,22 @@ module NetSuite
59
59
  end
60
60
 
61
61
  module Support
62
- def get(options = {})
63
- response = NetSuite::Actions::Get.call(self, options)
64
- if response.success?
65
- new(response.body)
66
- else
67
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
62
+
63
+ def self.included(base)
64
+ base.extend(ClassMethods)
65
+ end
66
+
67
+ module ClassMethods
68
+
69
+ def get(options = {})
70
+ response = NetSuite::Actions::Get.call(self, options)
71
+ if response.success?
72
+ new(response.body)
73
+ else
74
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
75
+ end
68
76
  end
77
+
69
78
  end
70
79
  end
71
80
 
@@ -52,13 +52,27 @@ module NetSuite
52
52
  end
53
53
 
54
54
  module Support
55
- def initialize(object)
56
- response = NetSuite::Actions::Initialize.call(self, object)
57
- if response.success?
58
- new(response.body)
59
- else
60
- raise InitializationError, "#{self}.initialize with #{object} failed."
55
+
56
+ def self.included(base)
57
+ (class << base; self; end).instance_eval do # We have to do this because Class has a private
58
+ define_method :initialize do |*args| # #initialize method that this method will override.
59
+ super(*args)
60
+ end
61
+ end
62
+ base.extend(ClassMethods)
63
+ end
64
+
65
+ module ClassMethods
66
+
67
+ def initialize(object)
68
+ response = NetSuite::Actions::Initialize.call(self, object)
69
+ if response.success?
70
+ new(response.body)
71
+ else
72
+ raise InitializationError, "#{self}.initialize with #{object} failed."
73
+ end
61
74
  end
75
+
62
76
  end
63
77
  end
64
78
 
@@ -6,13 +6,15 @@ module NetSuite
6
6
  include Support::Records
7
7
  include Namespaces::TranSales
8
8
 
9
- fields :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent, :custom_field_list,
9
+ fields :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent,
10
10
  :defer_rev_rec, :description, :gift_cert_from, :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email,
11
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
12
+ :klass, :options, :order_line, :percent_complete, :quantity, :quantity_available, :quantity_fulfilled,
13
+ :quantity_on_hand, :quantity_ordered, :quantity_remaining, :rate, :rev_rec_end_date, :rev_rec_start_date,
14
+ :serial_numbers, :ship_group, :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral,
15
+ :vsoe_delivered, :vsoe_permit_discount, :vsoe_price
16
+
17
+ field :custom_field_list, CustomFieldList
16
18
 
17
19
  record_refs :department, :item, :job, :location, :price, :rev_rec_schedule, :ship_address, :ship_method, :tax_code, :units
18
20
 
@@ -29,6 +31,14 @@ module NetSuite
29
31
  self.attributes = record.send(:attributes)
30
32
  end
31
33
 
34
+ def to_record
35
+ rec = super
36
+ if rec["#{record_namespace}:customFieldList"]
37
+ rec["#{record_namespace}:customFieldList!"] = rec.delete("#{record_namespace}:customFieldList")
38
+ end
39
+ rec
40
+ end
41
+
32
42
  end
33
43
  end
34
44
  end
@@ -17,7 +17,7 @@ module NetSuite
17
17
  def action(name)
18
18
  case name
19
19
  when :get
20
- self.extend(NetSuite::Actions::Get::Support)
20
+ self.send(:include, NetSuite::Actions::Get::Support)
21
21
  when :add
22
22
  self.send(:include, NetSuite::Actions::Add::Support)
23
23
  when :delete
@@ -25,12 +25,7 @@ module NetSuite
25
25
  when :update
26
26
  self.send(:include, NetSuite::Actions::Update::Support)
27
27
  when :initialize
28
- (class << self; self; end).instance_eval do # We have to do this because Class has a private
29
- define_method :initialize do |*args| # #initialize method that this method will override.
30
- super(*args)
31
- end
32
- end
33
- self.extend(NetSuite::Actions::Initialize::Support)
28
+ self.send(:include, NetSuite::Actions::Initialize::Support)
34
29
  else
35
30
  raise "Unknown action: #{name.inspect}"
36
31
  end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.34'
2
+ VERSION = '0.0.35'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/netsuite/version', __FILE__)
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+ require 'netsuite/version'
3
4
 
4
5
  Gem::Specification.new do |gem|
5
6
  gem.authors = ['Ryan Moran']
@@ -1,18 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NetSuite::Records::InvoiceItem do
4
- let(:list) { NetSuite::Records::InvoiceItem.new }
4
+ let(:item) { NetSuite::Records::InvoiceItem.new }
5
5
 
6
6
  it 'has the right fields' do
7
7
  [
8
- :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent, :custom_field_list,
9
- :defer_rev_rec, :description, :gift_cert_from, :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email,
10
- :gift_cert_recipient_name, :gross_amt, :inventory_detail, :is_taxable, :item_is_fulfilled, :license_code, :line, :options,
11
- :order_line, :percent_complete, :quantity, :quantity_available, :quantity_fulfilled, :quantity_on_hand, :quantity_ordered,
12
- :quantity_remaining, :rate, :rev_rec_end_date, :rev_rec_start_date, :serial_numbers, :ship_group, :tax1_amt, :tax_rate1,
13
- :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount, :vsoe_price
8
+ :amount, :amount_ordered, :bin_numbers, :cost_estimate, :cost_estimate_type, :current_percent, :defer_rev_rec,
9
+ :description, :gift_cert_from, :gift_cert_message, :gift_cert_number, :gift_cert_recipient_email,
10
+ :gift_cert_recipient_name, :gross_amt, :inventory_detail, :is_taxable, :item_is_fulfilled, :license_code, :line, :klass,
11
+ :options, :order_line, :percent_complete, :quantity, :quantity_available, :quantity_fulfilled, :quantity_on_hand,
12
+ :quantity_ordered, :quantity_remaining, :rate, :rev_rec_end_date, :rev_rec_start_date, :serial_numbers, :ship_group,
13
+ :tax1_amt, :tax_rate1, :tax_rate2, :vsoe_allocation, :vsoe_amount, :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount,
14
+ :vsoe_price
14
15
  ].each do |field|
15
- list.should have_field(field)
16
+ item.should have_field(field)
16
17
  end
17
18
  end
18
19
 
@@ -20,24 +21,41 @@ describe NetSuite::Records::InvoiceItem do
20
21
  [
21
22
  :department, :item, :job, :location, :price, :rev_rec_schedule, :ship_address, :ship_method, :tax_code, :units
22
23
  ].each do |record_ref|
23
- list.should have_record_ref(record_ref)
24
+ item.should have_record_ref(record_ref)
24
25
  end
25
26
  end
26
27
 
27
28
  it 'can initialize from a record' do
28
29
  record = NetSuite::Records::InvoiceItem.new(:amount => 123, :cost_estimate => 234)
29
- list = NetSuite::Records::InvoiceItem.new(record)
30
- list.should be_kind_of(NetSuite::Records::InvoiceItem)
31
- list.amount.should eql(123)
32
- list.cost_estimate.should eql(234)
30
+ item = NetSuite::Records::InvoiceItem.new(record)
31
+ item.should be_kind_of(NetSuite::Records::InvoiceItem)
32
+ item.amount.should eql(123)
33
+ item.cost_estimate.should eql(234)
33
34
  end
34
35
 
35
- # :class RecordRef
36
+ describe '#custom_field_list' do
37
+ it 'can be set from attributes' do
38
+ attributes = {
39
+ :custom_field => {
40
+ :value => 10
41
+ }
42
+ }
43
+ item.custom_field_list = attributes
44
+ item.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
45
+ item.custom_field_list.custom_fields.length.should eql(1)
46
+ end
47
+
48
+ it 'can be set from a CustomFieldList object' do
49
+ custom_field_list = NetSuite::Records::CustomFieldList.new
50
+ item.custom_field_list = custom_field_list
51
+ item.custom_field_list.should eql(custom_field_list)
52
+ end
53
+ end
36
54
 
37
55
  describe '#to_record' do
38
56
  before do
39
- list.amount = '7'
40
- list.description = 'Some thingy'
57
+ item.amount = '7'
58
+ item.description = 'Some thingy'
41
59
  end
42
60
 
43
61
  it 'can represent itself as a SOAP record' do
@@ -45,13 +63,13 @@ describe NetSuite::Records::InvoiceItem do
45
63
  'tranSales:amount' => '7',
46
64
  'tranSales:description' => 'Some thingy'
47
65
  }
48
- list.to_record.should eql(record)
66
+ item.to_record.should eql(record)
49
67
  end
50
68
  end
51
69
 
52
70
  describe '#record_type' do
53
71
  it 'returns a string of the SOAP record type' do
54
- list.record_type.should eql('tranSales:InvoiceItem')
72
+ item.record_type.should eql('tranSales:InvoiceItem')
55
73
  end
56
74
  end
57
75
 
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: 91
4
+ hash: 89
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 34
10
- version: 0.0.34
9
+ - 35
10
+ version: 0.0.35
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran