[#4183] Implemented HourlyDeliverable#total_spent.
This commit is contained in:
@@ -22,6 +22,22 @@ class HourlyDeliverable < Deliverable
|
|||||||
return contract.billable_rate * labor_budgets.sum(:hours)
|
return contract.billable_rate * labor_budgets.sum(:hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Total amount to be billed on the deliverable, using the total time logged
|
||||||
|
# and the contract rate
|
||||||
|
def total_spent
|
||||||
|
return 0 if contract.nil?
|
||||||
|
return 0 if contract.billable_rate.blank?
|
||||||
|
return 0 unless self.issues.count > 0
|
||||||
|
|
||||||
|
time_logs = self.issues.collect(&:time_entries).flatten
|
||||||
|
hours = time_logs.inject(0) {|total, time_entry|
|
||||||
|
total += time_entry.hours if time_entry.billable?
|
||||||
|
total
|
||||||
|
}
|
||||||
|
|
||||||
|
return hours * contract.billable_rate
|
||||||
|
end
|
||||||
|
|
||||||
# Block setting the total on HourlyDeliverables
|
# Block setting the total on HourlyDeliverables
|
||||||
def total=(v)
|
def total=(v)
|
||||||
nil
|
nil
|
||||||
|
|||||||
@@ -30,6 +30,26 @@ class HourlyDeliverableTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#total_spent" do
|
||||||
|
should "be equal to the number of hours used multipled by the contract rate" do
|
||||||
|
configure_overhead_plugin
|
||||||
|
|
||||||
|
contract = Contract.generate!(:billable_rate => 150.0)
|
||||||
|
@project = Project.generate!
|
||||||
|
@developer = User.generate!
|
||||||
|
@role = Role.generate!
|
||||||
|
User.add_to_project(@developer, @project, @role)
|
||||||
|
|
||||||
|
d = HourlyDeliverable.generate!(:contract => contract)
|
||||||
|
d.issues << @issue1 = Issue.generate_for_project!(@project)
|
||||||
|
TimeEntry.generate!(:hours => 15, :issue => @issue1, :project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:user => @developer)
|
||||||
|
|
||||||
|
assert_equal 2250, d.total_spent
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "#total=" do
|
context "#total=" do
|
||||||
should "not write any attributes" do
|
should "not write any attributes" do
|
||||||
d = HourlyDeliverable.new
|
d = HourlyDeliverable.new
|
||||||
|
|||||||
Reference in New Issue
Block a user