Module: NetSuite::Support::Records
- Includes:
- Namespaces::PlatformCore, Attributes
- Included in:
- Records::Account, Records::Address, Records::AssemblyBuild, Records::AssemblyComponent, Records::AssemblyItem, Records::AssemblyUnbuild, Records::BillAddress, Records::BillingSchedule, Records::BillingScheduleMilestone, Records::BillingScheduleRecurrence, Records::Bin, Records::BinNumber, Records::BinTransfer, Records::BinTransferInventory, Records::CashRefund, Records::CashRefundItem, Records::CashSale, Records::CashSaleItem, Records::Classification, Records::Contact, Records::ContactAccessRoles, Records::ContactAddressbook, Records::ContactRole, Records::CostCategory, Records::CreditMemo, Records::CreditMemoApply, Records::CreditMemoItem, Records::Currency, Records::CurrencyRate, Records::CustomField, Records::CustomList, Records::CustomListCustomValue, Records::CustomRecord, Records::CustomRecordRef, Records::Customer, Records::CustomerAddressbook, Records::CustomerCategory, Records::CustomerCreditCards, Records::CustomerCurrency, Records::CustomerDeposit, Records::CustomerDepositApply, Records::CustomerPartner, Records::CustomerPayment, Records::CustomerPaymentApply, Records::CustomerPaymentCredit, Records::CustomerRefund, Records::CustomerRefundApply, Records::CustomerRefundDeposit, Records::CustomerSalesTeam, Records::CustomerStatus, Records::Deposit, Records::DepositApplication, Records::DepositCashBack, Records::DepositOther, Records::DepositPayment, Records::DescriptionItem, Records::DiscountItem, Records::Duration, Records::Employee, Records::EntityCustomField, Records::Estimate, Records::EstimateItem, Records::File, Records::Folder, Records::GiftCertRedemption, Records::GiftCertificate, Records::GiftCertificateItem, Records::InboundShipment, Records::InboundShipmentItem, Records::InterCompanyJournalEntry, Records::InterCompanyJournalEntryLine, Records::InventoryAdjustment, Records::InventoryAdjustmentInventory, Records::InventoryAssignment, Records::InventoryAssignmentList, Records::InventoryDetail, Records::InventoryItem, Records::InventoryNumber, Records::InventoryNumberLocations, Records::InventoryTransfer, Records::InventoryTransferInventory, Records::Invoice, Records::InvoiceItem, Records::ItemAvailability, Records::ItemFulfillment, Records::ItemFulfillmentItem, Records::ItemFulfillmentPackage, Records::ItemFulfillmentPackageFedEx, Records::ItemFulfillmentPackageFedExList, Records::ItemFulfillmentPackageUps, Records::ItemFulfillmentPackageUpsList, Records::ItemFulfillmentPackageUsps, Records::ItemFulfillmentPackageUspsList, Records::ItemGroup, Records::ItemMember, Records::ItemOptionCustomField, Records::ItemReceipt, Records::ItemReceiptItem, Records::ItemVendor, Records::Job, Records::JobStatus, Records::JournalEntry, Records::JournalEntryLine, Records::KitItem, Records::Location, Records::LotNumberedAssemblyItem, Records::LotNumberedInventoryItem, Records::Message, Records::NonInventoryPurchaseItem, Records::NonInventoryResaleItem, Records::NonInventorySaleItem, Records::Note, Records::NoteType, Records::NullFieldList, Records::Opportunity, Records::OpportunityItem, Records::OtherChargeSaleItem, Records::Partner, Records::PaymentItem, Records::PaymentMethod, Records::PayrollItem, Records::PhoneCall, Records::Price, Records::PriceLevel, Records::Pricing, Records::PromotionCode, Records::Promotions, Records::PurchaseOrder, Records::PurchaseOrderItem, Records::RecordRef, Records::RecordRefList, Records::ReturnAuthorization, Records::ReturnAuthorizationItem, Records::RevRecSchedule, Records::RevRecTemplate, Records::Roles, Records::SalesOrder, Records::SalesOrderItem, Records::SalesRole, Records::SalesTaxItem, Records::SerializedAssemblyItem, Records::SerializedInventoryItem, Records::SerializedInventoryItemLocation, Records::SerializedInventoryItemNumbers, Records::ServiceResaleItem, Records::ServiceSaleItem, Records::ShipAddress, Records::SiteCategory, Records::Subscription, Records::Subsidiary, Records::SubtotalItem, Records::SupportCase, Records::SupportCaseType, Records::Task, Records::TaxGroup, Records::Term, Records::TimeBill, Records::TransactionBodyCustomField, Records::TransactionColumnCustomField, Records::TransactionShipGroup, Records::TransferOrder, Records::TransferOrderItem, Records::Translation, Records::UnitsType, Records::UnitsTypeUom, Records::Vendor, Records::VendorBill, Records::VendorBillExpense, Records::VendorBillItem, Records::VendorCategory, Records::VendorCredit, Records::VendorCreditApply, Records::VendorCreditExpense, Records::VendorCreditItem, Records::VendorCurrency, Records::VendorPayment, Records::VendorPaymentApply, Records::VendorReturnAuthorization, Records::VendorReturnAuthorizationItem, Records::WorkOrder, Records::WorkOrderItem
- Defined in:
- lib/netsuite/support/records.rb
Class Method Summary collapse
Instance Method Summary collapse
- #netsuite_type ⇒ Object
- #record_type ⇒ Object
- #record_type_without_namespace ⇒ Object
- #refresh(credentials = {}) ⇒ Object
- #to_attributes!(hash, kname, v) ⇒ Object
- #to_record ⇒ Object
Methods included from Namespaces::PlatformCore
Methods included from Attributes
#attributes, #attributes=, #initialize_from_attributes_hash
Class Method Details
.netsuite_type(obj) ⇒ Object
78 79 80 |
# File 'lib/netsuite/support/records.rb', line 78 def self.netsuite_type(obj) NetSuite::Utilities::Strings.lower_camelcase(record_type_without_namespace(obj)) end |
.record_type_without_namespace(obj) ⇒ Object
82 83 84 85 |
# File 'lib/netsuite/support/records.rb', line 82 def self.record_type_without_namespace(obj) klass = obj.is_a?(Class) ? obj : obj.class "#{klass.to_s.split('::').last}" end |
Instance Method Details
#netsuite_type ⇒ Object
55 56 57 |
# File 'lib/netsuite/support/records.rb', line 55 def netsuite_type Records.netsuite_type(self) end |
#record_type ⇒ Object
51 52 53 |
# File 'lib/netsuite/support/records.rb', line 51 def record_type "#{record_namespace}:#{record_type_without_namespace}" end |
#record_type_without_namespace ⇒ Object
59 60 61 |
# File 'lib/netsuite/support/records.rb', line 59 def record_type_without_namespace Records.record_type_without_namespace(self) end |
#refresh(credentials = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/netsuite/support/records.rb', line 63 def refresh(credentials = {}) fresh_record = self.class.get(self.internal_id, credentials) self.attributes = fresh_record.send(:attributes) # gift cards do not have an external ID if fresh_record.respond_to?(:external_id) self.external_id = fresh_record.external_id end self.errors = nil self 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'] = NetSuite::Utilities::Strings.lower_camelcase(v.type) end if v.kind_of?(NetSuite::Records::CustomRecordRef) && v.type_id hash[:attributes!] ||= {} hash[:attributes!][kname] ||= {} hash[:attributes!][kname]['typeId'] = NetSuite::Utilities::Strings.lower_camelcase(v.type_id) 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) || self.class.search_only_fields.include?(k) }.inject({}) do |hash, (k,v)| kname = "#{v.is_a?(NetSuite::Records::NullFieldList) ? v.record_namespace : record_namespace}:" kname += k == :klass ? 'class' : NetSuite::Utilities::Strings.lower_camelcase(k.to_s) 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 |