diff --git a/app/views/valuation/budget_investments/edit.html.erb b/app/views/valuation/budget_investments/edit.html.erb index 3e7c1369c..090e6bddc 100644 --- a/app/views/valuation/budget_investments/edit.html.erb +++ b/app/views/valuation/budget_investments/edit.html.erb @@ -4,96 +4,125 @@ <% end %>

<%= t("valuation.budget_investments.edit.dossier") %>

- -<%= form_for(@investment, url: valuate_valuation_budget_budget_investment_path(@budget, @investment), html: {id: "valuation_budget_investment_edit_form"}) do |f| %> - <%= render 'shared/errors', resource: @investment %> -
-
-
- <%= t('valuation.budget_investments.edit.feasibility') %> -
- - <%= f.radio_button :feasibility, 'undecided', label: false %> - <%= f.label :feasibility_undecided, t('valuation.budget_investments.edit.undefined_feasible') %> - -
- -
- - <%= f.radio_button :feasibility, 'feasible', label: false %> - <%= f.label :feasibility_feasible, t('valuation.budget_investments.edit.feasible') %> - -
- -
- - <%= f.radio_button :feasibility, 'unfeasible', label: false %> - <%= f.label :feasibility_unfeasible, t('valuation.budget_investments.edit.unfeasible') %> - -
-
-
-
- -
- +<% if can?(:valuate, @investment) %> + <%= form_for(@investment, url: valuate_valuation_budget_budget_investment_path(@budget, @investment), html: {id: "valuation_budget_investment_edit_form"}) do |f| %> + <%= render 'shared/errors', resource: @investment %>
- <%= f.label :unfeasibility_explanation, t("valuation.budget_investments.edit.feasible_explanation_html") %> - <%= f.text_area :unfeasibility_explanation, label: false, rows: 3 %> +
+ <%= t('valuation.budget_investments.edit.feasibility') %> +
+ + <%= f.radio_button :feasibility, 'undecided', label: false %> + <%= f.label :feasibility_undecided, t('valuation.budget_investments.edit.undefined_feasible') %> + +
+ +
+ + <%= f.radio_button :feasibility, 'feasible', label: false %> + <%= f.label :feasibility_feasible, t('valuation.budget_investments.edit.feasible') %> + +
+ +
+ + <%= f.radio_button :feasibility, 'unfeasible', label: false %> + <%= f.label :feasibility_unfeasible, t('valuation.budget_investments.edit.unfeasible') %> + +
+
-
+
-
- -
-
- <%= f.label :price, "#{t('valuation.budget_investments.edit.price_html', currency: @budget.currency_symbol)}" %> - <%= f.number_field :price, label: false, max: 1000000000000000 %> +
+
+ <%= f.label :unfeasibility_explanation, t("valuation.budget_investments.edit.feasible_explanation_html") %> + <%= f.text_area :unfeasibility_explanation, label: false, rows: 3 %> +
-
- <%= f.label :price_first_year, "#{t('valuation.budget_investments.edit.price_first_year_html', currency: @budget.currency_symbol)}" %> - <%= f.number_field :price_first_year, label: false, max: 1000000000000000 %> +
+ +
+ +
+
+ <%= f.label :price, "#{t('valuation.budget_investments.edit.price_html', currency: @budget.currency_symbol)}" %> + <%= f.number_field :price, label: false, max: 1000000000000000 %> +
+ +
+ <%= f.label :price_first_year, "#{t('valuation.budget_investments.edit.price_first_year_html', currency: @budget.currency_symbol)}" %> + <%= f.number_field :price_first_year, label: false, max: 1000000000000000 %> +
+
+ +
+
+ <%= f.label :price_explanation, t("valuation.budget_investments.edit.price_explanation_html") %> + <%= f.text_area :price_explanation, label: false, rows: 3 %> +
+
+ +
+
+ <%= f.label :duration, t("valuation.budget_investments.edit.duration_html") %> + <%= f.text_field :duration, label: false %> +
+
+ +
+ +
+
+ <%= f.label :valuation_finished do %> + <%= f.check_box :valuation_finished, + title: t('valuation.budget_investments.edit.valuation_finished'), + label: false, id: 'js-investment-report-alert', + "data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"), + "data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %> + <%= t("valuation.budget_investments.edit.valuation_finished") %> + <% end %>
-
- <%= f.label :price_explanation, t("valuation.budget_investments.edit.price_explanation_html") %> - <%= f.text_area :price_explanation, label: false, rows: 3 %> +
+ <%= f.submit(class: "button expanded large", value: t("valuation.budget_investments.edit.save")) %>
- -
-
- <%= f.label :duration, t("valuation.budget_investments.edit.duration_html") %> - <%= f.text_field :duration, label: false %> -
-
- -
- -
-
- <%= f.label :valuation_finished do %> - <%= f.check_box :valuation_finished, - title: t('valuation.budget_investments.edit.valuation_finished'), - label: false, id: 'js-investment-report-alert', - "data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"), - "data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %> - <%= t("valuation.budget_investments.edit.valuation_finished") %> - <% end %> -
-
- -
-
- <%= f.submit(class: "button expanded large", value: t("valuation.budget_investments.edit.save")) %> -
-
+ <% end %> +<% else %> +

+

<%= t('valuation.budget_investments.edit.valuation_finished') %>

+

+

+ <%= t('valuation.budget_investments.edit.feasibility') %>: + <%= t("admin.budget_investments.index.feasibility.#{@investment.feasibility}") %> +

+

+ <%= t("valuation.budget_investments.edit.feasible_explanation_html") %>: + <%= @investment.unfeasibility_explanation.presence || '-' %> +

+

+ <%= t('valuation.budget_investments.edit.price_html', currency: @budget.currency_symbol) %>: + <%= @investment.price.presence || '-' %> +

+

+ <%= t('valuation.budget_investments.show.price_first_year', currency: @budget.currency_symbol) %>: + <%= @investment.price_first_year.presence || '-' %> +

+

+ <%= t('valuation.budget_investments.edit.price_explanation_html') %>: + <%= @investment.price_explanation.presence || '-'%> +

+

+ <%= t('valuation.budget_investments.edit.duration_html') %>: + <%= @investment.duration.presence || '-' %> +

<% end %> <%= render 'valuation/budget_investments/valuation_comments' %> diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 16e3aa09c..91e98ee1e 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -352,6 +352,47 @@ feature 'Valuation budget investments' do expect(page).to have_content('Valuation finished') end + context 'Reopen valuation' do + background do + investment.update( + valuation_finished: true, + feasibility: 'feasible', + unfeasibility_explanation: 'Explanation is explanatory', + price: 999, + price_first_year: 666, + price_explanation: 'Democracy is not cheap', + duration: '1 light year' + ) + end + + scenario 'Admins can reopen & modify finished valuation' do + logout + login_as(admin.user) + visit edit_valuation_budget_budget_investment_path(budget, investment) + + expect(page).to have_selector("input[id='budget_investment_feasibility_undecided']") + expect(page).to have_selector("textarea[id='budget_investment_unfeasibility_explanation']") + expect(page).to have_selector("input[name='budget_investment[valuation_finished]']") + expect(page).to have_button('Save changes') + end + + scenario 'Valuators that are not admins cannot reopen or modify a finished valuation' do + visit edit_valuation_budget_budget_investment_path(budget, investment) + + expect(page).not_to have_selector("input[id='budget_investment_feasibility_undecided']") + expect(page).not_to have_selector("textarea[id='budget_investment_unfeasibility_explanation']") + expect(page).not_to have_selector("input[name='budget_investment[valuation_finished]']") + expect(page).to have_content('Valuation finished') + expect(page).to have_content('Feasibility: Feasible') + expect(page).to have_content('Feasibility explanation: Explanation is explanatory') + expect(page).to have_content('Price (€): 999') + expect(page).to have_content('Cost during the first year: 666') + expect(page).to have_content('Price explanation: Democracy is not cheap') + expect(page).to have_content('Time scope: 1 light year') + expect(page).not_to have_button('Save changes') + end + end + scenario 'Validates price formats' do visit valuation_budget_budget_investments_path(budget) within("#budget_investment_#{investment.id}") do