summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2022-06-20 17:40:39 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2022-06-20 17:40:39 +0000
commit3f97ec875c6a1d9475dadede6a32044a852d45f1 (patch)
tree2a99e2e02334b1b9e63b1b89d913df9c9ec4e333 /app
parent69a8fe2f6d422c9653a7cc16076c3140040fe349 (diff)
downloadredmine-3f97ec875c6a1d9475dadede6a32044a852d45f1.tar.gz
redmine-3f97ec875c6a1d9475dadede6a32044a852d45f1.zip
Merged r21668 and r21669 to 5.0-stable (#33914).
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@21670 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/time_entry.rb2
-rw-r--r--app/models/time_entry_activity.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index 34e4aab7b..7776db0d8 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -107,7 +107,7 @@ class TimeEntry < ActiveRecord::Base
def initialize(attributes=nil, *args)
super
if new_record? && self.activity.nil?
- if default_activity = TimeEntryActivity.default
+ if default_activity = TimeEntryActivity.default(self.project)
self.activity_id = default_activity.id
end
self.hours = nil if hours == 0
diff --git a/app/models/time_entry_activity.rb b/app/models/time_entry_activity.rb
index 973ec923f..40505019c 100644
--- a/app/models/time_entry_activity.rb
+++ b/app/models/time_entry_activity.rb
@@ -22,6 +22,16 @@ class TimeEntryActivity < Enumeration
OptionName = :enumeration_activities
+ def self.default(project=nil)
+ default_activity = super()
+
+ if default_activity.nil? || project.nil? || project.activities.blank? || project.activities.include?(default_activity)
+ return default_activity
+ end
+
+ project.activities.detect { |activity| activity.parent_id == default_activity.id }
+ end
+
def option_name
OptionName
end