mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-20 04:59:16 +00:00
45 lines
1.6 KiB
Ruby
45 lines
1.6 KiB
Ruby
require 'open_food_network/accounts_and_billing_settings'
|
|
|
|
class Admin::AccountsAndBillingSettingsController < Spree::Admin::BaseController
|
|
before_filter :load_distributors, only: [:edit, :update]
|
|
|
|
def edit
|
|
@settings = OpenFoodNetwork::AccountsAndBillingSettings.new({
|
|
accounts_distributor_id: Spree::Config[:accounts_distributor_id],
|
|
default_accounts_payment_method_id: Spree::Config[:default_accounts_payment_method_id],
|
|
default_accounts_shipping_method_id: Spree::Config[:default_accounts_shipping_method_id],
|
|
collect_billing_information: Spree::Config[:collect_billing_information],
|
|
create_invoices_for_enterprise_users: Spree::Config[:create_invoices_for_enterprise_users]
|
|
})
|
|
end
|
|
|
|
def update
|
|
@settings = OpenFoodNetwork::AccountsAndBillingSettings.new(params[:settings], params[:button])
|
|
if @settings.valid?
|
|
Spree::Config.set(params[:settings])
|
|
|
|
if params[:button] == "update_and_run_job"
|
|
Delayed::Job.enqueue UpdateBillablePeriods.new({create_invoices: true})
|
|
end
|
|
|
|
flash[:success] = t(:successfully_updated, :resource => t(:billing_and_account_settings))
|
|
redirect_to main_app.edit_admin_accounts_and_billing_settings_path
|
|
else
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def show_methods
|
|
@enterprise = Enterprise.find_by_id(params[:enterprise_id])
|
|
@shipping_methods = @enterprise.shipping_methods
|
|
@payment_methods = @enterprise.payment_methods
|
|
render partial: 'method_settings'
|
|
end
|
|
|
|
private
|
|
|
|
def load_distributors
|
|
@distributors = Enterprise.is_distributor.select([:id, :name])
|
|
end
|
|
end
|