Feature #10314 » feature-10314-v2.patch
| app/helpers/timelog_helper.rb | ||
|---|---|---|
|
def activity_collection_for_select_options(time_entry=nil, project=nil)
|
||
|
project ||= time_entry.try(:project)
|
||
|
project ||= @project
|
||
|
if project.nil?
|
||
|
activities = TimeEntryActivity.shared.active
|
||
|
else
|
||
|
activities = project.activities
|
||
|
end
|
||
|
activities = TimeEntryActivity.available_activities(project)
|
||
|
collection = []
|
||
|
if time_entry && time_entry.activity && !time_entry.activity.active?
|
||
| app/models/time_entry.rb | ||
|---|---|---|
|
if new_record? && self.activity.nil?
|
||
|
if default_activity = TimeEntryActivity.default(self.project)
|
||
|
self.activity_id = default_activity.id
|
||
|
elsif (activities = TimeEntryActivity.available_activities(self.project)) && activities.count == 1
|
||
|
self.activity_id = activities.first.id
|
||
|
end
|
||
|
self.hours = nil if hours == 0
|
||
|
end
|
||
| app/models/time_entry_activity.rb | ||
|---|---|---|
|
project.activities.detect { |activity| activity.parent_id == default_activity.id }
|
||
|
end
|
||
|
def self.available_activities(project=nil)
|
||
|
if project.nil?
|
||
|
TimeEntryActivity.shared.active
|
||
|
else
|
||
|
project.activities
|
||
|
end
|
||
|
end
|
||
|
def option_name
|
||
|
OptionName
|
||
|
end
|
||
| test/unit/time_entry_test.rb | ||
|---|---|---|
|
assert_equal entry.activity_id, project_specific_default_activity.id
|
||
|
end
|
||
|
def test_activity_id_should_be_set_automatically_if_there_is_only_one_activity_available
|
||
|
project = Project.find(1)
|
||
|
TimeEntry.all.destroy_all
|
||
|
TimeEntryActivity.destroy_all
|
||
|
only_one_activity = TimeEntryActivity.create!(
|
||
|
name: 'Development',
|
||
|
parent_id: nil,
|
||
|
project_id: nil,
|
||
|
is_default: false
|
||
|
)
|
||
|
entry = TimeEntry.new(project: project)
|
||
|
assert_equal entry.activity_id, only_one_activity.id
|
||
|
end
|
||
|
def test_should_accept_future_dates
|
||
|
entry = TimeEntry.generate
|
||
|
entry.spent_on = User.current.today + 1
|
||
- « Previous
- 1
- 2
- Next »