Class: Spree::Calculator::DefaultTax
- Inherits:
-
Spree::Calculator
- Object
- ActiveRecord::Base
- Base
- Spree::Calculator
- Spree::Calculator::DefaultTax
- Includes:
- Tax::TaxHelpers
- Defined in:
- app/models/spree/calculator/default_tax.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#compute_item(item) ⇒ Object
(also: #compute_shipment, #compute_line_item, #compute_shipping_rate)
When it comes to computing shipments or line items: same same.
-
#compute_order(order) ⇒ Object
Default tax calculator still needs to support orders for legacy reasons Orders created before Spree 2.1 had tax adjustments applied to the order, as a whole.
Methods inherited from Spree::Calculator
#available?, calculators, #compute, #description, register, #to_s
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
Methods included from Preferences::Preferable
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.description ⇒ Object
7 8 9 |
# File 'app/models/spree/calculator/default_tax.rb', line 7 def self.description Spree.t(:default_tax) end |
Instance Method Details
#compute_item(item) ⇒ Object Also known as: compute_shipment, compute_line_item, compute_shipping_rate
When it comes to computing shipments or line items: same same.
29 30 31 32 33 34 35 |
# File 'app/models/spree/calculator/default_tax.rb', line 29 def compute_item(item) if rate.included_in_price deduced_total_by_rate(item, rate) else round_to_two_places(item.discounted_amount * rate.amount) end end |
#compute_order(order) ⇒ Object
Default tax calculator still needs to support orders for legacy reasons Orders created before Spree 2.1 had tax adjustments applied to the order, as a whole. Orders created with Spree 2.2 and after, have them applied to the line items individually.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/spree/calculator/default_tax.rb', line 14 def compute_order(order) matched_line_items = order.line_items.select do |line_item| line_item.tax_category == rate.tax_category end line_items_total = matched_line_items.sum(&:discounted_amount) if rate.included_in_price order_tax_amount = round_to_two_places(line_items_total - ( line_items_total / (1 + rate.amount) ) ) refund_if_necessary(order_tax_amount, order.tax_zone) else round_to_two_places(line_items_total * rate.amount) end end |