Added registrar code

This commit is contained in:
Priit Tark 2015-05-04 12:35:42 +03:00
parent 85efa5eb28
commit 8b22c58eec
7 changed files with 28 additions and 5 deletions

View file

@ -57,7 +57,7 @@ class Admin::RegistrarsController < AdminController
def registrar_params def registrar_params
params.require(:registrar).permit( params.require(:registrar).permit(
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address, :name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address,
:country_code, :email, :phone, :billing_email :country_code, :email, :phone, :billing_email, :code
) )
end end
end end

View file

@ -12,7 +12,7 @@ class Registrar < ActiveRecord::Base
belongs_to :country_deprecated, foreign_key: :country_id belongs_to :country_deprecated, foreign_key: :country_id
validates :name, :reg_no, :country_code, :email, presence: true validates :name, :reg_no, :country_code, :email, :code, presence: true
validates :name, :reg_no, :reference_no, uniqueness: true validates :name, :reg_no, :reference_no, uniqueness: true
validate :set_code, if: :new_record? validate :set_code, if: :new_record?
@ -139,7 +139,11 @@ class Registrar < ActiveRecord::Base
end end
def code=(code) def code=(code)
self[:code] = code if new_record? self[:code] = code.upcase if new_record? && code.present?
end
def contact_prefix
"CID:#{code}:"
end end
private private

View file

@ -70,6 +70,19 @@
.col-md-7 .col-md-7
= f.select(:country_code, = f.select(:country_code,
SortedCountry.all_options(f.object.country_code), {}, class: 'form-control') SortedCountry.all_options(f.object.country_code), {}, class: 'form-control')
.row
.col-md-8
.panel.panel-default
.panel-heading.clearfix
.pull-left= t(:misc)
.panel-body
.form-group
.col-md-4.control-label
= f.label :code
.col-md-7
= f.text_field(:code, class: 'form-control')
%hr %hr
.row .row
.col-md-8.text-right .col-md-8.text-right

View file

@ -29,6 +29,9 @@
%dt= t(:reference_no) %dt= t(:reference_no)
%dd= @registrar.reference_no %dd= @registrar.reference_no
%dt= t(:code)
%dd= @registrar.code
.col-md-6 .col-md-6
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading

View file

@ -86,7 +86,8 @@ namespace :import do
vat: x.vat, vat: x.vat,
legacy_id: x.id, legacy_id: x.id,
creator_str: user, creator_str: user,
updator_str: user updator_str: user,
code: x.handle.upcase
}) })
end end

View file

@ -7,6 +7,7 @@ Fabricator(:registrar) do
zip 'Postal' zip 'Postal'
email 'info@registrar1.ee' email 'info@registrar1.ee'
country_code 'EE' country_code 'EE'
code 'REG'
reference_no { sequence(:reference_no) { |i| "RF#{i}" } } reference_no { sequence(:reference_no) { |i| "RF#{i}" } }
accounts(count: 1) accounts(count: 1)
end end

View file

@ -16,7 +16,8 @@ describe Registrar do
'Contact e-mail is missing', 'Contact e-mail is missing',
'Country code is missing', 'Country code is missing',
'Name is missing', 'Name is missing',
'Reg no is missing' 'Reg no is missing',
'Code is missing',
]) ])
end end