[#4552] Add the Labor hours spent to the Deliverable details
This commit is contained in:
1 parent
7a5599b4f9
commit
38f2bcb17f
5 files changed
+116
-2
No files matched your search
@@ -86,6 +86,11 @@ class Deliverable < ActiveRecord::Base
|
|||||||
(overhead_budgets.sum(:hours) || 0.0)
|
(overhead_budgets.sum(:hours) || 0.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# OPTIMIZE: N+1
|
||||||
|
def labor_hours_spent_total(date=nil)
|
||||||
|
issues.inject(0) {|total, issue| total += issue.billable_time_spent } # From redmine_overhead
|
||||||
|
end
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def hours_spent_total
|
def hours_spent_total
|
||||||
issues.inject(0) {|total, issue| total += issue.spent_hours }
|
issues.inject(0) {|total, issue| total += issue.spent_hours }
|
||||||
|
|||||||
@@ -133,6 +133,19 @@ class RetainerDeliverable < HourlyDeliverable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def labor_hours_spent_total(date=nil)
|
||||||
|
case scope_date_status(date)
|
||||||
|
when :in
|
||||||
|
time_entries = issues.collect {|issue| issue.time_entries.all(:conditions => {:tyear => date.year, :tmonth => date.month}) }.flatten
|
||||||
|
|
||||||
|
billable_hours_on_time_entries(time_entries)
|
||||||
|
when :out
|
||||||
|
0
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fixed_budget_total(date=nil)
|
def fixed_budget_total(date=nil)
|
||||||
case scope_date_status(date)
|
case scope_date_status(date)
|
||||||
when :in
|
when :in
|
||||||
|
|||||||
@@ -54,13 +54,15 @@
|
|||||||
<td class="l"><a href="#"><strong>Labor</strong></a></td>
|
<td class="l"><a href="#"><strong>Labor</strong></a></td>
|
||||||
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(validated_period))) %></td>
|
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(validated_period))) %></td>
|
||||||
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(validated_period))) %></td>
|
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(validated_period))) %></td>
|
||||||
<td> TODO: Release 2 / TODO hrs </td>
|
<td class="labor_hours">
|
||||||
|
<%= h(format_value_field_for_contracts(deliverable.labor_hours_spent_total(validated_period))) %>/<%= h(format_value_field_for_contracts(deliverable.labor_budget_hours(validated_period))) %> <%= l(:text_short_hours) %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="l"><a href="#"><strong>Overhead</strong></a></td>
|
<td class="l"><a href="#"><strong>Overhead</strong></a></td>
|
||||||
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(validated_period))) %></td>
|
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(validated_period))) %></td>
|
||||||
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(validated_period))) %></td>
|
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(validated_period))) %></td>
|
||||||
<td> TODO: Release 2 / TODO hrs </td>
|
<td class="overhead_hours"> TODO: Release 2 / TODO hrs </td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% deliverable.fixed_budgets.by_period(validated_period).each do |fixed_budget| %>
|
<% deliverable.fixed_budgets.by_period(validated_period).each do |fixed_budget| %>
|
||||||
|
|||||||
@@ -281,6 +281,40 @@ class ContractsShowTest < ActionController::IntegrationTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "show the labor hours for the deliverable" do
|
||||||
|
configure_overhead_plugin
|
||||||
|
|
||||||
|
@manager = User.generate!
|
||||||
|
|
||||||
|
@deliverable1 = FixedDeliverable.generate!(:contract => @contract, :manager => @manager)
|
||||||
|
LaborBudget.generate!(:deliverable => @deliverable1,
|
||||||
|
:hours => 100,
|
||||||
|
:budget => 4000.5)
|
||||||
|
|
||||||
|
@issue1 = Issue.generate_for_project!(@project)
|
||||||
|
@time_entry1 = TimeEntry.generate!(:issue => @issue1,
|
||||||
|
:project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:spent_on => Date.today,
|
||||||
|
:hours => 10,
|
||||||
|
:user => @manager)
|
||||||
|
|
||||||
|
@rate = Rate.generate!(:project => @project,
|
||||||
|
:user => @manager,
|
||||||
|
:date_in_effect => Date.yesterday,
|
||||||
|
:amount => 100)
|
||||||
|
|
||||||
|
@deliverable1.issues << @issue1
|
||||||
|
|
||||||
|
assert_equal 1, @deliverable1.issues.count
|
||||||
|
|
||||||
|
visit_contract_page(@contract)
|
||||||
|
assert_select "table#deliverables" do
|
||||||
|
assert_select "td.labor_hours", :text => /10\/100/
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
should "show the current period for a Retainer" do
|
should "show the current period for a Retainer" do
|
||||||
today_mock = Date.new(2010,2,15)
|
today_mock = Date.new(2010,2,15)
|
||||||
Date.stubs(:today).returns(today_mock)
|
Date.stubs(:today).returns(today_mock)
|
||||||
|
|||||||
@@ -176,6 +176,66 @@ class RetainerDeliverableTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#labor_hours_spent_total" do
|
||||||
|
setup do
|
||||||
|
@project = Project.generate!
|
||||||
|
@contract = Contract.generate!(:billable_rate => 100, :project => @project)
|
||||||
|
@deliverable = RetainerDeliverable.generate!(:start_date => '2010-01-01', :end_date => '2010-03-31', :contract => @contract)
|
||||||
|
|
||||||
|
@manager = User.generate!
|
||||||
|
@role = Role.generate!
|
||||||
|
User.add_to_project(@manager, @project, @role)
|
||||||
|
|
||||||
|
configure_overhead_plugin
|
||||||
|
|
||||||
|
@issue1 = Issue.generate_for_project!(@project)
|
||||||
|
@time_entry1 = TimeEntry.generate!(:issue => @issue1,
|
||||||
|
:project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:spent_on => Date.new(2010,1,2),
|
||||||
|
:hours => 10,
|
||||||
|
:user => @manager)
|
||||||
|
@time_entry2 = TimeEntry.generate!(:issue => @issue1,
|
||||||
|
:project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:spent_on => Date.new(2010,2,1),
|
||||||
|
:hours => 20,
|
||||||
|
:user => @manager)
|
||||||
|
|
||||||
|
@rate = Rate.generate!(:project => @project,
|
||||||
|
:user => @manager,
|
||||||
|
:date_in_effect => Date.new(2010,1,1),
|
||||||
|
:amount => 100)
|
||||||
|
|
||||||
|
@deliverable.issues << @issue1
|
||||||
|
assert_equal 30, @deliverable.labor_hours_spent_total
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a empty period" do
|
||||||
|
should "use all periods" do
|
||||||
|
assert_equal 30.0, @deliverable.labor_hours_spent_total(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a period out of the retainer range" do
|
||||||
|
should "filter the records" do
|
||||||
|
assert_equal 0, @deliverable.labor_hours_spent_total(Date.new(2011,1,1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with an invalid period" do
|
||||||
|
should "return 0" do
|
||||||
|
assert_equal 0, @deliverable.labor_hours_spent_total('1')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a period in the retainer range" do
|
||||||
|
should "filter the records" do
|
||||||
|
assert_equal 20.0, @deliverable.labor_hours_spent_total(Date.new(2010,2,1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "#overhead_spent" do
|
context "#overhead_spent" do
|
||||||
setup do
|
setup do
|
||||||
@project = Project.generate!
|
@project = Project.generate!
|
||||||
|
|||||||
Reference in new issue
Block a user