Method: Spree::TaxRate.store_pre_tax_amount

Defined in:
app/models/spree/tax_rate.rb

.store_pre_tax_amount(item, rates) ⇒ Object

Pre-tax amounts must be stored so that we can calculate correct rate amounts in the future. For example: github.com/spree/spree/issues/4318#issuecomment-34723428



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/spree/tax_rate.rb', line 60

def self.store_pre_tax_amount(item, rates)
  if rates.any? { |r| r.included_in_price }
    case item
    when Spree::LineItem
      item_amount = item.discounted_amount
    when Spree::Shipment
      item_amount = item.discounted_cost
    end
    pre_tax_amount = item_amount / (1 + rates.map(&:amount).sum)
    item.update_column(:pre_tax_amount, pre_tax_amount)
  end
end