Last active
December 21, 2015 20:59
-
-
Save msevestre/6365472 to your computer and use it in GitHub Desktop.
Eligible promotions are excluded from tax
Warning: Only works if you have one Tax category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_dependency 'spree/calculator' | |
module Spree | |
class Calculator::CanadianTax < Calculator::DefaultTax | |
def self.description | |
"Canadian tax (Eligible promotions are excluded from tax)" | |
end | |
private | |
def compute_order(order) | |
matched_line_items = order.line_items.select do |line_item| | |
line_item.product.tax_category == rate.tax_category | |
end | |
line_items_total = matched_line_items.sum(&:total) | |
#This returns a negative amount! | |
promotion_adjustments_total = order.adjustments.eligible.promotion.sum(&:amount) | |
total = promotion_adjustments_total + line_items_total | |
round_to_two_places(total * rate.amount) | |
end | |
#def compute_order(order) | |
# matched_line_items = order.line_items.select do |line_item| | |
# line_item.product.tax_category == rate.tax_category | |
# end | |
# | |
# line_items_total = matched_line_items.sum(&:total) | |
# round_to_two_places(line_items_total * rate.amount) | |
#end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment