app/models/order.rb
## TODO: this doesn't pass errors up to the caller.. does it need to?
this doesn't pass errors up to the caller..
this doesn ' t pass errors up to the caller ..
def update_details(order_detail_updates)
    order_details_to_update = order_detail_updates.keys.map(&:to_i)
    selected_order_details = self.order_details.select { |od| od.id.in?(order_details_to_update) }
    selected_order_details.each do |order_detail|
      updates = order_detail_updates[order_detail.id]
      quantity = updates[:quantity].present? ? updates[:quantity].to_i : order_detail.quantity
      if quantity == 0 && !order_detail.bundled?
        order_detail.destroy
        next
      end
      unless order_detail.update(updates)
        logger.debug "errors on #{order_detail.id}"
        order_detail.errors.each do |attr, error|
          logger.debug "#{attr} #{error}"
          errors.add attr, error
        end
        next
      end
      order_detail.assign_estimated_price if order_detail.cost_estimated?
      order_detail.save
    end
    errors.empty?
  end
def update_details ( order_detail_updates ) order_details_to_update = order_detail_updates . keys . map ( & :to_i ) selected_order_details = self . order_details . select { | od | od . id . in? ( order_details_to_update ) } selected_order_details . each do | order_detail | updates = order_detail_updates [ order_detail . id ] quantity = updates [ :quantity ] . present? ? updates [ :quantity ] . to_i : order_detail . quantity if quantity == 0 && ! order_detail . bundled? order_detail . destroy next end unless order_detail . update ( updates ) logger . debug "errors on #{order_detail.id}" order_detail . errors . each do | attr , error | logger . debug "#{attr} #{error}" errors . add attr , error end next end order_detail . assign_estimated_price if order_detail . cost_estimated? order_detail . save end errors . empty? end
TODO: this doesn't pass errors up to the caller.. does it need to?
TODO : this doesn ' t pass errors up to the caller .. does it need to?
# reset quantity (if present) # if quantity isn't there or is 0 (and not bundled), destroy and skip
order_detail_updates
<not_specific>