[#4477] Hook up FixedBudgets to Contract#fixed_budget and #fixed_markup_budget
This commit is contained in:
+12
-2
@@ -36,8 +36,8 @@ class Contract < ActiveRecord::Base
|
||||
named_scope :by_name, {:order => "#{Contract.table_name}.name ASC"}
|
||||
|
||||
[:status, :contract_type,
|
||||
:fixed_spent, :fixed_budget,
|
||||
:markup_spent, :markup_budget,
|
||||
:fixed_spent,
|
||||
:fixed_markup_spent,
|
||||
:discount_spent, :discount_budget
|
||||
].each do |mthd|
|
||||
define_method(mthd) { "TODO in later release" }
|
||||
@@ -96,6 +96,16 @@ class Contract < ActiveRecord::Base
|
||||
end
|
||||
alias_method :profit_spent, :profit_left
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_budget
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_budget_total }
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_budget
|
||||
deliverables.inject(0) {|total, deliverable| total += deliverable.fixed_markup_budget_total }
|
||||
end
|
||||
|
||||
def after_initialize
|
||||
self.executed = false unless self.executed.present?
|
||||
end
|
||||
|
||||
@@ -88,6 +88,15 @@ class Deliverable < ActiveRecord::Base
|
||||
issues.inject(0) {|total, issue| total += issue.spent_hours }
|
||||
end
|
||||
|
||||
def fixed_budget_total(date=nil)
|
||||
fixed_budgets.sum(:budget)
|
||||
end
|
||||
|
||||
# OPTIMIZE: N+1
|
||||
def fixed_markup_budget_total(date=nil)
|
||||
fixed_budgets.inject(0) {|total, fixed_budget| total += fixed_budget.markup_value }
|
||||
end
|
||||
|
||||
def filter_by_date(date=nil, &block)
|
||||
block.call
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<%= show_budget_field(resource, :labor_spent, :labor_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-labor'}, :label_html_options => {:width => '46%'}) %>
|
||||
<%= show_budget_field(resource, :overhead_spent, :overhead_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-overhead'}) %>
|
||||
<%= show_budget_field(resource, :fixed_spent, :fixed_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-fixed'}) %>
|
||||
<%= show_budget_field(resource, :markup_spent, :markup_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-markup'}) %>
|
||||
<%= show_budget_field(resource, :fixed_markup_spent, :fixed_markup_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-markup'}) %>
|
||||
<%= show_budget_field(resource, :profit_spent, :profit_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-profit'}) %>
|
||||
<%= show_budget_field(resource, :discount_spent, :discount_budget, :format => :format_value_field_for_contracts, :html_options => {:class => 'contract-discount'}) %>
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ en:
|
||||
field_fixed_spent: "Fixed"
|
||||
field_labor_budget: "Labor"
|
||||
field_labor_spent: "Labor"
|
||||
field_markup_budget: "Markup"
|
||||
field_markup_spent: "Markup"
|
||||
field_fixed_markup_budget: "Markup"
|
||||
field_fixed_markup_spent: "Markup"
|
||||
field_overhead_budget: "Overhead"
|
||||
field_overhead_spent: "Overhead"
|
||||
field_profit_budget: "Profit"
|
||||
|
||||
@@ -254,4 +254,38 @@ class ContractTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "#fixed_budget" do
|
||||
should "sum all fixed budget amounts on the Deliverables" do
|
||||
contract = Contract.generate!
|
||||
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!
|
||||
FixedBudget.generate!(:deliverable => @deliverable_1, :budget => '$1,000')
|
||||
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!
|
||||
FixedBudget.generate!(:deliverable => @deliverable_2, :budget => '$2,000')
|
||||
|
||||
assert_equal 3000, contract.fixed_budget
|
||||
end
|
||||
end
|
||||
|
||||
context "#fixed_spent" do
|
||||
should "QUESTION: how to compute the amount spent"
|
||||
end
|
||||
|
||||
context "#fixed_markup_budget" do
|
||||
should "sum all fixed budget markup values on the Deliverables" do
|
||||
contract = Contract.generate!
|
||||
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!
|
||||
FixedBudget.generate!(:deliverable => @deliverable_1, :budget => '$1,000', :markup => '$100')
|
||||
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!
|
||||
FixedBudget.generate!(:deliverable => @deliverable_2, :budget => '$2,000', :markup => '200%')
|
||||
|
||||
assert_equal (100) + (2.00 * 2000), contract.fixed_markup_budget
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "#fixed_markup_spent" do
|
||||
should "QUESTION: how to compute the amount spent"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user