Class: Spree::OrderTaxation
- Inherits:
-
Object
- Object
- Spree::OrderTaxation
- Defined in:
- app/models/spree/order_taxation.rb
Overview
Relatively simple class used to apply a Tax::OrderTax to a Order.
This class will create or update adjustments on the taxed items and remove any now inapplicable tax adjustments from the order.
Instance Method Summary collapse
-
#apply(taxes) ⇒ void
Apply taxes to the order.
-
#initialize(order) ⇒ Spree::OrderTaxation
constructor
Create a new order taxation.
Constructor Details
#initialize(order) ⇒ Spree::OrderTaxation
Create a new order taxation.
14 15 16 |
# File 'app/models/spree/order_taxation.rb', line 14 def initialize(order) @order = order end |
Instance Method Details
#apply(taxes) ⇒ void
This method returns an undefined value.
Apply taxes to the order.
This method will create or update adjustments on the order and all line items and shipments in the order to reflect the appropriate taxes passed in. It will also remove any now inapplicable tax adjustments.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/spree/order_taxation.rb', line 26 def apply(taxes) update_adjustments(@order, taxes.order_taxes) if taxes.order_taxes @order.line_items.each do |item| taxed_items = taxes.line_item_taxes.select { |element| element.item_id == item.id } update_adjustments(item, taxed_items) end @order.shipments.each do |item| taxed_items = taxes.shipment_taxes.select { |element| element.item_id == item.id } update_adjustments(item, taxed_items) end end |