Auto-assign time to jobs
If a job is not specified, a reasonable choice will be made. Refs #2111
This commit is contained in:
parent
40eb43e0c5
commit
a71ffbcacc
|
@ -26,7 +26,7 @@ class JobsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@job = Job.new(job_params)
|
@job = Job.new(remove_empty_time_budgets(job_params))
|
||||||
if @job.save
|
if @job.save
|
||||||
redirect_to project_job_path(@job.project, @job)
|
redirect_to project_job_path(@job.project, @job)
|
||||||
else
|
else
|
||||||
|
|
|
@ -50,4 +50,23 @@ class Job < ActiveRecord::Base
|
||||||
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
ActionView::Base.send(:include, Rails.application.routes.url_helpers)
|
||||||
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self)
|
ActionController::Base.helpers.link_to name, ActionController::Base.helpers.project_job_path(project, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.default_for(time_entry)
|
||||||
|
projects = [time_entry.project, time_entry.project.parent]
|
||||||
|
jobs = Job.where(project: projects).active
|
||||||
|
support = jobs.where(category: JobCategory.support).first
|
||||||
|
retainer = jobs.where(category: JobCategory.retainer).first
|
||||||
|
sprints = jobs.where(category: JobCategory.sprints).first
|
||||||
|
priority_list = [sprints, retainer, support].compact
|
||||||
|
|
||||||
|
return jobs.first if priority_list.empty?
|
||||||
|
|
||||||
|
return support if time_entry.activity.name == "Support"
|
||||||
|
|
||||||
|
return priority_list.first if time_entry.issue.blank?
|
||||||
|
|
||||||
|
return support if time_entry.issue.tracker.name == "Support"
|
||||||
|
|
||||||
|
priority_list.first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@ class JobCategory < Enumeration
|
||||||
|
|
||||||
OptionName = :enumeration_job_category
|
OptionName = :enumeration_job_category
|
||||||
|
|
||||||
|
scope :support, -> { where(name: 'Support').first }
|
||||||
|
scope :retainer, -> { where(name: 'Retainer').first }
|
||||||
|
scope :sprints, -> { where(name: 'Sprints').first }
|
||||||
|
|
||||||
def option_name
|
def option_name
|
||||||
OptionName
|
OptionName
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,5 +7,13 @@ module TimeEntryPatch
|
||||||
|
|
||||||
included do
|
included do
|
||||||
belongs_to :job
|
belongs_to :job
|
||||||
|
|
||||||
|
before_save :set_job, unless: :job
|
||||||
|
|
||||||
|
def set_job
|
||||||
|
return if job.present?
|
||||||
|
|
||||||
|
self.job = Job.default_for(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue