Method: LineItem#applicable_tax_rate
- Defined in:
- lib/forge/app/models/line_item.rb
#applicable_tax_rate(billing_address) ⇒ Object
collect all of the applicable tax rates based on where the person purchasing it is located, then enumerate through them and add up their rates
25 26 27 28 29 30 31 |
# File 'lib/forge/app/models/line_item.rb', line 25 def applicable_tax_rate(billing_address) raise "billing address must be an Address" unless billing_address.kind_of? Address applicable_tax_rates = self.product.tax_rates.where(country_id: billing_address.country_id).to_a applicable_tax_rates += self.product.tax_rates.where(province_id: billing_address.province_id).to_a if billing_address.province_id # use uniq to ensure we don't charge tax too many times - it's possible to get overlapping rates between a country and its provinces applicable_tax_rates.uniq.inject(0.0) { |sum, applicable_tax_rate| sum += applicable_tax_rate.rate } end |