Calc cleanup

This commit is contained in:
Eric Davis
2008-06-03 17:19:30 -07:00
parent 5180b5b218
commit 490bf73efe
8 changed files with 45 additions and 1 deletions
+1
View File
@@ -64,6 +64,7 @@ class Budget
def progress
return 100 unless self.deliverables.size > 0
return 100 if self.budget == 0.0
balance = 0.0
+1
View File
@@ -42,6 +42,7 @@ class Deliverable < ActiveRecord::Base
end
def budget_ratio
return 0.0 if self.budget.nil? || self.budget == 0.0
return ((self.spent / self.budget) * 100).round
end
+8
View File
@@ -9,4 +9,12 @@ class FixedDeliverable < Deliverable
def spent
(self.progress.to_f / 100 ) * self.budget
end
def profit
if read_attribute(:profit_percent).nil?
return super
else
return (read_attribute(:profit_percent).to_f / 100.0) * read_attribute(:fixed_cost)
end
end
end
+8
View File
@@ -22,5 +22,13 @@ class HourlyDeliverable < Deliverable
return self.issues.collect(&:time_entries).flatten.collect(&:hours).sum
end
def profit
if read_attribute(:profit_percent).nil?
return super
else
return (read_attribute(:profit_percent).to_f / 100.0) * (read_attribute(:cost_per_hour) * read_attribute(:total_hours))
end
end
end
+12
View File
@@ -186,6 +186,18 @@ describe Budget, '.progress' do
@budget = Budget.new(@project.id)
@budget.progress.should eql(100)
end
it 'should return 100 if there is no budget' do
@deliverable1 = mock_model(Deliverable, :project_id => @project, :budget => 0.00, :progress => 50)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :budget => 0.00, :progress => 75)
@project = mock_model(Project)
Deliverable.stub!(:find_all_by_project_id).and_return([@deliverable1, @deliverable2])
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.progress.should eql(100)
end
end
describe Budget,'.budget' do
+1 -1
View File
@@ -113,7 +113,7 @@ end
describe Deliverable, '.budget_ratio' do
it 'should be the whole number of the budget spent' do
@deliverable = Deliverable.new({ :subject => 'test' })
@deliverable.should_receive(:budget).and_return(3000.00)
@deliverable.should_receive(:budget).exactly(3).times.and_return(3000.00)
@deliverable.should_receive(:spent).and_return(1000.00)
@deliverable.budget_ratio.should eql(33)
+7
View File
@@ -15,3 +15,10 @@ describe FixedDeliverable, '.spent' do
@deliverable.spent.should eql(2500.0)
end
end
describe FixedDeliverable, '.profit as a %' do
it 'should return the % of the fixed bid amount' do
@deliverable = FixedDeliverable.new({ :subject => 'test', :profit_percent => 50, :fixed_cost => 1000.0 })
@deliverable.profit.should eql(500.0)
end
end
+7
View File
@@ -26,3 +26,10 @@ describe HourlyDeliverable, '.spent' do
@deliverable.spent.should eql(60.0)
end
end
describe HourlyDeliverable, '.profit as a %' do
it 'should return the % of the hours mutipled by the cost per hour amount' do
@deliverable = HourlyDeliverable.new({ :subject => 'test', :profit_percent => 50, :cost_per_hour => 100.0, :total_hours => 10 })
@deliverable.profit.should eql(500.0)
end
end