Class: Spree::Calculator::DefaultTax
- Inherits:
-
Spree::Calculator
- Object
- ApplicationRecord
- Base
- Spree::Calculator
- Spree::Calculator::DefaultTax
- Includes:
- VatPriceCalculation
- Defined in:
- app/models/spree/calculator/default_tax.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#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.
-
#compute_shipment_or_line_item(item) ⇒ Object
(also: #compute_shipment, #compute_line_item)
When it comes to computing shipments or line items: same same.
- #compute_shipping_rate(shipping_rate) ⇒ Object
Methods included from VatPriceCalculation
Methods inherited from Spree::Calculator
#available?, calculators, #compute, #description, #to_s
Methods inherited from Base
belongs_to_required_by_default, page, spree_base_scopes
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.description ⇒ Object
6 7 8 |
# File 'app/models/spree/calculator/default_tax.rb', line 6 def self.description Spree.t(:default_tax) end |
Instance Method Details
#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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/spree/calculator/default_tax.rb', line 13 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(&:total) if rate.included_in_price round_to_two_places(line_items_total - (line_items_total / (1 + rate.amount))) else round_to_two_places(line_items_total * rate.amount) end end |
#compute_shipment_or_line_item(item) ⇒ Object Also known as: compute_shipment, compute_line_item
When it comes to computing shipments or line items: same same.
27 28 29 30 31 32 33 |
# File 'app/models/spree/calculator/default_tax.rb', line 27 def compute_shipment_or_line_item(item) if rate.included_in_price deduced_total_by_rate(item.pre_tax_amount, rate) else round_to_two_places(item.discounted_amount * rate.amount) end end |
#compute_shipping_rate(shipping_rate) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/models/spree/calculator/default_tax.rb', line 38 def compute_shipping_rate(shipping_rate) if rate.included_in_price pre_tax_amount = shipping_rate.cost / (1 + rate.amount) deduced_total_by_rate(pre_tax_amount, rate) else with_tax_amount = shipping_rate.cost * rate.amount round_to_two_places(with_tax_amount) end end |