[#6574] Associate LaborBudgets with TimeEntryActivities

This commit is contained in:
Eric Davis
2011-09-14 18:39:49 -07:00
parent 38c22e2f92
commit df61a1fe9e
10 changed files with 34 additions and 2 deletions
+2
View File
@@ -3,8 +3,10 @@ class LaborBudget < ActiveRecord::Base
# Associations
belongs_to :deliverable
belongs_to :time_entry_activity
# Validations
validates_presence_of :time_entry_activity_id
# Accessors
include DollarizedAttribute
@@ -13,7 +13,8 @@
<%= labor_budget.hidden_field(:month) %>
<tr>
<td>
<%= release(3, "Select field for the Time Entry Activity in a td") %>
<%= labor_budget.label(:time_entry_activity_id, :class => "hidden") %>
<%= labor_budget.select(:time_entry_activity_id, options_from_collection_for_select(@project.billable_activities, :id, :name, labor_budget.object.time_entry_activity_id), {:include_blank => false}, {:class => 'financial'}) %>
</td>
<td>
<p class="inline-hints"><%= labor_budget.label(:hours, l(:text_short_hours)) %></p>
+1
View File
@@ -26,6 +26,7 @@ html>body .tabular li {overflow:hidden;}
.tabular li.hidden { height: 0; padding: 0; margin: 0; }
/* End tabular */
.hidden { display: none; }
a.contract-delete {color: red; }
.overage { color: #A40000; }
+1
View File
@@ -100,3 +100,4 @@ en:
text_deliverable_closed_warning: "This deliverable is closed and cannot be saved without changing it's status to Open."
text_contract_locked_warning: "This contract is locked and cannot be saved without changing it's status to Open."
text_contract_closed_warning: "This contract is closed and cannot be saved without changing it's status to Open."
field_time_entry_activity: "Activity"
@@ -0,0 +1,10 @@
class AddTimeEntryActivityIdToLaborBudgets < ActiveRecord::Migration
def self.up
add_column :labor_budgets, :time_entry_activity_id, :integer
add_index :labor_budgets, :time_entry_activity_id
end
def self.down
remove_column :labor_budgets, :time_entry_activity_id
end
end
@@ -103,7 +103,8 @@ module RedmineContracts
if old_deliverable['total_hours'].present? || old_deliverable['cost_per_hour'].present?
deliverable.labor_budgets << LaborBudget.new(:deliverable => deliverable,
:budget => @total_cost,
:hours => old_deliverable['total_hours'])
:hours => old_deliverable['total_hours'],
:time_entry_activity => first_billable_activity(project))
end
else
@total_cost = 0
@@ -228,5 +229,9 @@ module RedmineContracts
def self.append_old_deliverable_to_notes(old_deliverable, new_deliverable)
new_deliverable.notes += "Converted data:\n<pre>" + old_deliverable.pretty_inspect + "</pre>"
end
def self.first_billable_activity(project)
project.billable_activities.first || TimeEntryActivity.first
end
end
end
@@ -16,6 +16,11 @@ module RedmineContracts
end
module InstanceMethods
def billable_activities
activities.partition do |activity|
activity.billable?
end.first
end
end
end
end
@@ -13,6 +13,7 @@ class DeliverablesEditTest < ActionController::IntegrationTest
@hourly_deliverable = HourlyDeliverable.generate!(:contract => @contract, :manager => @manager, :title => 'An Hourly')
@user = User.generate_user_with_permission_to_manage_budget(:project => @project)
configure_overhead_plugin
login_as(@user.login, 'contracts')
end
@@ -7,6 +7,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest
@project = Project.generate!(:identifier => 'main')
@contract = Contract.generate!(:project => @project)
@user = User.generate_user_with_permission_to_manage_budget(:project => @project)
configure_overhead_plugin
login_as(@user.login, 'contracts')
end
@@ -231,6 +232,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest
end
within("#deliverable-labor") do
select @billable_activity.name, :from => 'Activity'
fill_in "hrs", :with => '20'
fill_in "$", :with => '$2,000'
end
@@ -258,6 +260,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest
@labor_budget = @deliverable.labor_budgets.first
assert_equal 20, @labor_budget.hours
assert_equal 2000.0, @labor_budget.budget
assert_equal @billable_activity, @labor_budget.time_entry_activity
assert_equal 1, @deliverable.overhead_budgets.count
@overhead_budget = @deliverable.overhead_budgets.first
+3
View File
@@ -2,6 +2,9 @@ require File.dirname(__FILE__) + '/../test_helper'
class LaborBudgetTest < ActiveSupport::TestCase
should_belong_to :deliverable
should_belong_to :time_entry_activity
should_validate_presence_of :time_entry_activity_id
context "#budget=" do
should "strip dollar signs when writing" do