Permalink
Browse files

removed any uses of update_totals! that shouldn't be necessary and di…

…sabled bits of logic that are supposed to ensure correct order state as this logic will be consolidated into the Order model
  • Loading branch information...
davidnorth committed Aug 13, 2010
1 parent e52f814 commit c819356a96df59dcf6a1348fd87bd9d307822876
@@ -10,9 +10,6 @@ class Admin::AdjustmentsController < Admin::BaseController
destroy.success.wants.js { render_js_for_destroy }
create.before :set_type
- create.after :set_order_state
- update.after :set_order_state
- destroy.after :set_order_state
private
def list_adjustment_types
@@ -28,18 +25,19 @@ def set_type
object.type = params[:adjustment][:type]
end
+ # TODO: refactor into Order class
# Automatically complete and order where no payment is necessary because adjustments cancel out the total
- def set_order_state
- @order.update_totals!
-
- if @order.in_progress? and @order.item_total > 0 and @order.total == 0 and @order.payments.total == 0 #for new orders that are adjusted to zero
- until @order.checkout.complete?
- @order.checkout.next!
- end
- @order.reload.pay!
- elsif @order.item_total > 0 && ((@order.balance_due? && @order.outstanding_balance == 0) || (@order.credit_owed? && @order.outstanding_credit == 0)) #set existing orders back to paid, if adjustment corrects balance
- @order.reload.pay!
- end
- end
+ # def set_order_state
+ # @order.update_totals!
+
+ # if @order.in_progress? and @order.item_total > 0 and @order.total == 0 and @order.payments.total == 0 #for new orders that are adjusted to zero
+ # until @order.checkout.complete?
+ # @order.checkout.next!
+ # end
+ # @order.reload.pay!
+ # elsif @order.item_total > 0 && ((@order.balance_due? && @order.outstanding_balance == 0) || (@order.credit_owed? && @order.outstanding_credit == 0)) #set existing orders back to paid, if adjustment corrects balance
+ # @order.reload.pay!
+ # end
+ # end
end
@@ -43,26 +43,27 @@ def create
update.success.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order}, :layout => false}
update.failure.wants.html { render :partial => "admin/orders/form", :locals => {:order => @order}, :layout => false}
- destroy.after :recalulate_totals
- update.after :recalulate_totals
- create.after :recalulate_totals
+ # destroy.after :recalulate_totals
+ # update.after :recalulate_totals
+ # create.after :recalulate_totals
private
- def recalulate_totals
- unless @order.shipping_method.nil?
- @order.shipping_charges.each do |shipping_charge|
- shipping_charge.update_attributes(:amount => @order.shipping_method.calculate_cost(@order.shipment))
- end
- end
+ # TODO: Order model should look after this
+ # def recalulate_totals
+ # unless @order.shipping_method.nil?
+ # @order.shipping_charges.each do |shipping_charge|
+ # shipping_charge.update_attributes(:amount => @order.shipping_method.calculate_cost(@order.shipment))
+ # end
+ # end
- @order.tax_charges.each do |tax_charge|
- tax_charge.update_attributes(:amount => tax_charge.calculate_tax_charge)
- end
+ # @order.tax_charges.each do |tax_charge|
+ # tax_charge.update_attributes(:amount => tax_charge.calculate_tax_charge)
+ # end
- @order.update_totals!
+ # @order.update_totals!
- unless @order.in_progress?
- InventoryUnit.adjust_units(@order)
- end
- end
+ # unless @order.in_progress?
+ # InventoryUnit.adjust_units(@order)
+ # end
+ # end
end
@@ -87,7 +87,6 @@ def ensure_line_items
load_object
if @order.line_items.empty?
@order.errors.add(:line_items, t('errors.messages.blank'))
- @order.update_totals
render :edit
end
end
@@ -86,9 +86,7 @@ def recalculate_needed?
def recalculate_order
shipping_charge.update_attribute(:description, description_for_shipping_charge)
- order.update_adjustments
order.update_totals!
- order.save
end
private
@@ -129,4 +127,4 @@ def release_inventory_units
inventory_units.each {|unit| unit.update_attribute(:shipment_id, nil)}
end
-end
+end
@@ -82,7 +82,6 @@ def void(payment)
:txn_type => CreditcardTxn::TxnType::VOID
)
payment.update_attribute(:amount, 0.00)
- payment.order.update_totals!
payment.finalize!
end
@@ -106,7 +105,6 @@ def credit(payment, amount=nil)
:txn_type => CreditcardTxn::TxnType::CREDIT
)
payment.update_attribute(:amount, payment.amount - amount)
- payment.order.update_totals!
rescue ActiveMerchant::ConnectionError => e
gateway_error I18n.t(:unable_to_connect_to_gateway)
end

0 comments on commit c819356

Please sign in to comment.