Module: NetSuite::Support::Records
- Includes:
- Namespaces::PlatformCore, Attributes
- Included in:
- Records::Account, Records::AssemblyItem, Records::BillAddress, Records::Contact, Records::CreditMemo, Records::CreditMemoApply, Records::CreditMemoItem, Records::CustomField, Records::CustomRecord, Records::CustomRecordRef, Records::Customer, Records::CustomerAddressbook, Records::CustomerDeposit, Records::CustomerPayment, Records::CustomerPaymentApply, Records::CustomerRefund, Records::CustomerRefundApply, Records::CustomerRefundDeposit, Records::CustomerRefundDepositList, Records::Duration, Records::InventoryItem, Records::Invoice, Records::InvoiceItem, Records::ItemFulfillment, Records::ItemFulfillmentItem, Records::Job, Records::JournalEntry, Records::JournalEntryLine, Records::NonInventorySaleItem, Records::PhoneCall, Records::RecordRef, Records::RevRecTemplate, Records::SalesOrder, Records::SalesOrderItem, Records::ShipAddress, Records::SupportCase, Records::Task
- Defined in:
- lib/netsuite/support/records.rb
Instance Method Summary
collapse
#record_namespace
Methods included from Attributes
#attributes, #attributes=, #initialize_from_attributes_hash
Instance Method Details
#record_type ⇒ Object
51
52
53
|
# File 'lib/netsuite/support/records.rb', line 51
def record_type
"#{record_namespace}:#{self.class.to_s.split('::').last}"
end
|
#to_attributes!(hash, kname, v) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/netsuite/support/records.rb', line 25
def to_attributes!(hash, kname, v)
if v.respond_to?(:internal_id) && v.internal_id
hash[:attributes!] ||= {}
hash[:attributes!][kname] ||= {}
hash[:attributes!][kname]['internalId'] = v.internal_id
end
if v.respond_to?(:external_id) && v.external_id
hash[:attributes!] ||= {}
hash[:attributes!][kname] ||= {}
hash[:attributes!][kname]['externalId'] = v.external_id
end
if v.kind_of?(NetSuite::Records::RecordRef) && v.type
hash[:attributes!] ||= {}
hash[:attributes!][kname] ||= {}
hash[:attributes!][kname]['type'] = v.type.lower_camelcase
end
if v.kind_of?(NetSuite::Records::CustomRecordRef) && v.type_id
hash[:attributes!] ||= {}
hash[:attributes!][kname] ||= {}
hash[:attributes!][kname]['typeId'] = v.type_id.lower_camelcase
end
end
|
#to_record ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/netsuite/support/records.rb', line 7
def to_record
attributes.reject { |k,v| self.class.read_only_fields.include?(k) }.inject({}) do |hash, (k,v)|
kname = "#{record_namespace}:"
kname += k == :klass ? 'class' : k.to_s.lower_camelcase
to_attributes!(hash, kname, v)
if Array === v
v = v.map { |i| i.respond_to?(:to_record) ? i.to_record : i }
elsif v.respond_to?(:to_record)
v = v.to_record
end
hash[kname] = v
hash
end
end
|