Update line_item included taxes

Drops use of the `spree_adjustments.included_tax` database field (when summing line item tax), which we are slowly deprecating before eventual removal
This commit is contained in:
Matt-Yorkley
2021-02-28 10:48:28 +00:00
parent 3a5f763bf2
commit 064f7582cc
7 changed files with 16 additions and 11 deletions

View File

@@ -174,11 +174,11 @@ module Spree
end
def has_tax?
adjustments.included_tax.any?
adjustments.tax.any?
end
def included_tax
adjustments.included_tax.sum(:included_tax)
adjustments.tax.inclusive.sum(:amount)
end
def tax_rates

View File

@@ -662,7 +662,9 @@ module Spree
end
def total_tax
all_adjustments.sum(:included_tax)
adjustments.sum(:included_tax) +
shipment_adjustments.sum(:included_tax) +
line_item_adjustments.tax.sum(:amount)
end
def has_taxes_included

View File

@@ -84,7 +84,7 @@ module Spree
order.line_items.reload
# TaxRate adjustments (order.adjustments.tax)
# and line item adjustments (tax included on line items) consist of 100% tax
(order.adjustments.tax + order.line_item_adjustments.reload).each do |adjustment|
order.adjustments.tax.additional.each do |adjustment|
adjustment.set_absolute_included_tax! adjustment.amount
end
end

View File

@@ -59,7 +59,7 @@ module OrderManagement
def update_adjustment_total
order.adjustment_total = all_adjustments.additional.eligible.sum(:amount)
order.additional_tax_total = all_adjustments.tax.additional.sum(:amount)
order.included_tax_total = order.line_item_adjustments.tax.sum(:included_tax) +
order.included_tax_total = order.line_item_adjustments.tax.inclusive.sum(:amount) +
all_adjustments.enterprise_fee.sum(:included_tax) +
all_adjustments.shipping.sum(:included_tax) +
adjustments.admin.sum(:included_tax)

View File

@@ -100,7 +100,7 @@ module OpenFoodNetwork
end
def tax_included_in(line_item)
line_item.adjustments.sum(:included_tax)
line_item.adjustments.tax.inclusive.sum(:amount)
end
def shipment_inc_vat

View File

@@ -185,9 +185,9 @@ module Spree
tax_rate.adjust(order)
end
it "has 100% tax included" do
it "has tax included" do
expect(adjustment.amount).to be > 0
expect(adjustment.included_tax).to eq(adjustment.amount)
expect(adjustment.included).to be true
end
it "does not crash when order data has been updated previously" do
@@ -365,7 +365,7 @@ module Spree
# so tax on the enterprise_fee adjustment will be 0
# Tax on line item is: 0.2/1.2 x $10 = $1.67
expect(adjustment.included_tax).to eq(0.0)
expect(line_item.adjustments.first.included_tax).to eq(1.67)
expect(line_item.adjustments.tax.first.amount).to eq(1.67)
end
end
@@ -395,7 +395,7 @@ module Spree
# gives tax on fee of 0.2/1.2 x $50 = $8.33
# Tax on line item is: 0.2/1.2 x $10 = $1.67
expect(adjustment.included_tax).to eq(8.33)
expect(line_item.adjustments.first.included_tax).to eq(1.67)
expect(line_item.adjustments.tax.first.amount).to eq(1.67)
end
end

View File

@@ -443,7 +443,10 @@ module Spree
let(:li_no_tax) { create(:line_item) }
let(:li_tax) { create(:line_item) }
let(:tax_rate) { create(:tax_rate, calculator: ::Calculator::DefaultTax.new) }
let!(:adjustment) { create(:adjustment, adjustable: li_tax, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
let!(:adjustment) {
create(:adjustment, adjustable: li_tax, originator: tax_rate, label: "TR",
amount: 10.00, included: true)
}
context "checking if a line item has tax included" do
it "returns true when it does" do