[#4517] Default the details row to All periods when it's out of the date range
This commit is contained in:
@@ -111,4 +111,12 @@ module ContractsHelper
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
# Given a deliverable and period, validate the period
|
||||
# TODO: could use a better name
|
||||
def validate_period(deliverable, period)
|
||||
if deliverable.current_date && deliverable.within_period_range?(period)
|
||||
return period
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,6 +47,17 @@ class RetainerDeliverable < HourlyDeliverable
|
||||
date_range.include?(date)
|
||||
end
|
||||
|
||||
# period in the format of "%Y-%m" or "%B %Y"
|
||||
def within_period_range?(period)
|
||||
begin
|
||||
# both valid formats work by adding a day to the end like -01
|
||||
date = Date.parse(period.to_s + "-01")
|
||||
within_date_range?(date)
|
||||
rescue ArgumentError
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def months
|
||||
month_acc = []
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<% period ||= nil %>
|
||||
<% validated_period = validate_period(deliverable, period) %>
|
||||
|
||||
<td colspan="11" class="deliverable_details_outer_wrapper_<%= h(deliverable.id) %>">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<form method="get" action="<%= contract_deliverable_path(@project, contract, deliverable, :format => 'js', :as => 'deliverable_details_row') %>">
|
||||
<fieldset>
|
||||
<select name="period" id="retainer_period_change_<%= h(deliverable.id) %>" class="retainer_period_change">
|
||||
<%= retainer_period_options(deliverable, :selected => period) %>
|
||||
<%= retainer_period_options(deliverable, :selected => validated_period) %>
|
||||
</select>
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -52,28 +52,28 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="l"><a href="#"><strong>Labor</strong></a></td>
|
||||
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(period))) %></td>
|
||||
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(period))) %></td>
|
||||
<td class="labor_budget_spent"><%= h(format_value_field_for_contracts(deliverable.labor_budget_spent(validated_period))) %></td>
|
||||
<td class="labor_budget_total"><%= h(format_value_field_for_contracts(deliverable.labor_budget_total(validated_period))) %></td>
|
||||
<td> TODO: Release 2 / TODO hrs </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="l"><a href="#"><strong>Overhead</strong></a></td>
|
||||
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(period))) %></td>
|
||||
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(period))) %></td>
|
||||
<td class="overhead_budget_spent"><%= h(format_value_field_for_contracts(deliverable.overhead_spent(validated_period))) %></td>
|
||||
<td class="overhead_budget_total"><%= h(format_value_field_for_contracts(deliverable.overhead_budget_total(validated_period))) %></td>
|
||||
<td> TODO: Release 2 / TODO hrs </td>
|
||||
</tr>
|
||||
<%# TODO: Release 2, Fixed %>
|
||||
<%# TODO: Release 2, Markup %>
|
||||
<tr>
|
||||
<td class="l">Profit</td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_left(period))) %></td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_budget(period))) %></td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_left(validated_period))) %></td>
|
||||
<td><%= h(format_value_field_for_contracts(deliverable.profit_budget(validated_period))) %></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="total">
|
||||
<td class="l"><strong>Total:</strong></td>
|
||||
<td class="total_spent"><strong><%= h(format_value_field_for_contracts(deliverable.total_spent(period))) %></strong></td>
|
||||
<td class="total"><strong><%= h(format_value_field_for_contracts(deliverable.total(period))) %></strong></td>
|
||||
<td class="total_spent"><strong><%= h(format_value_field_for_contracts(deliverable.total_spent(validated_period))) %></strong></td>
|
||||
<td class="total"><strong><%= h(format_value_field_for_contracts(deliverable.total(validated_period))) %></strong></td>
|
||||
<td><strong>TODO: Release 2</strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
31
test/unit/helpers/contracts_helper_test.rb
Normal file
31
test/unit/helpers/contracts_helper_test.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ContractsHelperTest < ActionView::TestCase
|
||||
context "#validate_period" do
|
||||
should "with a HourlyDeliverable should return nil" do
|
||||
assert_equal nil, validate_period(HourlyDeliverable.new, '2010-01')
|
||||
end
|
||||
|
||||
should "with a FixedDeliverable should return nil" do
|
||||
assert_equal nil, validate_period(FixedDeliverable.new, '2010-01')
|
||||
end
|
||||
|
||||
context "with a RetainerDeliverable" do
|
||||
should "return nil when there period is not within the Deliverable's date range" do
|
||||
retainer = RetainerDeliverable.new(:start_date => Date.new(2011,1,1),
|
||||
:end_date => Date.new(2012,1,1))
|
||||
|
||||
assert_equal nil, validate_period(retainer, '2010-01')
|
||||
end
|
||||
|
||||
should "return the period when it's within the Deliverable's date range" do
|
||||
retainer = RetainerDeliverable.new(:start_date => Date.new(2001,1,1),
|
||||
:end_date => Date.new(2003,1,1))
|
||||
|
||||
assert_equal '2001-02', validate_period(retainer, '2001-02')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user