mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding configurable Shop Trial Length in business model
This commit is contained in:
@@ -18,8 +18,9 @@ class Admin::BusinessModelConfigurationController < Spree::Admin::BaseController
|
||||
|
||||
def load_settings
|
||||
@settings = OpenFoodNetwork::BusinessModelConfigurationValidator.new(params[:settings] || {
|
||||
shop_trial_length_days: Spree::Config[:shop_trial_length_days],
|
||||
account_invoices_monthly_fixed: Spree::Config[:account_invoices_monthly_fixed],
|
||||
account_invoices_monthly_rate: Spree::Config[:account_invoices_monthly_rate],
|
||||
account_invoiceaccount_invoices_monthly_rates_monthly_rate: Spree::Config[:account_invoices_monthly_rate],
|
||||
account_invoices_monthly_cap: Spree::Config[:account_invoices_monthly_cap],
|
||||
account_invoices_tax_rate: Spree::Config[:account_invoices_tax_rate]
|
||||
})
|
||||
|
||||
@@ -48,17 +48,17 @@ module EnterprisesHelper
|
||||
|
||||
def shop_trial_in_progress?(enterprise)
|
||||
!!enterprise.shop_trial_start_date &&
|
||||
(enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days > Time.zone.now) &&
|
||||
(enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days > Time.zone.now) &&
|
||||
%w(own any).include?(enterprise.sells)
|
||||
end
|
||||
|
||||
def shop_trial_expired?(enterprise)
|
||||
!!enterprise.shop_trial_start_date &&
|
||||
(enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days <= Time.zone.now) &&
|
||||
(enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days <= Time.zone.now) &&
|
||||
%w(own any).include?(enterprise.sells)
|
||||
end
|
||||
|
||||
def remaining_trial_days(enterprise)
|
||||
distance_of_time_in_words(Time.zone.now, enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days)
|
||||
distance_of_time_in_words(Time.zone.now, enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class Enterprise < ActiveRecord::Base
|
||||
SELLS = %w(unspecified none own any)
|
||||
SHOP_TRIAL_LENGTH = 30
|
||||
ENTERPRISE_SEARCH_RADIUS = 100
|
||||
|
||||
preference :shopfront_message, :text, default: ""
|
||||
@@ -332,7 +331,7 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def shop_trial_expiry
|
||||
shop_trial_start_date.andand + Enterprise::SHOP_TRIAL_LENGTH.days
|
||||
shop_trial_start_date.andand + Spree::Config[:shop_trial_length_days].days
|
||||
end
|
||||
|
||||
def can_invoice?
|
||||
|
||||
@@ -20,4 +20,5 @@ Spree::AppConfiguration.class_eval do
|
||||
preference :account_invoices_monthly_rate, :decimal, default: 0
|
||||
preference :account_invoices_monthly_cap, :decimal, default: 0
|
||||
preference :account_invoices_tax_rate, :decimal, default: 0
|
||||
preference :shop_trial_length_days, :integer, default: 30
|
||||
end
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
Adjust the amount that enterprises will be billed each month for use of the OFN.
|
||||
%br
|
||||
= form_for @settings, as: :settings, url: main_app.admin_business_model_configuration_path, :method => :put do |f|
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :shop_trial_length_days, t(:shop_trial_length)
|
||||
%span.icon-question-sign{'ofn-with-tip' => "The length of time (in days) that enterprises who are set up as shops can run as a trial period."}
|
||||
.two.columns.omega
|
||||
= f.number_field :shop_trial_length_days, min: 0.0, step: 1.0, class: "fullwidth", 'watch-value-as' => 'fixed'
|
||||
.row
|
||||
.three.columns.alpha
|
||||
= f.label :account_invoices_monthly_fixed, t(:fixed_monthly_charge)
|
||||
|
||||
@@ -5,8 +5,9 @@ module OpenFoodNetwork
|
||||
class BusinessModelConfigurationValidator
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :account_invoices_monthly_fixed, :account_invoices_monthly_rate, :account_invoices_monthly_cap, :account_invoices_tax_rate
|
||||
attr_accessor :shop_trial_length_days, :account_invoices_monthly_fixed, :account_invoices_monthly_rate, :account_invoices_monthly_cap, :account_invoices_tax_rate
|
||||
|
||||
validates :shop_trial_length_days, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :account_invoices_monthly_fixed, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :account_invoices_monthly_rate, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 }
|
||||
validates :account_invoices_monthly_cap, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
||||
@@ -9,7 +9,8 @@ describe Admin::BusinessModelConfigurationController, type: :controller do
|
||||
account_invoices_monthly_fixed: 5,
|
||||
account_invoices_monthly_rate: 0.02,
|
||||
account_invoices_monthly_cap: 50,
|
||||
account_invoices_tax_rate: 0.1
|
||||
account_invoices_tax_rate: 0.1,
|
||||
shop_trial_length_days: 30
|
||||
})
|
||||
end
|
||||
|
||||
@@ -53,16 +54,18 @@ describe Admin::BusinessModelConfigurationController, type: :controller do
|
||||
params[:settings][:account_invoices_monthly_rate] = '2'
|
||||
params[:settings][:account_invoices_monthly_cap] = '-1'
|
||||
params[:settings][:account_invoices_tax_rate] = '4'
|
||||
params[:settings][:shop_trial_length_days] = '-30'
|
||||
spree_get :update, params
|
||||
end
|
||||
|
||||
it "does not allow them to be set" do
|
||||
expect(response).to render_template :edit
|
||||
expect(assigns(:settings).errors.count).to be 5
|
||||
expect(assigns(:settings).errors.count).to be 6
|
||||
expect(Spree::Config.account_invoices_monthly_fixed).to eq 5
|
||||
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.02
|
||||
expect(Spree::Config.account_invoices_monthly_cap).to eq 50
|
||||
expect(Spree::Config.account_invoices_tax_rate).to eq 0.1
|
||||
expect(Spree::Config.shop_trial_length_days).to eq 30
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,6 +75,7 @@ describe Admin::BusinessModelConfigurationController, type: :controller do
|
||||
params[:settings][:account_invoices_monthly_rate] = '0.05'
|
||||
params[:settings][:account_invoices_monthly_cap] = '30'
|
||||
params[:settings][:account_invoices_tax_rate] = '0.15'
|
||||
params[:settings][:shop_trial_length_days] = '20'
|
||||
end
|
||||
|
||||
it "sets global config to the specified values" do
|
||||
@@ -81,6 +85,7 @@ describe Admin::BusinessModelConfigurationController, type: :controller do
|
||||
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.05
|
||||
expect(Spree::Config.account_invoices_monthly_cap).to eq 30
|
||||
expect(Spree::Config.account_invoices_tax_rate).to eq 0.15
|
||||
expect(Spree::Config.shop_trial_length_days).to eq 20
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user