[#6574] Add a TimeEntryActivity to OverheadBudgets
This commit is contained in:
@@ -31,6 +31,7 @@ class Deliverable < ActiveRecord::Base
|
|||||||
delegate "open?", :to => :contract, :prefix => true, :allow_nil => true
|
delegate "open?", :to => :contract, :prefix => true, :allow_nil => true
|
||||||
delegate "closed?", :to => :contract, :prefix => true, :allow_nil => true
|
delegate "closed?", :to => :contract, :prefix => true, :allow_nil => true
|
||||||
delegate "locked?", :to => :contract, :prefix => true, :allow_nil => true
|
delegate "locked?", :to => :contract, :prefix => true, :allow_nil => true
|
||||||
|
delegate :project, :to => :contract, :allow_nil => true
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
before_destroy :block_on_locked_contracts
|
before_destroy :block_on_locked_contracts
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ class OverheadBudget < ActiveRecord::Base
|
|||||||
|
|
||||||
# Associations
|
# Associations
|
||||||
belongs_to :deliverable
|
belongs_to :deliverable
|
||||||
|
belongs_to :time_entry_activity
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
|
validates_presence_of :time_entry_activity_id
|
||||||
|
|
||||||
# Accessors
|
# Accessors
|
||||||
include DollarizedAttribute
|
include DollarizedAttribute
|
||||||
|
|||||||
@@ -41,7 +41,8 @@
|
|||||||
<%= overhead_budget.hidden_field(:month) %>
|
<%= overhead_budget.hidden_field(:month) %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<%= release(3, "Select field for the Time Entry Activity in a td") %>
|
<%= overhead_budget.label(:time_entry_activity_id, :class => "hidden") %>
|
||||||
|
<%= overhead_budget.select(:time_entry_activity_id, options_from_collection_for_select(@project.non_billable_activities, :id, :name, overhead_budget.object.time_entry_activity_id), {:include_blank => false}, {:class => 'financial'}) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p class="inline-hints"><%= overhead_budget.label(:hours, l(:text_short_hours)) %></p>
|
<p class="inline-hints"><%= overhead_budget.label(:hours, l(:text_short_hours)) %></p>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class AddTimeEntryActivityIdToOverheadBudgets < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :overhead_budgets, :time_entry_activity_id, :integer
|
||||||
|
add_index :overhead_budgets, :time_entry_activity_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :overhead_budgets, :time_entry_activity_id
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -171,7 +171,8 @@ module RedmineContracts
|
|||||||
|
|
||||||
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
|
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
|
||||||
:budget => old_deliverable['overhead'],
|
:budget => old_deliverable['overhead'],
|
||||||
:hours => hours.to_f.round(2))
|
:hours => hours.to_f.round(2),
|
||||||
|
:time_entry_activity => first_non_billable_activity(deliverable.project))
|
||||||
elsif old_deliverable['overhead_percent'].present?
|
elsif old_deliverable['overhead_percent'].present?
|
||||||
overhead = total * (old_deliverable['overhead_percent'].to_f / 100)
|
overhead = total * (old_deliverable['overhead_percent'].to_f / 100)
|
||||||
if @overhead_rate != 0
|
if @overhead_rate != 0
|
||||||
@@ -182,7 +183,8 @@ module RedmineContracts
|
|||||||
|
|
||||||
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
|
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
|
||||||
:budget => overhead,
|
:budget => overhead,
|
||||||
:hours => hours.to_f.round(2))
|
:hours => hours.to_f.round(2),
|
||||||
|
:time_entry_activity => first_non_billable_activity(deliverable.project))
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -233,5 +235,9 @@ module RedmineContracts
|
|||||||
def self.first_billable_activity(project)
|
def self.first_billable_activity(project)
|
||||||
project.billable_activities.first || TimeEntryActivity.first
|
project.billable_activities.first || TimeEntryActivity.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.first_non_billable_activity(project)
|
||||||
|
project.non_billable_activities.first || TimeEntryActivity.first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ module RedmineContracts
|
|||||||
activity.billable?
|
activity.billable?
|
||||||
end.first
|
end.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def non_billable_activities
|
||||||
|
activities.partition do |activity|
|
||||||
|
activity.billable?
|
||||||
|
end.second
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
within("#deliverable-overhead") do
|
within("#deliverable-overhead") do
|
||||||
|
select @non_billable_activity.name, :from => 'Activity'
|
||||||
fill_in "hrs", :with => '10'
|
fill_in "hrs", :with => '10'
|
||||||
fill_in "$", :with => '$1,000'
|
fill_in "$", :with => '$1,000'
|
||||||
end
|
end
|
||||||
@@ -266,6 +267,7 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
|||||||
@overhead_budget = @deliverable.overhead_budgets.first
|
@overhead_budget = @deliverable.overhead_budgets.first
|
||||||
assert_equal 10, @overhead_budget.hours
|
assert_equal 10, @overhead_budget.hours
|
||||||
assert_equal 1000.0, @overhead_budget.budget
|
assert_equal 1000.0, @overhead_budget.budget
|
||||||
|
assert_equal @non_billable_activity, @overhead_budget.time_entry_activity
|
||||||
|
|
||||||
assert_equal 1, @deliverable.fixed_budgets.count
|
assert_equal 1, @deliverable.fixed_budgets.count
|
||||||
@fixed_budget = @deliverable.fixed_budgets.first
|
@fixed_budget = @deliverable.fixed_budgets.first
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|||||||
|
|
||||||
class OverheadBudgetTest < ActiveSupport::TestCase
|
class OverheadBudgetTest < ActiveSupport::TestCase
|
||||||
should_belong_to :deliverable
|
should_belong_to :deliverable
|
||||||
|
should_belong_to :time_entry_activity
|
||||||
|
|
||||||
|
should_validate_presence_of :time_entry_activity_id
|
||||||
|
|
||||||
context "#budget=" do
|
context "#budget=" do
|
||||||
should "strip dollar signs when writing" do
|
should "strip dollar signs when writing" do
|
||||||
|
|||||||
Reference in New Issue
Block a user