diff --git a/app/models/labor_budget.rb b/app/models/labor_budget.rb index 831fc91..71c0319 100644 --- a/app/models/labor_budget.rb +++ b/app/models/labor_budget.rb @@ -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 diff --git a/app/views/deliverables/_finance_form.html.erb b/app/views/deliverables/_finance_form.html.erb index f26472b..654f80e 100644 --- a/app/views/deliverables/_finance_form.html.erb +++ b/app/views/deliverables/_finance_form.html.erb @@ -13,7 +13,8 @@ <%= labor_budget.hidden_field(:month) %> - <%= 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'}) %>

<%= labor_budget.label(:hours, l(:text_short_hours)) %>

diff --git a/assets/stylesheets/redmine_contracts.css b/assets/stylesheets/redmine_contracts.css index 20b0b48..37d3bbe 100644 --- a/assets/stylesheets/redmine_contracts.css +++ b/assets/stylesheets/redmine_contracts.css @@ -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; } diff --git a/config/locales/en.yml b/config/locales/en.yml index acb3852..fc61d00 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/db/migrate/020_add_time_entry_activity_id_to_labor_budgets.rb b/db/migrate/020_add_time_entry_activity_id_to_labor_budgets.rb new file mode 100644 index 0000000..95f9251 --- /dev/null +++ b/db/migrate/020_add_time_entry_activity_id_to_labor_budgets.rb @@ -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 diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 63e5260..6625e51 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -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
" + old_deliverable.pretty_inspect + "
" end + + def self.first_billable_activity(project) + project.billable_activities.first || TimeEntryActivity.first + end end end diff --git a/lib/redmine_contracts/patches/project_patch.rb b/lib/redmine_contracts/patches/project_patch.rb index f462171..f42a3b3 100644 --- a/lib/redmine_contracts/patches/project_patch.rb +++ b/lib/redmine_contracts/patches/project_patch.rb @@ -16,6 +16,11 @@ module RedmineContracts end module InstanceMethods + def billable_activities + activities.partition do |activity| + activity.billable? + end.first + end end end end diff --git a/test/integration/deliverables_edit_test.rb b/test/integration/deliverables_edit_test.rb index 8d1b569..9682f67 100644 --- a/test/integration/deliverables_edit_test.rb +++ b/test/integration/deliverables_edit_test.rb @@ -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 diff --git a/test/integration/deliverables_new_test.rb b/test/integration/deliverables_new_test.rb index 97edac4..3792029 100644 --- a/test/integration/deliverables_new_test.rb +++ b/test/integration/deliverables_new_test.rb @@ -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 diff --git a/test/unit/labor_budget_test.rb b/test/unit/labor_budget_test.rb index f264ce5..9d44c98 100644 --- a/test/unit/labor_budget_test.rb +++ b/test/unit/labor_budget_test.rb @@ -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