From f62546254fa82fc7f7482d0b9abb2f58d05a9c86 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 16 Jun 2020 17:25:21 +0100 Subject: [PATCH] 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 --- config/application.rb | 6 ++++++ spec/models/spree/adjustment_spec.rb | 12 ++++++------ spec/models/spree/payment_spec.rb | 7 +++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config/application.rb b/config/application.rb index 3860b0b928..3d061b97be 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 57047457ac..0ea3eea273 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -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 diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index eb148a736c..1ca723566c 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -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