Create a "None" calculator for shipping and payment methods

Only for payment and shipping methods
This commit is contained in:
Jean-Baptiste Bellet
2022-12-26 15:47:43 +01:00
parent c96bba8094
commit a793fc9f99
4 changed files with 34 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: false
module Calculator
class None < Spree::Calculator
def self.description
I18n.t(:none)
end
def compute(_object = nil)
0
end
end
end

View File

@@ -116,7 +116,8 @@ module Openfoodnetwork
Calculator::FlexiRate,
Calculator::PerItem,
Calculator::PriceSack,
Calculator::Weight
Calculator::Weight,
Calculator::None
]
app.config.spree.calculators.add_class('enterprise_fees')
@@ -135,7 +136,8 @@ module Openfoodnetwork
Calculator::FlatRate,
Calculator::FlexiRate,
Calculator::PerItem,
Calculator::PriceSack
Calculator::PriceSack,
Calculator::None
]
app.config.spree.calculators.add_class('tax_rates')

View File

@@ -251,6 +251,14 @@ describe '
let!(:payment_method) { create(:payment_method, calculator: calculator) }
before { login_as_admin_and_visit spree.edit_admin_payment_method_path payment_method }
it "handle the 'None' calculator" do
select2_select "None", from: 'calc_type'
click_button 'Update'
expect(page).to have_content("Payment Method has been successfully updated!")
expect(payment_method.reload.calculator_type).to eq "Calculator::None"
expect(page).to have_select "calc_type", selected: "None"
end
context "using Flat Percent calculator" do
before { select2_select "Flat Percent", from: 'calc_type' }

View File

@@ -83,6 +83,15 @@ describe 'shipping methods' do
expect(@shipping_method.reload.calculator_type).to eq("Calculator::PerItem")
end
it "handle when updating calculator type to 'None'" do
visit spree.edit_admin_shipping_method_path(@shipping_method)
select2_select 'None', from: 'calc_type'
click_button 'Update'
expect(@shipping_method.reload.calculator_type).to eq "Calculator::None"
end
end
context "as an enterprise user", js: true do