diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index 03facadb3..666fac74a 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -21,6 +21,11 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController def valuate if valid_price_params? && @investment.update(valuation_params) + + if @investment.unfeasible_email_pending? + @investment.send_unfeasible_email + end + redirect_to valuation_budget_budget_investment_path(@budget, @investment), notice: t('valuation.budget_investments.notice.valuate') else render action: :edit diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index c5c4ae603..188de029b 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -82,6 +82,15 @@ class Mailer < ApplicationMailer end end + def budget_investment_unfeasible(investment) + @investment = investment + @author = investment.author + + with_user(@author) do + mail(to: @author.email, subject: t('mailers.budget_investment_unfeasible.subject', code: @investment.code)) + end + end + private def with_user(user, &block) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index dd98e472e..4c8816abc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -136,12 +136,21 @@ class Budget unfeasible? && valuation_finished? end + def unfeasible_email_pending? + unfeasible_email_sent_at.blank? && unfeasible? && valuation_finished? + end + def total_votes cached_votes_up + physical_votes end def code - "B#{budget.id}I#{id}" + "#{created_at.strftime('%Y')}-#{id}" + (administrator.present? ? "-A#{administrator.id}" : "") + end + + def send_unfeasible_email + Mailer.budget_investment_unfeasible(self).deliver_later + update(unfeasible_email_sent_at: Time.current) end def reason_for_not_being_selectable_by(user) diff --git a/app/views/mailer/budget_investment_unfeasible.html.erb b/app/views/mailer/budget_investment_unfeasible.html.erb new file mode 100644 index 000000000..3bed46cec --- /dev/null +++ b/app/views/mailer/budget_investment_unfeasible.html.erb @@ -0,0 +1,35 @@ +
+ <%= t("mailers.budget_investment_unfeasible.hi") %> +
+ ++ <%= t("mailers.budget_investment_unfeasible.unfeasible_html", + title: @investment.title) %> +
+ ++ <%= @investment.unfeasibility_explanation %> +
+ ++ <%= t("mailers.budget_investment_unfeasible.new_html", + url: link_to(t("mailers.budget_investment_unfeasible.new_href"), + new_budget_investment_url(@investment.budget), style: "color: #2895F1; text-decoration: underline;")) %> +
+ ++ <%= t("mailers.budget_investment_unfeasible.reconsider_html", code: @investment.code) %> +
+ ++ <%= t("mailers.budget_investment_unfeasible.sorry") %> +
+ +
+ <%= t("mailers.budget_investment_unfeasible.sincerely") %>
+
+ <%= t("mailers.budget_investment_unfeasible.signatory") %>
+