Module: NetSuiteRails::RecordSync::InstanceMethods
- Defined in:
- lib/netsuite_rails/record_sync.rb
Instance Attribute Summary collapse
-
#netsuite_manual_fields ⇒ Object
Returns the value of attribute netsuite_manual_fields.
Instance Method Summary collapse
- #netsuite_custom_record? ⇒ Boolean
-
#netsuite_execute_callbacks(list, record) ⇒ Object
TODO this should be protected; it needs to be pushed down to the Push/Pull manager level.
- #netsuite_extract_from_record(netsuite_record) ⇒ Object
- #netsuite_field_hints ⇒ Object
- #netsuite_field_map ⇒ Object
- #netsuite_pull ⇒ Object
- #netsuite_pull_record ⇒ Object
- #netsuite_pulled? ⇒ Boolean
-
#netsuite_pulling? ⇒ Boolean
assumes netsuite_id field on activerecord.
- #netsuite_push(opts = {}) ⇒ Object
- #netsuite_record_class ⇒ Object
- #netsuite_sync ⇒ Object
-
#netsuite_sync_options ⇒ Object
these methods are here for easy model override.
- #new_netsuite_record? ⇒ Boolean
Instance Attribute Details
#netsuite_manual_fields ⇒ Object
Returns the value of attribute netsuite_manual_fields.
99 100 101 |
# File 'lib/netsuite_rails/record_sync.rb', line 99 def netsuite_manual_fields @netsuite_manual_fields end |
Instance Method Details
#netsuite_custom_record? ⇒ Boolean
218 219 220 |
# File 'lib/netsuite_rails/record_sync.rb', line 218 def netsuite_custom_record? self.netsuite_record_class == NetSuite::Records::CustomRecord end |
#netsuite_execute_callbacks(list, record) ⇒ Object
TODO this should be protected; it needs to be pushed down to the Push/Pull manager level
224 225 226 227 228 229 230 231 232 |
# File 'lib/netsuite_rails/record_sync.rb', line 224 def netsuite_execute_callbacks(list, record) list.each do |callback| if callback.is_a?(Symbol) self.send(callback, record) else instance_exec(record, &callback) end end end |
#netsuite_extract_from_record(netsuite_record) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/netsuite_rails/record_sync.rb', line 152 def netsuite_extract_from_record(netsuite_record) @netsuite_pulling = true field_hints = self.netsuite_field_hints custom_field_list = self.netsuite_field_map[:custom_field_list] || {} all_field_list = self.netsuite_field_map.except(:custom_field_list) || {} all_field_list.merge!(custom_field_list) # self.netsuite_normalize_datetimes(:pull) # handle non-collection associations association_keys = self.reflections.values.reject(&:collection?).map(&:name) all_field_list.each do |local_field, netsuite_field| is_custom_field = custom_field_list.keys.include?(local_field) if netsuite_field.is_a?(Proc) netsuite_field.call(self, netsuite_record, :pull) next end field_value = if is_custom_field netsuite_record.custom_field_list.send(netsuite_field).value rescue "" else netsuite_record.send(netsuite_field) end if field_value.blank? # TODO possibly nil out the local value? next end if association_keys.include?(local_field) field_value = self.reflections[local_field].klass.where(netsuite_id: field_value.internal_id).first_or_initialize elsif is_custom_field field_value = NetSuiteRails::RecordSync::PullManager.extract_custom_field_value(field_value) else # then it's not a custom field end # TODO should we just check for nil? vs present? # TODO should be moved to Transformations with a direction flag if field_hints.has_key?(local_field) && field_value.present? case field_hints[local_field] when :datetime field_value = field_value.change(offset: "00:00") - (Time.zone.utc_offset / 3600).hours + (8 + NetSuiteRails::Configuration.netsuite_instance_time_zone_offset).hours end end self.send(:"#{local_field}=", field_value) end netsuite_execute_callbacks(self.class.after_netsuite_pull, netsuite_record) @netsuite_pulling = false @netsuite_pulled = true end |
#netsuite_field_hints ⇒ Object
119 120 121 |
# File 'lib/netsuite_rails/record_sync.rb', line 119 def netsuite_field_hints self.class.netsuite_field_hints end |
#netsuite_field_map ⇒ Object
115 116 117 |
# File 'lib/netsuite_rails/record_sync.rb', line 115 def netsuite_field_map self.class.netsuite_field_map end |
#netsuite_pull ⇒ Object
133 134 135 |
# File 'lib/netsuite_rails/record_sync.rb', line 133 def netsuite_pull netsuite_extract_from_record(netsuite_pull_record) end |
#netsuite_pull_record ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/netsuite_rails/record_sync.rb', line 137 def netsuite_pull_record if netsuite_custom_record? NetSuite::Records::CustomRecord.get( internal_id: self.netsuite_id, type_id: self.class.netsuite_custom_record_type_id ) else self.netsuite_record_class.get(self.netsuite_id) end end |
#netsuite_pulled? ⇒ Boolean
129 130 131 |
# File 'lib/netsuite_rails/record_sync.rb', line 129 def netsuite_pulled? @netsuite_pulled ||= false end |
#netsuite_pulling? ⇒ Boolean
assumes netsuite_id field on activerecord
125 126 127 |
# File 'lib/netsuite_rails/record_sync.rb', line 125 def netsuite_pulling? @netsuite_pulling ||= false end |
#netsuite_push(opts = {}) ⇒ Object
148 149 150 |
# File 'lib/netsuite_rails/record_sync.rb', line 148 def netsuite_push(opts = {}) NetSuiteRails::RecordSync::PushManager.push(self, opts) end |
#netsuite_record_class ⇒ Object
111 112 113 |
# File 'lib/netsuite_rails/record_sync.rb', line 111 def netsuite_record_class self.class.netsuite_record_class end |
#netsuite_sync ⇒ Object
107 108 109 |
# File 'lib/netsuite_rails/record_sync.rb', line 107 def netsuite_sync self.class.netsuite_sync end |
#netsuite_sync_options ⇒ Object
these methods are here for easy model override
103 104 105 |
# File 'lib/netsuite_rails/record_sync.rb', line 103 def self.class. end |
#new_netsuite_record? ⇒ Boolean
214 215 216 |
# File 'lib/netsuite_rails/record_sync.rb', line 214 def new_netsuite_record? self.netsuite_id.blank? end |