Extract order total tax calculations to model

This commit is contained in:
Rohan Mitchell
2015-03-25 16:14:46 +11:00
parent 84f3097217
commit 89d4a59e9d
3 changed files with 22 additions and 1 deletions

View File

@@ -206,6 +206,9 @@ Spree::Order.class_eval do
adjustments(:reload).enterprise_fee.sum(&:included_tax)
end
def total_tax
(adjustments + price_adjustments).sum &:included_tax
end
# Overrride of Spree method, that allows us to send separate confirmation emails to user and shop owners
def deliver_order_confirmation_email

View File

@@ -18,7 +18,7 @@ module OpenFoodNetwork
shipping_cost = shipping_cost_for order
shipping_tax = order.shipping_tax
enterprise_fee_tax = order.enterprise_fee_tax
total_tax = (order.adjustments + order.price_adjustments).sum(&:included_tax)
total_tax = order.total_tax
[order.number, order.created_at, totals[:items], totals[:items_total],
totals[:taxable_total], totals[:sales_tax], shipping_cost, shipping_tax, enterprise_fee_tax, total_tax,

View File

@@ -219,6 +219,24 @@ describe Spree::Order do
end
end
describe "getting the total tax" do
let(:order) { create(:order, shipping_method: shipping_method) }
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) }
let(:enterprise_fee) { create(:enterprise_fee) }
let!(:adjustment) { create(:adjustment, adjustable: order, originator: enterprise_fee, label: "EF", amount: 123, included_tax: 2) }
before do
Spree::Config.shipment_inc_vat = true
Spree::Config.shipping_tax_rate = 0.25
order.create_shipment!
order.reload
end
it "returns a sum of all tax on the order" do
order.total_tax.should == 12
end
end
describe "setting the distributor" do
it "sets the distributor when no order cycle is set" do
d = create(:distributor_enterprise)