Define DefaultTax calculator outside of spree namespace the tax_rate to be used by the app and make spree specs use calculators outside the spree namespace

This commit is contained in:
Luis Ramos
2020-06-16 17:25:21 +01:00
parent 6a94168ee5
commit f62546254f
3 changed files with 15 additions and 10 deletions

View File

@@ -66,6 +66,7 @@ module Openfoodnetwork
Calculator::PriceSack,
Calculator::Weight
]
app.config.spree.calculators.add_class('payment_methods')
config.spree.calculators.payment_methods = [
Calculator::FlatPercentItemTotal,
@@ -74,6 +75,11 @@ module Openfoodnetwork
Calculator::PerItem,
Calculator::PriceSack
]
app.config.spree.calculators.add_class('tax_rates')
config.spree.calculators.tax_rates = [
Calculator::DefaultTax
]
end
# Register Spree payment methods

View File

@@ -127,7 +127,7 @@ module Spree
describe "EnterpriseFee adjustments" do
let(:zone) { create(:zone_with_member) }
let(:fee_tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
let(:fee_tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) }
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
@@ -143,7 +143,7 @@ module Spree
end
context "when enterprise fees are taxed per-order" do
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) }
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do
@@ -181,7 +181,7 @@ module Spree
end
context "when enterprise fees are taxed per-item" do
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: Calculator::PerItem.new(preferred_amount: 50.0)) }
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do
@@ -205,7 +205,7 @@ module Spree
end
context "when enterprise fees inherit their tax_category from the product they are applied to" do
let(:product_tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.2) }
let(:product_tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.2) }
let(:product_tax_category) { create(:tax_category, tax_rates: [product_tax_rate]) }
before do
@@ -216,7 +216,7 @@ module Spree
end
context "when enterprise fees are taxed per-order" do
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) }
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records no tax on the enterprise fee adjustments" do
@@ -246,7 +246,7 @@ module Spree
end
context "when enterprise fees are taxed per-item" do
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: Calculator::PerItem.new(preferred_amount: 50.0)) }
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do

View File

@@ -136,12 +136,11 @@ module Spree
context "when order-based calculator" do
let!(:shop) { create(:enterprise) }
let!(:payment_method) { create(:payment_method, calculator: calculator) }
let!(:calculator) do
Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
end
context "when order complete and inventory tracking enabled" do
context "when order complete" do
let!(:order) { create(:completed_order_with_totals, distributor: shop) }
let!(:variant) { order.line_items.first.variant }
let!(:inventory_item) { create(:inventory_item, enterprise: shop, variant: variant) }
@@ -159,7 +158,7 @@ module Spree
let(:shop) { create(:enterprise) }
let(:payment_method) { create(:stripe_payment_method, distributor_ids: [create(:distributor_enterprise).id], preferred_enterprise_id: shop.id) }
let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) }
let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
before do
payment_method.calculator = calculator