From feee5e8b43f7851e6e5bf09f30f2ba7bcd002ede Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 9 Sep 2010 17:06:35 -0700 Subject: [PATCH] [#4477] Added FixedBudgets to the Deliverable finance form. --- app/helpers/contracts_helper.rb | 1 + app/models/deliverable.rb | 1 + app/models/fixed_budget.rb | 8 ++ app/models/retainer_deliverable.rb | 6 ++ app/views/deliverables/_finance_form.html.erb | 31 ++++++++ app/views/deliverables/_form.html.erb | 6 +- config/locales/en.yml | 3 +- ...016_add_year_and_month_to_fixed_budgets.rb | 14 ++++ test/integration/deliverables_new_test.rb | 74 ++++++++++++------- 9 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 db/migrate/016_add_year_and_month_to_fixed_budgets.rb diff --git a/app/helpers/contracts_helper.rb b/app/helpers/contracts_helper.rb index 0266bd0..ef553e2 100644 --- a/app/helpers/contracts_helper.rb +++ b/app/helpers/contracts_helper.rb @@ -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 diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index b83eb54..9f2f677 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -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 diff --git a/app/models/fixed_budget.rb b/app/models/fixed_budget.rb index ff04099..9ea971c 100644 --- a/app/models/fixed_budget.rb +++ b/app/models/fixed_budget.rb @@ -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? diff --git a/app/models/retainer_deliverable.rb b/app/models/retainer_deliverable.rb index 0a675d6..d8f07ad 100644 --- a/app/models/retainer_deliverable.rb +++ b/app/models/retainer_deliverable.rb @@ -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 diff --git a/app/views/deliverables/_finance_form.html.erb b/app/views/deliverables/_finance_form.html.erb index b77a973..6c3d44d 100644 --- a/app/views/deliverables/_finance_form.html.erb +++ b/app/views/deliverables/_finance_form.html.erb @@ -62,6 +62,37 @@ +
  • +
    + + + <% form.fields_for :fixed_budgets, fixed_budgets do |fixed_budget| %> + + <%= fixed_budget.text_field(:title) %> + +

    + <%= fixed_budget.label(:budget, l(:field_budget), :style => 'display: none;')%> <%# Hidden label :| %> + <%= l(:text_dollar_sign) %> +

    + <%= fixed_budget.text_field(:budget) %> + +

    + <%= fixed_budget.label(:markup, l(:field_markup), :style => 'display: none;')%> <%# Hidden label :| %> + <%= l(:field_discount_hint) %> +

    + <%= fixed_budget.text_field(:markup) %> + + + <%= 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}" %> + +

    Todo: Add button (Release 3)

    + <% end %> +
    + + +
  • + <%= form.input :total, :input_html => {:size => 10}, :wrapper_html => {:class => 'deliverable_total_input'}, :hint => l(:text_dollar_sign) %> <% end %> diff --git a/app/views/deliverables/_form.html.erb b/app/views/deliverables/_form.html.erb index 8d0f7ef..ac810c3 100644 --- a/app/views/deliverables/_form.html.erb +++ b/app/views/deliverables/_form.html.erb @@ -3,7 +3,7 @@ <%= javascript_tag("var i18nChangedPeriodMessage = '#{l(:text_changed_period_message)}'") %>
    -<% 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 %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index e12914d..64c8cad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/db/migrate/016_add_year_and_month_to_fixed_budgets.rb b/db/migrate/016_add_year_and_month_to_fixed_budgets.rb new file mode 100644 index 0000000..7c71ea1 --- /dev/null +++ b/db/migrate/016_add_year_and_month_to_fixed_budgets.rb @@ -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 diff --git a/test/integration/deliverables_new_test.rb b/test/integration/deliverables_new_test.rb index 0c2ef2a..a211f6d 100644 --- a/test/integration/deliverables_new_test.rb +++ b/test/integration/deliverables_new_test.rb @@ -50,12 +50,15 @@ class DeliverablesNewTest < ActionController::IntegrationTest click_link 'Add New' assert_response :success - 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' + 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 - 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' + 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,13 +125,15 @@ class DeliverablesNewTest < ActionController::IntegrationTest click_link 'Add New' assert_response :success - 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' - + 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' fill_in "$", :with => '$2,000' @@ -193,12 +200,14 @@ class DeliverablesNewTest < ActionController::IntegrationTest click_link 'Add New' assert_response :success - 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' + 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