Skip to content

Commit

Permalink
Merge pull request #1203 from internetee/add-registrar-iban
Browse files Browse the repository at this point in the history
Add registrar IBAN
  • Loading branch information
vohmar authored Jun 12, 2019
2 parents 10dbd83 + 8c0d654 commit 09a6a3f
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/admin/registrars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class RegistrarsController < BaseController
load_and_authorize_resource
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
helper_method :registry_vat_rate
helper_method :iban_max_length

def index
@q = Registrar.joins(:accounts).ordered.search(params[:q])
Expand Down Expand Up @@ -73,11 +74,16 @@ def registrar_params
:vat_rate,
:accounting_customer_code,
:billing_email,
:iban,
:language)
end

def registry_vat_rate
Registry.current.vat_rate
end

def iban_max_length
Iban.max_length
end
end
end
7 changes: 6 additions & 1 deletion app/controllers/registrar/account_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Registrar
class AccountController < BaseController
skip_authorization_check
helper_method :iban_max_length

def show; end

Expand All @@ -18,7 +19,11 @@ def update
private

def registrar_params
params.require(:registrar).permit(:billing_email)
params.require(:registrar).permit(:billing_email, :iban)
end

def iban_max_length
Iban.max_length
end
end
end
5 changes: 5 additions & 0 deletions app/models/iban.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Iban
def self.max_length
34
end
end
10 changes: 10 additions & 0 deletions app/views/admin/registrars/form/_billing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
</div>
<% end %>
</div>

<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label :iban %>
</div>
<div class="col-md-7">
<%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %>
<span class="help-block"><%= t '.iban_hint' %></span>
</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/registrars/show/_billing.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

<dt><%= Registrar.human_attribute_name :reference_no %></dt>
<dd><%= registrar.reference_no %></dd>

<dt><%= Registrar.human_attribute_name :iban %></dt>
<dd><%= registrar.iban %></dd>
</dl>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/registrar/account/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<dl class="dl-horizontal">
<dt><%= Registrar.human_attribute_name :billing_email %></dt>
<dd><%= registrar.billing_email %></dd>

<dt><%= Registrar.human_attribute_name :iban %></dt>
<dd><%= registrar.iban %></dd>
</dl>
</div>

Expand Down
11 changes: 11 additions & 0 deletions app/views/registrar/account/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
</div>
</div>

<div class="form-group">
<div class="col-sm-2 control-label">
<%= f.label :iban %>
</div>

<div class="col-sm-4">
<%= f.text_field :iban, maxlength: iban_max_length, class: 'form-control' %>
<span class="help-block"><%= t '.iban_hint' %></span>
</div>
</div>

<hr>

<div class="row">
Expand Down
4 changes: 2 additions & 2 deletions app/views/registrar/account/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
</div>

<div class="row">
<div class="col-sm-5">
<div class="col-sm-6">
<%= render 'details', registrar: current_registrar_user.registrar %>
</div>
</div>

<div class="row">
<div class="col-sm-5">
<div class="col-sm-6">
<%= render 'linked_users', linked_users: current_registrar_user.linked_users %>
</div>
</div>
1 change: 1 addition & 0 deletions config/locales/admin/registrars.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ en:
registry's rate of %{registry_vat_rate} will be applied in this case.
no_reference_number_hint: Reference number will be generated automatically
disabled_reference_number_hint: Reference number cannot be changed
iban_hint: Used for e-invoices

preferences:
header: Preferences
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,4 @@ en:
ipv4: IPv4
ipv6: IPv6
reference_no: Reference number
iban: IBAN
1 change: 1 addition & 0 deletions config/locales/registrar/account.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ en:
header: Edit your account

form:
iban_hint: Required for sending e-invoices to the bank
submit_btn: Save changes

update:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190515113153_add_registrars_iban.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRegistrarsIban < ActiveRecord::Migration
def change
add_column :registrars, :iban, :string
end
end
5 changes: 4 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,8 @@ CREATE TABLE public.registrars (
reference_no character varying NOT NULL,
test_registrar boolean DEFAULT false,
language character varying NOT NULL,
vat_rate numeric(4,3)
vat_rate numeric(4,3),
iban character varying
);


Expand Down Expand Up @@ -4966,5 +4967,7 @@ INSERT INTO schema_migrations (version) VALUES ('20190510090240');

INSERT INTO schema_migrations (version) VALUES ('20190510102549');

INSERT INTO schema_migrations (version) VALUES ('20190515113153');

INSERT INTO schema_migrations (version) VALUES ('20190520093231');

1 change: 1 addition & 0 deletions test/fixtures/registrars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bestnames:
billing_email: [email protected]
website: https://bestnames.test
reference_no: 13
iban: GB33BUKB20201555555555

goodnames:
name: Good Names
Expand Down
20 changes: 20 additions & 0 deletions test/integration/admin_area/registrars_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'

class AdminAreaRegistrarsIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers

setup do
@registrar = registrars(:bestnames)
sign_in users(:admin)
end

def test_updates_registrar_optional_attributes
new_iban = 'GB94BARC10201530093459'
assert_not_equal new_iban, @registrar.iban

patch admin_registrar_path(@registrar), registrar: { iban: new_iban }
@registrar.reload

assert_equal new_iban, @registrar.iban
end
end
7 changes: 7 additions & 0 deletions test/models/iban_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class IbanTest < ActiveSupport::TestCase
def test_returns_max_length
assert_equal 34, Iban.max_length
end
end
4 changes: 4 additions & 0 deletions test/system/registrar_area/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ class RegistrarAccountTest < ApplicationSystemTestCase

def test_updates_account
new_billing_email = '[email protected]'
new_iban = 'GB77BARC20201530093459'
assert_not_equal new_billing_email, @registrar.billing_email
assert_not_equal new_iban, @registrar.iban

visit registrar_account_path
click_on 'Edit'

fill_in 'Billing email', with: new_billing_email
fill_in 'IBAN', with: new_iban
click_on 'Save changes'

assert_text 'Your account has been updated'
assert_text new_billing_email
assert_text new_iban
end
end

0 comments on commit 09a6a3f

Please sign in to comment.