Add line item included_tax_amount method to multiply by quantity

This commit is contained in:
Steve Pettitt
2016-05-14 11:00:13 +01:00
parent 3a813cb612
commit 547fcf49e0
3 changed files with 21 additions and 3 deletions

View File

@@ -56,6 +56,6 @@ class ProducerMailer < Spree::BaseMailer
end
def tax_total_from_line_items(aggregated_line_items)
Spree::Money.new aggregated_line_items.values.map(&:included_tax).sum
Spree::Money.new aggregated_line_items.values.map(&:included_tax_amount).sum
end
end

View File

@@ -52,10 +52,15 @@ Spree::LineItem.class_eval do
adjustments.included_tax.any?
end
# Single
def included_tax
adjustments.included_tax.sum(&:included_tax)
end
def included_tax_amount
included_tax * quantity
end
def price_with_adjustments
# EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
# so line_item.adjustments returns an empty array
@@ -77,8 +82,12 @@ Spree::LineItem.class_eval do
Spree::Money.new(amount_with_adjustments, { :currency => currency })
end
def display_included_tax
Spree::Money.new(included_tax, { :currency => currency })
def display_included_tax_amount
Spree::Money.new(included_tax_amount, { :currency => currency })
end
def display_amount_without_tax
Spree::Money.new(amount_with_adjustments - included_tax_amount, { currency: currency })
end
def display_name

View File

@@ -124,6 +124,15 @@ module Spree
expect(li_no_tax.included_tax).to eq 0.00
end
end
context "scaling included tax by quantity" do
it "multiplies included_tax" do
li_tax.quantity = 3
li_tax.save
expect(li_tax.included_tax).to eq 10.00
expect(li_tax.included_tax_amount).to eq 30.00
end
end
end
describe "unit value/description" do