Add configurable minimum deposit #2782

This commit is contained in:
Martin Lensment 2015-07-31 18:09:34 +03:00
parent e92ef92331
commit 1fe8bd3f46
6 changed files with 31 additions and 1 deletions

View file

@ -61,7 +61,7 @@ class Admin::SettingsController < AdminController
:expire_pending_confirmation
]
floats = [:registry_vat_prc]
floats = [:registry_vat_prc, :minimum_deposit]
booleans = [
:ds_data_allowed,

View file

@ -7,6 +7,11 @@ class Deposit
attr_accessor :amount, :description, :registrar, :registrar_id
validates :amount, :registrar, presence: true
validate :validate_amount
def validate_amount
return if BigDecimal.new(amount) >= Setting.minimum_deposit
errors.add(:amount, I18n.t(:is_too_small_minimum_deposit_is, amount: Setting.minimum_deposit, currency: 'EUR'))
end
def initialize(attributes = {})
attributes.each do |name, value|

View file

@ -69,6 +69,7 @@
= render 'setting_row', var: :invoice_number_max
= render 'setting_row', var: :days_to_keep_invoices_active
= render 'setting_row', var: :days_to_keep_overdue_invoices_active
= render 'setting_row', var: :minimum_deposit
= render 'setting_row', var: :registry_billing_email
= render 'setting_row', var: :registry_invoice_contact
= render 'setting_row', var: :registry_vat_no

View file

@ -31,6 +31,8 @@ if con.present? && con.table_exists?('settings')
Setting.save_default(:invoice_number_max, 149999)
Setting.save_default(:days_to_keep_invoices_active, 30)
Setting.save_default(:days_to_keep_overdue_invoices_active, 30)
Setting.save_default(:minimum_deposit, 0.0)
Setting.save_default(:days_to_renew_domain_before_expire, 90)
Setting.save_default(:expire_warning_period, 15)
Setting.save_default(:redemption_grace_period, 30)

View file

@ -894,3 +894,4 @@ en:
nameserver_hostname: 'Nameserver hostname'
result_count: '%{count} results'
failed_to_generate_invoice_invoice_number_limit_reached: 'Failed to generate invoice - invoice number limit reached'
is_too_small_minimum_deposit_is: 'is too small. Minimum deposit is %{amount} %{currency}'

View file

@ -41,6 +41,27 @@ feature 'Invoice', type: :feature do
page.should have_content(r.name)
end
it 'should not issue and invoice with deposit amount too small' do
Setting.minimum_deposit = 0.0
r = Fabricate(:registrar)
visit admin_invoices_url
click_link('Add')
select r.name, from: 'Registrar'
fill_in 'Amount', with: '-2.11'
fill_in 'Description', with: 'test issue'
click_button 'Save'
page.should have_content('Amount is too small. Minimum deposit is 0.0 EUR')
Setting.minimum_deposit = 12.43
fill_in 'Amount', with: '12.42'
click_button 'Save'
page.should have_content('Amount is too small. Minimum deposit is 12.43 EUR')
fill_in 'Amount', with: '12.44'
click_button 'Save'
page.should have_content('Record created')
Setting.minimum_deposit = 0.0
end
it 'should forward invoice' do
visit '/admin/invoices'
click_link @invoice.to_s