Created
June 30, 2010 17:08
-
-
Save byped/458951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this method gets called on the before_save of transaction_item. | |
def apply_adjustments | |
applicable_adjustments = self.class.adjustments_to_apply[self.status.name.methodize.to_sym] || [] | |
unless applicable_adjustments.empty? | |
pairing = if [:shipping_ready, :pending].include?(self.status.name.methodize.to_sym) && self.estimated_value | |
[:estimated_value, :estimated_total=] | |
elsif [:awaiting_confirmation, :accepted].include?(self.status.name.methodize.to_sym) && | |
self.inspected_value | |
[:inspected_value, :payout_total=] | |
end | |
total_adjustment_value = 0 | |
applicable_adjustments.each do |a| | |
total_adjustment_value += (a.apply_to(self) || 0) | |
end | |
unless pairing.nil? | |
total = ('%.2f' % (self.send(pairing[0]) + total_adjustment_value)).to_f | |
self.send(pairing[1], total) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment