Merge branch 'registry-343' into refactor-admin-registrars

This commit is contained in:
Artur Beljajev 2017-11-22 03:02:37 +02:00
commit de23a7bdb4
21 changed files with 171 additions and 82 deletions

View file

@ -63,10 +63,22 @@ module Admin
end end
def registrar_params def registrar_params
params.require(:registrar).permit( params.require(:registrar).permit(:name,
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address, :reg_no,
:country_code, :email, :phone, :website, :billing_email, :code, :test_registrar :vat_no,
) :street,
:city,
:state,
:zip,
:billing_address,
:country_code,
:email,
:phone,
:website,
:billing_email,
:code,
:test_registrar,
:accounting_customer_code)
end end
end end
end end

View file

@ -29,7 +29,7 @@ class Directo < ActiveRecord::Base
"InvoiceDate" => invoice.created_at.strftime("%Y-%m-%dT%H:%M:%S"), "InvoiceDate" => invoice.created_at.strftime("%Y-%m-%dT%H:%M:%S"),
"PaymentTerm" => Setting.directo_receipt_payment_term, "PaymentTerm" => Setting.directo_receipt_payment_term,
"Currency" => invoice.currency, "Currency" => invoice.currency,
"CustomerCode"=> invoice.buyer.try(:directo_handle) "CustomerCode"=> invoice.buyer.accounting_customer_code
){ ){
xml.line( xml.line(
"ProductID" => Setting.directo_receipt_product_name, "ProductID" => Setting.directo_receipt_product_name,
@ -150,7 +150,7 @@ class Directo < ActiveRecord::Base
xml.invoice("Number" =>directo_next, xml.invoice("Number" =>directo_next,
"InvoiceDate" =>invoices_until.strftime(date_format), "InvoiceDate" =>invoices_until.strftime(date_format),
"PaymentTerm" =>Setting.directo_receipt_payment_term, "PaymentTerm" =>Setting.directo_receipt_payment_term,
"CustomerCode"=>registrar.directo_handle, "CustomerCode"=>registrar.accounting_customer_code,
"Language" =>"", "Language" =>"",
"Currency" =>registrar_activities.first.currency, "Currency" =>registrar_activities.first.currency,
"SalesAgent" =>Setting.directo_sales_agent){ "SalesAgent" =>Setting.directo_sales_agent){

View file

@ -15,7 +15,9 @@ class Registrar < ActiveRecord::Base
validates :name, :reg_no, :country_code, :email, :code, presence: true validates :name, :reg_no, :country_code, :email, :code, presence: true
validates :name, :reg_no, :reference_no, :code, uniqueness: true validates :name, :reg_no, :reference_no, :code, uniqueness: true
validates :accounting_customer_code, presence: true
validate :forbidden_codes validate :forbidden_codes
def forbidden_codes def forbidden_codes
return true unless ['CID'].include? code return true unless ['CID'].include? code
errors.add(:code, I18n.t(:forbidden_code)) errors.add(:code, I18n.t(:forbidden_code))

View file

@ -43,6 +43,12 @@
.col-md-7 .col-md-7
= f.email_field :billing_email, class: 'form-control' = f.email_field :billing_email, class: 'form-control'
.form-group
.col-md-4.control-label
= f.label :accounting_customer_code
.col-md-7
= f.text_field :accounting_customer_code, class: 'form-control', required: true
.row .row
.col-md-8 .col-md-8
.panel.panel-default .panel.panel-default

View file

@ -42,6 +42,9 @@
%dt= Registrar.human_attribute_name :website %dt= Registrar.human_attribute_name :website
%dd= @registrar.website %dd= @registrar.website
%dt= Registrar.human_attribute_name :accounting_customer_code
%dd= @registrar.accounting_customer_code
.col-md-6 .col-md-6
.panel.panel-default .panel.panel-default
.panel-heading .panel-heading

View file

@ -0,0 +1,5 @@
class RemoveRegistrarExcludeInMonthlyDirecto < ActiveRecord::Migration
def change
remove_column :registrars, :exclude_in_monthly_directo, :string
end
end

View file

@ -0,0 +1,5 @@
class RenameRegistrarDirectoHandleToAccountingCustomerCode < ActiveRecord::Migration
def change
rename_column :registrars, :directo_handle, :accounting_customer_code
end
end

View file

@ -0,0 +1,5 @@
class ChangeRegistrarAccountingCustomerCodeToNotNull < ActiveRecord::Migration
def change
change_column_null :registrars, :accounting_customer_code, false
end
end

View file

@ -2473,11 +2473,10 @@ CREATE TABLE registrars (
zip character varying, zip character varying,
code character varying, code character varying,
website character varying, website character varying,
directo_handle character varying, accounting_customer_code character varying NOT NULL,
vat boolean, vat boolean,
legacy_id integer, legacy_id integer,
reference_no character varying, reference_no character varying,
exclude_in_monthly_directo boolean DEFAULT false,
test_registrar boolean DEFAULT false test_registrar boolean DEFAULT false
); );
@ -5052,3 +5051,9 @@ INSERT INTO schema_migrations (version) VALUES ('20171009080822');
INSERT INTO schema_migrations (version) VALUES ('20171009082321'); INSERT INTO schema_migrations (version) VALUES ('20171009082321');
INSERT INTO schema_migrations (version) VALUES ('20171025110933');
INSERT INTO schema_migrations (version) VALUES ('20171025113808');
INSERT INTO schema_migrations (version) VALUES ('20171025153841');

View file

@ -1581,7 +1581,6 @@
<text text-anchor="start" x="1600.5" y="-2399.3" font-family="Times,serif" font-size="14.00">zip :string</text> <text text-anchor="start" x="1600.5" y="-2399.3" font-family="Times,serif" font-size="14.00">zip :string</text>
<text text-anchor="start" x="1600.5" y="-2384.3" font-family="Times,serif" font-size="14.00">code :string</text> <text text-anchor="start" x="1600.5" y="-2384.3" font-family="Times,serif" font-size="14.00">code :string</text>
<text text-anchor="start" x="1600.5" y="-2369.3" font-family="Times,serif" font-size="14.00">url :string</text> <text text-anchor="start" x="1600.5" y="-2369.3" font-family="Times,serif" font-size="14.00">url :string</text>
<text text-anchor="start" x="1600.5" y="-2354.3" font-family="Times,serif" font-size="14.00">directo_handle :string</text>
<text text-anchor="start" x="1600.5" y="-2339.3" font-family="Times,serif" font-size="14.00">vat :boolean</text> <text text-anchor="start" x="1600.5" y="-2339.3" font-family="Times,serif" font-size="14.00">vat :boolean</text>
<text text-anchor="start" x="1600.5" y="-2324.3" font-family="Times,serif" font-size="14.00">legacy_id :integer</text> <text text-anchor="start" x="1600.5" y="-2324.3" font-family="Times,serif" font-size="14.00">legacy_id :integer</text>
<text text-anchor="start" x="1600.5" y="-2309.3" font-family="Times,serif" font-size="14.00">reference_no :string</text> <text text-anchor="start" x="1600.5" y="-2309.3" font-family="Times,serif" font-size="14.00">reference_no :string</text>

Before

Width:  |  Height:  |  Size: 232 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Before After
Before After

View file

@ -87,7 +87,7 @@ namespace :import do
street: x.street1.try(:strip), street: x.street1.try(:strip),
zip: x.postalcode.try(:strip), zip: x.postalcode.try(:strip),
url: x.url.try(:strip), url: x.url.try(:strip),
directo_handle: x.directo_handle.try(:strip), accounting_customer_code: x.directo_handle.try(:strip),
vat: x.vat, vat: x.vat,
legacy_id: x.id, legacy_id: x.id,
creator_str: user, creator_str: user,

View file

@ -9,6 +9,7 @@ FactoryBot.define do
zip 'test' zip 'test'
email 'test@test.com' email 'test@test.com'
country_code 'EE' country_code 'EE'
accounting_customer_code 'test'
factory :registrar_with_unlimited_balance do factory :registrar_with_unlimited_balance do
after :create do |registrar| after :create do |registrar|

View file

@ -1,20 +0,0 @@
require 'rails_helper'
RSpec.feature 'New registrar' do
background do
sign_in_to_admin_area
end
it 'creates registrar' do
visit admin_registrars_url
click_link_or_button 'New registrar'
fill_in 'registrar[name]', with: 'test'
fill_in 'registrar[reg_no]', with: '1234567'
fill_in 'registrar[email]', with: 'test@test.com'
fill_in 'registrar[code]', with: 'test'
click_link_or_button 'Create registrar'
expect(page).to have_text('Registrar has been successfully created')
end
end

View file

@ -1,18 +0,0 @@
require 'rails_helper'
RSpec.feature 'Edit registrar' do
given!(:registrar) { create(:registrar) }
background do
sign_in_to_admin_area
end
it 'updates registrar' do
visit admin_registrar_url(registrar)
click_link_or_button 'Edit'
click_link_or_button 'Update registrar'
expect(page).to have_text('Registrar has been successfully updated')
end
end

View file

@ -1,34 +0,0 @@
require 'rails_helper'
RSpec.describe 'admin registrar create' do
subject(:registrar) { Registrar.first }
before :example do
sign_in_to_admin_area
end
it 'creates new registrar' do
expect { post admin_registrars_path, registrar: attributes_for(:registrar) }
.to change { Registrar.count }.from(0).to(1)
end
it 'saves website' do
post admin_registrars_path, { registrar: attributes_for(:registrar, website: 'test') }
expect(registrar.website).to eq('test')
end
it 'saves email' do
post admin_registrars_path, { registrar: attributes_for(:registrar, email: 'test@test.com') }
expect(registrar.email).to eq('test@test.com')
end
it 'saves billing email' do
post admin_registrars_path, { registrar: attributes_for(:registrar, billing_email: 'test@test.com') }
expect(registrar.billing_email).to eq('test@test.com')
end
it 'redirects to :show' do
post admin_registrars_path, { registrar: attributes_for(:registrar) }
expect(response).to redirect_to admin_registrar_path(registrar)
end
end

View file

@ -0,0 +1,18 @@
require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_creates_new_registrar
assert_difference -> { Registrar.count } do
post admin_registrars_path, registrar: attributes_for(:registrar)
end
end
def test_redirects_to_newly_created_registrar
post admin_registrars_path, registrar: attributes_for(:registrar)
assert_redirected_to admin_registrar_path(Registrar.first)
end
end

View file

@ -0,0 +1,13 @@
require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_accounting_customer_code
registrar = create(:registrar, accounting_customer_code: 'test accounting customer code')
visit admin_registrar_path(registrar)
assert_text 'test accounting customer code'
end
end

View file

@ -0,0 +1,40 @@
require 'test_helper'
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_updates_website
registrar = create(:registrar, website: 'test')
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, website: 'new-website')
registrar.reload
assert_equal 'new-website', registrar.website
end
def test_updates_email
registrar = create(:registrar, email: 'test@test.com')
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com')
registrar.reload
assert_equal 'new-test@test.com', registrar.email
end
def test_updates_billing_email
registrar = create(:registrar, billing_email: 'test@test.com')
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com')
registrar.reload
assert_equal 'new-test@test.com', registrar.billing_email
end
def test_redirects_to_registrar
registrar = create(:registrar)
patch admin_registrar_path(registrar), registrar: attributes_for(:registrar)
assert_redirected_to admin_registrar_path(registrar)
end
end

View file

@ -0,0 +1,17 @@
require 'test_helper'
class EditRegistrarTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_updates_registrar
registrar = create(:registrar)
visit admin_registrar_path(registrar)
click_link_or_button 'Edit'
click_link_or_button 'Update registrar'
assert_text 'Registrar has been successfully updated'
end
end

View file

@ -0,0 +1,21 @@
require 'test_helper'
class NewRegistrarTest < ActionDispatch::IntegrationTest
def setup
login_as create(:admin_user)
end
def test_creates_registrar
visit admin_registrars_path
click_link_or_button 'New registrar'
fill_in 'registrar[name]', with: 'test'
fill_in 'registrar[reg_no]', with: '1234567'
fill_in 'registrar[email]', with: 'test@test.com'
fill_in 'registrar[code]', with: 'test'
fill_in 'registrar[accounting_customer_code]', with: 'test'
click_link_or_button 'Create registrar'
assert_text 'Registrar has been successfully created'
end
end

View file

@ -0,0 +1,9 @@
require 'test_helper'
class RegistrarTest < ActiveSupport::TestCase
def test_rejects_absent_accounting_customer_code
registrar = Registrar.new(accounting_customer_code: nil)
registrar.validate
assert registrar.errors.added?(:accounting_customer_code, :blank)
end
end