diff --git a/app/models/cost_rate.rb b/app/models/cost_rate.rb
index 571d753bbe..d90675a51d 100644
--- a/app/models/cost_rate.rb
+++ b/app/models/cost_rate.rb
@@ -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?
diff --git a/app/models/cost_type.rb b/app/models/cost_type.rb
index 463a0708c4..bdd4b02e3d 100644
--- a/app/models/cost_type.rb
+++ b/app/models/cost_type.rb
@@ -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
\ No newline at end of file
+
+
+end
diff --git a/app/models/rate.rb b/app/models/rate.rb
index b45961a1ec..45f2324708 100644
--- a/app/models/rate.rb
+++ b/app/models/rate.rb
@@ -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
\ No newline at end of file
+end
diff --git a/app/views/cost_types/edit.rhtml b/app/views/cost_types/edit.rhtml
index d13e879eba..021ea55aff 100644
--- a/app/views/cost_types/edit.rhtml
+++ b/app/views/cost_types/edit.rhtml
@@ -10,7 +10,7 @@
<%= f.text_field :unit_plural, :size => 20 %>
<%= f.check_box :default %>
-
+
<%= l :caption_rate_history %>
<% javascript_tag do -%>
RatesForm = new Subform('<%= escape_javascript(render(:partial => "rate", :object => CostRate.new )) %>',<%= @cost_type.rates.length %>,'rates_body');
@@ -22,7 +22,15 @@
|
- <%- @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 -%>
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 335cfe7baf..2d345afefe 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -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"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2488320de3..a5d3df5e84 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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."