mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add line item included_tax_amount method to multiply by quantity
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user