Auto-assign logged time to budgets
Now that users have a "budget category" assigned to them, we can show time logged against the correct budget. Refs #2165
This commit is contained in:
parent
a697bbf7be
commit
3e04193d16
|
@ -7,6 +7,9 @@ module JobsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def progress_bar_for(budget)
|
def progress_bar_for(budget)
|
||||||
l_hours_short(budget.hours)
|
progress_bar(budget.done_ratio,
|
||||||
|
legend: "#{budget.done_ratio}%
|
||||||
|
(#{l_hours_short(budget.total_time_logged)}/#{l_hours_short(budget.hours)})",
|
||||||
|
class: "progress")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,12 +35,6 @@ class Job < ActiveRecord::Base
|
||||||
time_budgets.sum(&:hours)
|
time_budgets.sum(&:hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
def time_budget_for(category)
|
|
||||||
return 0 if category.nil? || time_budgets.find_by(category_id: category.id).nil?
|
|
||||||
|
|
||||||
time_budgets.find_by(category_id: category.id).hours
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_time_logged
|
def total_time_logged
|
||||||
TimeEntry.where(job_id: id)
|
TimeEntry.where(job_id: id)
|
||||||
.sum(:hours)
|
.sum(:hours)
|
||||||
|
|
|
@ -10,4 +10,18 @@ class TimeBudget < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :job
|
belongs_to :job
|
||||||
belongs_to :category, class_name: "TimeBudgetCategory"
|
belongs_to :category, class_name: "TimeBudgetCategory"
|
||||||
|
|
||||||
|
def done_ratio
|
||||||
|
return 0 if hours.zero?
|
||||||
|
|
||||||
|
(total_time_logged / hours * 100).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def total_time_logged
|
||||||
|
TimeEntry.joins(:user)
|
||||||
|
.where(
|
||||||
|
job_id: job_id,
|
||||||
|
users: { time_budget_category_id: category_id }
|
||||||
|
).sum(:hours)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue