summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/time_entry.rb28
-rw-r--r--app/views/settings/_timelog.html.erb3
2 files changed, 30 insertions, 1 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index 1e0f5bc95..80d14ad15 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -122,7 +122,19 @@ class TimeEntry < ActiveRecord::Base
end
def validate_time_entry
- errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
+ if hours
+ errors.add :hours, :invalid if hours < 0
+ errors.add :hours, :invalid if hours == 0.0 && hours_changed? && !Setting.timelog_accept_0_hours?
+
+ max_hours = Setting.timelog_max_hours_per_day.to_f
+ if hours_changed? && max_hours > 0.0
+ logged_hours = other_hours_with_same_user_and_day
+ if logged_hours + hours > max_hours
+ errors.add :base, I18n.t(:error_exceeds_maximum_hours_per_day,
+ :logged_hours => format_hours(logged_hours), :max_hours => format_hours(max_hours))
+ end
+ end
+ end
errors.add :project_id, :invalid if project.nil?
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
@@ -166,4 +178,18 @@ class TimeEntry < ActiveRecord::Base
def editable_custom_fields(user=nil)
editable_custom_field_values(user).map(&:custom_field).uniq
end
+
+ private
+
+ # Returns the hours that were logged in other time entries for the same user and the same day
+ def other_hours_with_same_user_and_day
+ if user_id && spent_on
+ TimeEntry.
+ where(:user_id => user_id, :spent_on => spent_on).
+ where.not(:id => id).
+ sum(:hours).to_f
+ else
+ 0.0
+ end
+ end
end
diff --git a/app/views/settings/_timelog.html.erb b/app/views/settings/_timelog.html.erb
index c4453a616..e3c0a5657 100644
--- a/app/views/settings/_timelog.html.erb
+++ b/app/views/settings/_timelog.html.erb
@@ -4,6 +4,9 @@
<p><%= setting_multiselect(:timelog_required_fields,
[[l(:field_issue), 'issue_id'], [l(:field_comments), 'comments'] ]) %></p>
+<p><%= setting_text_field :timelog_max_hours_per_day, :size => 6 %></p>
+
+<p><%= setting_check_box :timelog_accept_0_hours %></p>
</div>
<fieldset class="box">