adding validations

fixing existing validation
fixing view which breaks when error occurred
fixing error messages
fixing missing translations
pull/6827/head
Romano Licker 13 years ago
parent 683e9ec446
commit 40a17fc0b0
  1. 1
      app/models/cost_rate.rb
  2. 10
      app/models/cost_type.rb
  3. 11
      app/models/rate.rb
  4. 12
      app/views/cost_types/edit.rhtml
  5. 3
      config/locales/de.yml
  6. 3
      config/locales/en.yml

@ -5,6 +5,7 @@ class CostRate < Rate
def validate
# Only allow change of project and user on first creation
super
return if self.new_record?
errors.add :cost_type_id, :activerecord_error_invalid if cost_type_id_changed?

@ -63,12 +63,12 @@ class CostType < ActiveRecord::Base
end
end
end
def save_rates
rates.each do |rate|
rate.save(false)
rate.save!
end
end
end
end

@ -1,5 +1,8 @@
class Rate < ActiveRecord::Base
validates_numericality_of :rate, :allow_nil => false, :message => :activerecord_error_invalid
validates_presence_of :valid_from
validates_presence_of :rate
validates_numericality_of :rate, :allow_nil => false
belongs_to :user
belongs_to :project
@ -12,15 +15,15 @@ class Rate < ActiveRecord::Base
value
end
end
def validate
valid_from.to_date
rescue Exception
errors.add :valid_from, :activerecord_error_invalid
errors.add :valid_from, :not_a_date
end
def before_save
self.valid_from &&= valid_from.to_date
end
end
end

@ -10,7 +10,7 @@
<p><%= f.text_field :unit_plural, :size => 20 %></p>
<p><%= f.check_box :default %></p>
</div>
<h3><%= l :caption_rate_history %></h3>
<% javascript_tag do -%>
RatesForm = new Subform('<%= escape_javascript(render(:partial => "rate", :object => CostRate.new )) %>',<%= @cost_type.rates.length %>,'rates_body');
@ -22,7 +22,15 @@
<th></th>
</tr></thead>
<tbody id="rates_body">
<%- @cost_type.rates.sort { |a,b| b.valid_from <=> a.valid_from }.each_with_index do |rate, index| -%>
<%- @cost_type.rates.sort { |a,b|
case
when !a.valid? && !b.valid?: 0
when !a.valid?: -1
when !b.valid?: 1
else
b.valid_from <=> a.valid_from
end
}.each_with_index do |rate, index| -%>
<%= render :partial => 'rate', :object => rate, :locals => {:index => index, :classes => cycle('odd', 'even')} %>
<%- end -%>
</tbody>

@ -35,6 +35,8 @@ de:
caption_costs: Kosten
caption_current_rate: Aktueller Satz
caption_default: Standard
field_rate: Satz
field_rates: Sätze
caption_default_rate_history_for: "Standardsatz-Historie f\xC3\xBCr %{user}"
caption_default_rates: "Standards\xC3\xA4tze"
caption_fixed_date: Referenzdatum
@ -56,6 +58,7 @@ de:
caption_status: Status
caption_subject: Titel
caption_valid_from: "G\xC3\xBCltig ab"
field_valid_from: "G\xC3\xBCltig ab"
error_generic: "Bei der Anfrage ist ein Fehler aufgetreten. Sie wurde zurückgesetzt. Bitte melden Sie das Problem Ihrem Redmine Administrator"

@ -34,6 +34,8 @@ en:
caption_costs: Costs
caption_current_rate: Current Rate
caption_default: Default
field_rate: Rate
field_rates: Rates
caption_default_rate_history_for: Default Rate History for %{user}
caption_default_rates: Default Rates
caption_fixed_date: Fixed Date
@ -55,6 +57,7 @@ en:
caption_status: Status
caption_subject: Title
caption_valid_from: Valid from
field_valid_from: Valid from
error_generic: "An error occurred while executing the query. It has been resetted. Please report this error to your Redmine administrator."

Loading…
Cancel
Save