Skip to content

Instantly share code, notes, and snippets.

@byped
Created June 30, 2010 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byped/458953 to your computer and use it in GitHub Desktop.
Save byped/458953 to your computer and use it in GitHub Desktop.
def apply_adjustments
adjustments = self.class.adjustments_to_apply[self.status.name.methodize.to_sym] || []
return if adjustments.empty?
total_adjustment = adjustments.inject(0.0){ |total,adjust| total + adjust.apply_to(self).to_f }
return if total_adjustment == 0.0
case self.status.name.methodize.to_sym
when :shipping_ready, :pending
self.estimated_total = ('%.2f' % (self.estimated_total + total_adjustment)).to_f if self.estimated_value
when :awaiting_confirmation, :accepted
self.payout_total = ('%.2f' % (self.inspected_value + total_adjustment)).to_f if self.inspected_value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment