lib/netsuite/support/records.rb in netsuite-0.8.11 vs lib/netsuite/support/records.rb in netsuite-0.8.12

- old
+ new

@@ -4,12 +4,12 @@ include Attributes include Namespaces::PlatformCore 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 = "#{record_namespace}:" - kname += k == :klass ? 'class' : k.to_s.lower_camelcase + 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 } @@ -36,30 +36,30 @@ end if v.kind_of?(NetSuite::Records::RecordRef) && v.type hash[:attributes!] ||= {} hash[:attributes!][kname] ||= {} - hash[:attributes!][kname]['type'] = v.type.lower_camelcase + 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'] = v.type_id.lower_camelcase + hash[:attributes!][kname]['typeId'] = NetSuite::Utilities::Strings.lower_camelcase(v.type_id) end end def record_type "#{record_namespace}:#{record_type_without_namespace}" end def netsuite_type - record_type_without_namespace.lower_camelcase + Records.netsuite_type(self) end def record_type_without_namespace - "#{self.class.to_s.split('::').last}" + Records.record_type_without_namespace(self) end def refresh(credentials = {}) fresh_record = self.class.get(self.internal_id, credentials) @@ -71,9 +71,18 @@ end self.errors = nil self + end + + def self.netsuite_type(obj) + NetSuite::Utilities::Strings.lower_camelcase(record_type_without_namespace(obj)) + end + + def self.record_type_without_namespace(obj) + klass = obj.is_a?(Class) ? obj : obj.class + "#{klass.to_s.split('::').last}" end end end end