lib/quickbooks/base.rb
# Saves the attributes that have changed.
# 
# If the EditSequence is out of date but none of the changes conflict, the object will be saved to Quickbooks.
# But if there are conflicts, the updated values from Quickbooks will be written to the original_values, and false is returned.
# This way you can deal with the differences (conflicts), if you so desire, and simply call save again to commit your changes.
Saves the attributes that have changed.
If the EditSequence is out of date but none of the changes conflict, the object will be saved to Quickbooks.
But if there are conflicts, the updated values from Quickbooks will be written to the original_values, and false is returned.
This way you can deal with the differences (conflicts), if you so desire, and simply call save again to commit your changes.
Saves the attributes that have changed . If the EditSequence is out of date but none of the changes conflict the object will be saved to Quickbooks . But if there are conflicts the updated values from Quickbooks will be written to the original_values and false is returned . This way you can deal with the differences ( conflicts ) if you so desire and simply call save again to commit your changes .
def save
      return false unless dirty?
      self.errors.clear 
      if new_record?
        self.class.query(self, :add)
        ret = !dirty?
        @new_record = false if ret
      else
        old_originals = original_values.dup 
        ret = self.class.query(self, :mod).error? ? false : true 
        if dirty? && self.response_log.last.status == 3200 && (dirty_attributes.only(dirty_attributes(old_originals).keys).keys - self.class.read_only.stringify_values).length == (dirty_attributes(old_originals).keys - old_originals.diff(original_values).keys - self.class.read_only.stringify_values).length
          (dirty_attributes - dirty_attributes(old_originals).keys).each_key do |at|
            self.send(at + '=', original_values[at]) if respond_to?(at + '=')
          end
          ret = self.save
        end
      end
      ret.errors << self.errors if self.error?
      ret
    end
def save return false unless dirty? self . errors . clear if new_record? self . class . query ( self , :add ) ret = ! dirty? @new_record = false if ret else old_originals = original_values . dup ret = self . class . query ( self , :mod ) . error? ? false : true if dirty? && self . response_log . last . status == 3200 && ( dirty_attributes . only ( dirty_attributes ( old_originals ) . keys ) . keys - self . class . read_only . stringify_values ) . length == ( dirty_attributes ( old_originals ) . keys - old_originals . diff ( original_values ) . keys - self . class . read_only . stringify_values ) . length ( dirty_attributes - dirty_attributes ( old_originals ) . keys ) . each_key do | at | self . send ( at + '=' , original_values [ at ] ) if respond_to? ( at + '=' ) end ret = self . save end end ret . errors << self . errors if self . error? ret end
Saves the attributes that have changed.
Saves the attributes that have changed .
# Clear out any errors: start with a clean slate! # Smart system that respects EditSequences and other people's changes. # 1) Try to save # 2) When we get a status of 3200, that means our EditSequence is not up to date # 3) Replace self's original_attributes with those just retrieved, and update the automatic attributes, like EditSequence and TimeModified # 4) Return false, return the object dirty but ready to save # Save the old_originals so we can detect any attributes that changed since we last loaded the object # Saves if possible, if EditSequence is out of date, it will read the up-to-date object into original_values # If save failed (dirty?) because of old record (status 3200), but none of the fields conflict (attributes I've modified and are still different aren't the same attributes as any of the attributes someone else updated), then re-save! # 'Revert' fields I didn't modify to equal the values of the more up-to-date record just loaded. # Fields I didn't modify: dirty_attributes - dirty_attributes(old_originals).keys # ret should be a false value if self has errors. Either way, ret gets the errors too. # Should be true or false with an error attached.