[#4477] Added FixedBudgets to the Deliverable finance form.
This commit is contained in:
@@ -3,6 +3,7 @@ module ContractsHelper
|
||||
returning(deliverable) do |d|
|
||||
d.labor_budgets.build if d.labor_budgets.empty?
|
||||
d.overhead_budgets.build if d.overhead_budgets.empty?
|
||||
d.fixed_budgets.build if d.fixed_budgets.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ class Deliverable < ActiveRecord::Base
|
||||
|
||||
accepts_nested_attributes_for :labor_budgets
|
||||
accepts_nested_attributes_for :overhead_budgets
|
||||
accepts_nested_attributes_for :fixed_budgets
|
||||
|
||||
# Validations
|
||||
validates_presence_of :title
|
||||
|
||||
@@ -7,6 +7,14 @@ class FixedBudget < ActiveRecord::Base
|
||||
# Validations
|
||||
|
||||
# Accessors
|
||||
def budget=(v)
|
||||
if v.is_a? String
|
||||
write_attribute(:budget, v.gsub(/[$ ,]/, ''))
|
||||
else
|
||||
write_attribute(:budget, v)
|
||||
end
|
||||
end
|
||||
|
||||
def markup_value
|
||||
return 0 if budget.blank? || markup.blank?
|
||||
|
||||
|
||||
@@ -83,6 +83,12 @@ class RetainerDeliverable < HourlyDeliverable
|
||||
budgets
|
||||
end
|
||||
|
||||
def fixed_budgets_for_date(date)
|
||||
budgets = fixed_budgets.all(:conditions => {:year => date.year, :month => date.month})
|
||||
budgets = [fixed_budgets.build(:year => date.year, :month => date.month)] if budgets.empty?
|
||||
budgets
|
||||
end
|
||||
|
||||
def labor_budget_total(date=nil)
|
||||
case scope_date_status(date)
|
||||
when :in
|
||||
|
||||
@@ -62,6 +62,37 @@
|
||||
</table>
|
||||
</li>
|
||||
|
||||
<li class="numeric optional">
|
||||
<div id="deliverable-fixed" class="fixed-item-form">
|
||||
<label for="contract_discount">Fixed</label>
|
||||
|
||||
<% form.fields_for :fixed_budgets, fixed_budgets do |fixed_budget| %>
|
||||
<p class="inline-hints" style="display:none;"><%= fixed_budget.label(:title, l(:field_title))%></p>
|
||||
<%= fixed_budget.text_field(:title) %>
|
||||
|
||||
<p class="inline-hints">
|
||||
<%= fixed_budget.label(:budget, l(:field_budget), :style => 'display: none;')%> <%# Hidden label :| %>
|
||||
<%= l(:text_dollar_sign) %>
|
||||
</p>
|
||||
<%= fixed_budget.text_field(:budget) %>
|
||||
|
||||
<p class="inline-hints">
|
||||
<%= fixed_budget.label(:markup, l(:field_markup), :style => 'display: none;')%> <%# Hidden label :| %>
|
||||
<%= l(:field_discount_hint) %>
|
||||
</p>
|
||||
<%= fixed_budget.text_field(:markup) %>
|
||||
|
||||
<p class="inline-hints" style="display:none;"><%= fixed_budget.label(:description, l(:field_description), :for => "fixed-description#{fixed_budget.object.object_id}")%></p>
|
||||
<%= fixed_budget.text_area(:description, :class => 'wiki-edit', :rows => '5', :id => "fixed-description#{fixed_budget.object.object_id}") %>
|
||||
<%= wikitoolbar_for "fixed-description#{fixed_budget.object.object_id}" %>
|
||||
|
||||
<p>Todo: Add button (Release 3)</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
<%= form.input :total, :input_html => {:size => 10}, :wrapper_html => {:class => 'deliverable_total_input'}, :hint => l(:text_dollar_sign) %>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<%= javascript_tag("var i18nChangedPeriodMessage = '#{l(:text_changed_period_message)}'") %>
|
||||
|
||||
<div class="box tabular">
|
||||
<% form.inputs :name => l(:text_deliverable_details_legend) do %>
|
||||
<% form.inputs :name => l(:text_deliverable_details_legend), :id => 'deliverable-details' do %>
|
||||
<%# Used by jquery to check if this is a new or existing record %>
|
||||
<%= hidden_field_tag('deliverable_id', h(resource.id), :id => 'deliverable_stored_id') %>
|
||||
<%= form.input :title, :required => true %>
|
||||
@@ -40,13 +40,13 @@
|
||||
<% if resource.retainer? && resource.respond_to?(:months) %>
|
||||
<% if resource.months.present? %>
|
||||
<% resource.months.each do |month| %>
|
||||
<%= render :partial => 'finance_form', :locals => {:form => form, :labor_budgets => resource.labor_budgets_for_date(month), :overhead_budgets => resource.overhead_budgets_for_date(month), :label => l(:text_deliverable_finances_date, :date => month.strftime("%B, %Y")), :fieldset_class => 'date-' + month.strftime('%Y-%m') } %>
|
||||
<%= render :partial => 'finance_form', :locals => {:form => form, :labor_budgets => resource.labor_budgets_for_date(month), :overhead_budgets => resource.overhead_budgets_for_date(month), :fixed_budgets => resource.fixed_budgets_for_date(month), :label => l(:text_deliverable_finances_date, :date => month.strftime("%B, %Y")), :fieldset_class => 'date-' + month.strftime('%Y-%m') } %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= content_tag(:p, l(:text_missing_period), :class => 'nodata') %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render :partial => 'finance_form', :locals => {:form => form, :labor_budgets => resource.labor_budgets, :overhead_budgets => resource.overhead_budgets, :label => l(:text_deliverable_finances), :fieldset_class => '' } %>
|
||||
<%= render :partial => 'finance_form', :locals => {:form => form, :labor_budgets => resource.labor_budgets, :overhead_budgets => resource.overhead_budgets, :fixed_budgets => resource.fixed_budgets, :label => l(:text_deliverable_finances), :fieldset_class => '' } %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -70,4 +70,5 @@ en:
|
||||
text_flash_deliverable_created: "Deliverable: {{name}} was successfully created."
|
||||
text_flash_deliverable_updated: "Deliverable: {{name}} was successfully updated."
|
||||
text_flash_deliverable_destroyed: "Deliverable: {{name}} was successfully destroyed."
|
||||
|
||||
field_budget: Budget
|
||||
field_markup: Markup
|
||||
|
||||
14
db/migrate/016_add_year_and_month_to_fixed_budgets.rb
Normal file
14
db/migrate/016_add_year_and_month_to_fixed_budgets.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class AddYearAndMonthToFixedBudgets < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :fixed_budgets, :year, :integer
|
||||
add_index :fixed_budgets, :year
|
||||
|
||||
add_column :fixed_budgets, :month, :integer
|
||||
add_index :fixed_budgets, :month
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :fixed_budgets, :year
|
||||
remove_column :fixed_budgets, :month
|
||||
end
|
||||
end
|
||||
@@ -50,12 +50,15 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
click_link 'Add New'
|
||||
assert_response :success
|
||||
|
||||
within("#deliverable-details") do
|
||||
fill_in "Title", :with => 'A New Deliverable'
|
||||
select "Fixed", :from => "Type"
|
||||
select @manager.name, :from => "Manager"
|
||||
fill_in "Start", :with => '2010-01-01'
|
||||
fill_in "End Date", :with => '2010-12-31'
|
||||
fill_in "Notes", :with => 'Some notes on the deliverable'
|
||||
end
|
||||
|
||||
fill_in "Total", :with => '1,000.00'
|
||||
# TODO: webrat can't trigger DOM events so it can't appear
|
||||
# assert js("jQuery('#deliverable_total').is(':visible')"), "Total is hidden when it should be visible"
|
||||
@@ -84,12 +87,14 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
click_link 'Add New'
|
||||
assert_response :success
|
||||
|
||||
within("#deliverable-details") do
|
||||
fill_in "Title", :with => 'A New Deliverable'
|
||||
select "Hourly", :from => "Type"
|
||||
select @manager.name, :from => "Manager"
|
||||
fill_in "Start", :with => '2010-01-01'
|
||||
fill_in "End Date", :with => '2010-12-31'
|
||||
fill_in "Notes", :with => 'Some notes on the deliverable'
|
||||
end
|
||||
fill_in "Total", :with => '1,000.00'
|
||||
|
||||
# # Hide and clear the total
|
||||
@@ -120,12 +125,14 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
click_link 'Add New'
|
||||
assert_response :success
|
||||
|
||||
within("#deliverable-details") do
|
||||
fill_in "Title", :with => 'A New Deliverable'
|
||||
select "Retainer", :from => "Type"
|
||||
select @manager.name, :from => "Manager"
|
||||
fill_in "Start", :with => '2010-01-01'
|
||||
fill_in "End Date", :with => '2010-12-31'
|
||||
fill_in "Notes", :with => 'Some notes on the deliverable'
|
||||
end
|
||||
|
||||
within("#deliverable-labor") do
|
||||
fill_in "hrs", :with => '20'
|
||||
@@ -193,12 +200,14 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
click_link 'Add New'
|
||||
assert_response :success
|
||||
|
||||
within("#deliverable-details") do
|
||||
fill_in "Title", :with => 'A New Deliverable'
|
||||
select "Hourly", :from => "Type"
|
||||
select @manager.name, :from => "Manager"
|
||||
fill_in "Start", :with => '2010-01-01'
|
||||
fill_in "End Date", :with => '2010-12-31'
|
||||
fill_in "Notes", :with => 'Some notes on the deliverable'
|
||||
end
|
||||
|
||||
within("#deliverable-labor") do
|
||||
fill_in "hrs", :with => '20'
|
||||
@@ -210,6 +219,13 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
fill_in "$", :with => '$1,000'
|
||||
end
|
||||
|
||||
within("#deliverable-fixed") do
|
||||
fill_in "title", :with => 'Flight to NYC'
|
||||
fill_in "budget", :with => '$600'
|
||||
fill_in "markup", :with => '50%'
|
||||
fill_in "description", :with => 'Need to fly to NYC for the week'
|
||||
end
|
||||
|
||||
click_button "Save"
|
||||
|
||||
assert_response :success
|
||||
@@ -226,6 +242,14 @@ class DeliverablesNewTest < ActionController::IntegrationTest
|
||||
@overhead_budget = @deliverable.overhead_budgets.first
|
||||
assert_equal 10, @overhead_budget.hours
|
||||
assert_equal 1000.0, @overhead_budget.budget
|
||||
|
||||
assert_equal 1, @deliverable.fixed_budgets.count
|
||||
@fixed_budget = @deliverable.fixed_budgets.first
|
||||
assert_equal "Flight to NYC", @fixed_budget.title
|
||||
assert_equal 600, @fixed_budget.budget
|
||||
assert_equal "50%", @fixed_budget.markup
|
||||
assert_equal 300, @fixed_budget.markup_value # 600 * 50%
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user