User can be add siret when is procedure at the attribut individual and individual_with_siret

This commit is contained in:
Xavier J 2016-10-05 14:28:10 +02:00
parent aa3b1e974d
commit 8160d4d0df
13 changed files with 80 additions and 8 deletions

View file

@ -0,0 +1,13 @@
class Users::Dossiers::AddSiretController < ApplicationController
def show
@facade = DossierFacades.new params[:dossier_id], current_user.email
raise ActiveRecord::RecordNotFound unless @facade.procedure.individual_with_siret?
@siret = current_user.siret unless current_user.siret.nil?
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for users_dossiers_path
end
end

View file

@ -65,8 +65,12 @@ class Users::DossiersController < UsersController
end end
@facade = facade params[:dossier_id] @facade = facade params[:dossier_id]
render '/dossiers/new_siret', formats: 'js'
if @facade.procedure.individual_with_siret?
render '/dossiers/add_siret', formats: 'js'
else
render '/dossiers/new_siret', formats: 'js'
end
rescue RestClient::ResourceNotFound, RestClient::BadRequest rescue RestClient::ResourceNotFound, RestClient::BadRequest
errors_valid_siret errors_valid_siret
@ -80,7 +84,11 @@ class Users::DossiersController < UsersController
@facade = facade params[:dossier_id] @facade = facade params[:dossier_id]
render '/dossiers/new_siret', formats: :js if @facade.procedure.individual_with_siret?
render '/dossiers/add_siret', formats: 'js'
else
render '/dossiers/new_siret', formats: 'js'
end
end end
def update def update

View file

@ -73,8 +73,6 @@ class Dossier < ActiveRecord::Base
def build_default_individual def build_default_individual
Individual.new(dossier_id: id).save(validate: false) Individual.new(dossier_id: id).save(validate: false)
Entreprise.new(dossier_id: id).save(validate: false)
Etablissement.new(dossier_id: id, entreprise_id: entreprise.id).save(validate: false)
end end
def ordered_champs def ordered_champs
@ -289,7 +287,8 @@ class Dossier < ActiveRecord::Base
end end
def reset! def reset!
entreprise.destroy unless entreprise.nil? entreprise.destroy
etablissement.destroy
update_attributes(autorisation_donnees: false) update_attributes(autorisation_donnees: false)
end end

View file

@ -4,6 +4,7 @@ class Entreprise < ActiveRecord::Base
has_one :rna_information, dependent: :destroy has_one :rna_information, dependent: :destroy
validates_presence_of :siren validates_presence_of :siren
validates_uniqueness_of :dossier_id
before_save :default_values before_save :default_values

View file

@ -4,6 +4,8 @@ class Etablissement < ActiveRecord::Base
has_many :exercices, dependent: :destroy has_many :exercices, dependent: :destroy
validates_uniqueness_of :dossier_id
def geo_adresse def geo_adresse
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ') [numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
end end

View file

@ -7,7 +7,7 @@
= @facade.dossier.display_state = @facade.dossier.display_state
= render partial: 'follow_action' = render partial: 'follow_action'
- unless @facade.procedure.for_individual? - unless @facade.entreprise.nil?
= render partial: '/dossiers/infos_entreprise' = render partial: '/dossiers/infos_entreprise'
= render partial: '/dossiers/infos_dossier' = render partial: '/dossiers/infos_dossier'

View file

@ -54,6 +54,9 @@
= render partial: 'users/recapitulatif/modal_upload_pj' = render partial: 'users/recapitulatif/modal_upload_pj'
-if @facade.procedure.individual_with_siret
%a#add_siret.btn.btn-success{href: users_dossier_add_siret_path(dossier_id: @facade.dossier.id)}
= "Renseigner un SIRET"
-if @facade.dossier.procedure.module_api_carto.use_api_carto -if @facade.dossier.procedure.module_api_carto.use_api_carto
%a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"} %a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"}
= 'Modifier la carte' = 'Modifier la carte'

View file

@ -0,0 +1,12 @@
<% if flash.empty? %>
$('.row.etape.etape_2').hide(300, render_new_siret);
$('.row.etape.etape_2').slideDown(400, the_terms);
<% else %>
error_form_siret('<%= invalid_siret %>');
<% end %>
<% flash.clear %>
function render_new_siret(){
$('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape_2/entreprise', locals: { facade: @facade } ) %>");
}

View file

@ -8,7 +8,6 @@ error_form_siret('<%= invalid_siret %>');
<% flash.clear %> <% flash.clear %>
function render_new_siret(){ function render_new_siret(){
$('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>"); $('.row.etape.etape_2').html("<%= escape_javascript(render partial: '/dossiers/etapes/etape2', locals: { facade: @facade } ) %>");
} }

View file

@ -0,0 +1,2 @@
.row.etape.etape_2
= render partial: 'dossiers/etapes/etape_2/entreprise'

View file

@ -62,6 +62,8 @@ Rails.application.routes.draw do
end end
resources :dossiers do resources :dossiers do
get '/add_siret' => 'dossiers/add_siret#show'
get '/description' => 'description#show' get '/description' => 'description#show'
get '/description/error' => 'description#error' get '/description/error' => 'description#error'
post 'description' => 'description#create' post 'description' => 'description#create'

View file

@ -0,0 +1,25 @@
require 'spec_helper'
describe Users::Dossiers::AddSiretController, type: :controller do
describe '#GET show' do
let(:dossier) { create :dossier }
before do
sign_in dossier.user
end
subject { get :show, dossier_id: dossier.id }
context 'when dossier is not attached at a procedure with individual siret attribut' do
it { is_expected.to redirect_to users_dossiers_path }
end
context 'when dossier is attached at a procedure with individual siret attribut' do
let(:procedure) { create :procedure, individual_with_siret: true }
let(:dossier) { create :dossier, procedure: procedure }
it { expect(subject.status).to eq 200 }
end
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'users/recapitulatif/show.html.haml', type: :view do describe 'users/recapitulatif/show.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise, state: state, procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative)) } let(:dossier) { create(:dossier, :with_entreprise, state: state, procedure: create(:procedure, :with_api_carto, :with_two_type_de_piece_justificative, for_individual: true, individual_with_siret: true)) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:state) { 'draft' } let(:state) { 'draft' }
@ -46,6 +46,12 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end end
end end
context 'lien carte' do
it 'le lien vers le renseignement un SIRET est présent' do
expect(rendered).to have_css('#add_siret')
end
end
context 'lien carte' do context 'lien carte' do
it 'le lien vers carte est présent' do it 'le lien vers carte est présent' do
expect(rendered).to have_css('#maj_carte') expect(rendered).to have_css('#maj_carte')