diff --git a/app/helpers/contracts_helper.rb b/app/helpers/contracts_helper.rb
index 4e49e50..9d93b38 100644
--- a/app/helpers/contracts_helper.rb
+++ b/app/helpers/contracts_helper.rb
@@ -6,6 +6,18 @@ module ContractsHelper
deliverable
end
+ def group_contracts_by_status(contracts)
+ grouped_contracts = contracts.inject({}) do |grouped, contract|
+ grouped[contract.status] ||= []
+ grouped[contract.status] << contract
+ grouped
+ end
+ grouped_contracts["open"] ||= []
+ grouped_contracts["locked"] ||= []
+ grouped_contracts["closed"] ||= []
+ grouped_contracts
+ end
+
# Simple helper to show the values of a field on an object in a standard format
#
#
diff --git a/app/models/contract.rb b/app/models/contract.rb
index 80d8d61..87e5de6 100644
--- a/app/models/contract.rb
+++ b/app/models/contract.rb
@@ -17,6 +17,7 @@ class Contract < ActiveRecord::Base
validates_presence_of :start_date
validates_presence_of :end_date
validates_inclusion_of :discount_type, :in => %w($ %), :allow_blank => true, :allow_nil => true
+ validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
validate :start_and_end_date_are_valid
# Accessors
@@ -33,15 +34,20 @@ class Contract < ActiveRecord::Base
attr_accessible :po_number
attr_accessible :client_point_of_contact
attr_accessible :details
+ attr_accessible :status
named_scope :by_name, {:order => "#{Contract.table_name}.name ASC"}
- [:status, :contract_type,
+ [:contract_type,
:discount_spent, :discount_budget
].each do |mthd|
define_method(mthd) { "TODO in later release" }
end
+ def status
+ read_attribute(:status) || "open"
+ end
+
# ------------------------------------------------------------
# Labor Methods
# ------------------------------------------------------------
@@ -229,6 +235,7 @@ class Contract < ActiveRecord::Base
def after_initialize
self.executed = false unless self.executed.present?
+ self.status = "open" unless self.status.present?
end
# Are the start_date and end_date valid?
@@ -270,5 +277,5 @@ class Contract < ActiveRecord::Base
def summarize_associated_values(records, value_method)
records.inject(0) {|total, record| total += record.send(value_method)}
end
-
+
end
diff --git a/app/views/contracts/_form.html.erb b/app/views/contracts/_form.html.erb
index 0a8c204..8a762cc 100644
--- a/app/views/contracts/_form.html.erb
+++ b/app/views/contracts/_form.html.erb
@@ -1,6 +1,7 @@
<% form.inputs :name => l(:text_general_legend) do %>
<%= form.input :name, :required => true %>
+ <%= form.input :status, :required => true, :collection => [["Open","open"],["Locked","locked"],["Closed","closed"]] %>
<%= form.input :account_executive, :required => true, :collection => @project.users.sort %>
<%= label('contract', 'executed') %>
diff --git a/app/views/contracts/index.html.erb b/app/views/contracts/index.html.erb
index 42d2734..b4534e8 100644
--- a/app/views/contracts/index.html.erb
+++ b/app/views/contracts/index.html.erb
@@ -12,10 +12,10 @@
- <% if collection.empty? %>
+ <% if group_contracts_by_status(collection)["open"].empty? %>
<%= l(:label_no_data) %>
<% else %>
-
+
| <%= l(:field_id) %> |
<%= l(:field_name) %> |
@@ -26,11 +26,11 @@
<%= l(:field_end_date) %> |
- <% collection.each do |contract| %>
+ <% group_contracts_by_status(collection)["open"].each do |contract| %>
<% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
<%= link_to(h(contract.id), contract_path(@project, contract)) %> |
<%= link_to(h(contract.name), contract_path(@project, contract)) %> |
- <%= release(5, "Contract Status") %> |
+ <%= h(contract.status) %> |
<%= release(5, "Contract Type") %> |
<%= h contract.account_executive.name %> |
<%= h(format_value_field_for_contracts(contract.total_budget)) %> |
@@ -42,11 +42,71 @@
<% end %>
-
Inactive Contracts
+ Locked Contracts
- <%= l(:label_no_data) %>
- <%= release(5, "Contract Status. Split contracts by active and inactive") %>
+ <% if group_contracts_by_status(collection)["locked"].empty? %>
+ <%= l(:label_no_data) %>
+ <% else %>
+
+
+ | <%= l(:field_id) %> |
+ <%= l(:field_name) %> |
+ <%= l(:field_status) %> |
+ <%= l(:field_type) %> |
+ <%= l(:field_account_executive_short) %> |
+ <%= l(:field_total_budget) %> |
+ <%= l(:field_end_date) %> |
+
+
+ <% group_contracts_by_status(collection)["locked"].each do |contract| %>
+ <% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
+ <%= link_to(h(contract.id), contract_path(@project, contract)) %> |
+ <%= link_to(h(contract.name), contract_path(@project, contract)) %> |
+ <%= h(contract.status) %> |
+ <%= release(5, "Contract Type") %> |
+ <%= h contract.account_executive.name %> |
+ <%= h(format_value_field_for_contracts(contract.total_budget)) %> |
+ <%= h format_date(contract.end_date) %> |
+ <% end %>
+ <% end %>
+
+
+ <% end %>
+
+
+
Closed Contracts
+
+
+ <% if group_contracts_by_status(collection)["closed"].empty? %>
+ <%= l(:label_no_data) %>
+ <% else %>
+
+
+ | <%= l(:field_id) %> |
+ <%= l(:field_name) %> |
+ <%= l(:field_status) %> |
+ <%= l(:field_type) %> |
+ <%= l(:field_account_executive_short) %> |
+ <%= l(:field_total_budget) %> |
+ <%= l(:field_end_date) %> |
+
+
+ <% group_contracts_by_status(collection)["closed"].each do |contract| %>
+ <% content_tag_for(:tr, contract, :class => cycle('','odd')) do %>
+ <%= link_to(h(contract.id), contract_path(@project, contract)) %> |
+ <%= link_to(h(contract.name), contract_path(@project, contract)) %> |
+ <%= h(contract.status) %> |
+ <%= release(5, "Contract Type") %> |
+ <%= h contract.account_executive.name %> |
+ <%= h(format_value_field_for_contracts(contract.total_budget)) %> |
+ <%= h format_date(contract.end_date) %> |
+ <% end %>
+ <% end %>
+
+
+ <% end %>
+
diff --git a/app/views/contracts/show.html.erb b/app/views/contracts/show.html.erb
index ea9830a..5c68f7f 100644
--- a/app/views/contracts/show.html.erb
+++ b/app/views/contracts/show.html.erb
@@ -15,10 +15,7 @@
-
- <%# show_field(resource, :status, :html_options => {:class => 'contract-status'}) %>
- | <%= release(5, "Contract status") %> |
-
+ <%= show_field(resource, :status, :html_options => {:class => 'contract-status'}) %>
<%= show_field(resource, :account_executive, :html_options => {:class => 'contract-account-manager'}) %>
<%# show_field(resource, :contract_type, :html_options => {:class => 'contract-type'}) %>
diff --git a/db/migrate/018_add_status_to_contracts.rb b/db/migrate/018_add_status_to_contracts.rb
new file mode 100644
index 0000000..58d1823
--- /dev/null
+++ b/db/migrate/018_add_status_to_contracts.rb
@@ -0,0 +1,10 @@
+class AddStatusToContracts < ActiveRecord::Migration
+ def self.up
+ add_column :contracts, :status, :string
+ add_index :contracts, :status
+ end
+
+ def self.down
+ remove_column :contracts, :status
+ end
+end
diff --git a/test/integration/contracts_edit_test.rb b/test/integration/contracts_edit_test.rb
index 0e10ae7..5115067 100644
--- a/test/integration/contracts_edit_test.rb
+++ b/test/integration/contracts_edit_test.rb
@@ -48,12 +48,13 @@ class ContractsEditTest < ActionController::IntegrationTest
end
fill_in "Name", :with => 'An updated name'
+ select "Locked", :from => "Status"
click_button "Save Contract"
assert_response :success
assert_template 'contracts/show'
assert_equal "An updated name", @contract.reload.name
-
+ assert_equal "locked", @contract.reload.status
end
end
diff --git a/test/integration/contracts_list_test.rb b/test/integration/contracts_list_test.rb
index a80d290..4888b91 100644
--- a/test/integration/contracts_list_test.rb
+++ b/test/integration/contracts_list_test.rb
@@ -5,8 +5,10 @@ class ContractsListTest < ActionController::IntegrationTest
def setup
@project = Project.generate!(:identifier => 'main')
- @contract = Contract.generate!(:project => @project)
- @contract2 = Contract.generate!(:project => @project)
+ @contract = Contract.generate!(:project => @project, :name => 'Contract1').reload
+ @contract2 = Contract.generate!(:project => @project, :name => 'Contract2').reload
+ @contract_locked = Contract.generate!(:project => @project, :status => 'locked', :name => 'LockedContract').reload
+ @contract_closed = Contract.generate!(:project => @project, :status => 'closed', :name => 'ClosedContract').reload
@other_project = Project.generate!(:identifier => 'other')
@other_contract = Contract.generate!(:project => @other_project)
@@ -44,10 +46,10 @@ class ContractsListTest < ActionController::IntegrationTest
visit_contracts_for_project(@project)
end
- should "list all contracts for the project" do
+ should "list all contracts for the project grouped by status" do
visit_contracts_for_project(@project)
- assert_select "table#contracts" do
+ assert_select "table#contracts.open" do
[@contract, @contract2].each do |contract|
assert_select "td.id", :text => /#{contract.id}/
assert_select "td.name", :text => /#{contract.name}/
@@ -56,7 +58,23 @@ class ContractsListTest < ActionController::IntegrationTest
assert_select "td.total-budget"
end
end
-
+
+ assert_select "table#contracts.locked" do
+ assert_select "td.id", :text => /#{@contract_locked.id}/
+ assert_select "td.name", :text => /#{@contract_locked.name}/
+ assert_select "td.account-executive", :text => /#{@contract_locked.account_executive.name}/
+ assert_select "td.end-date", :text => /#{format_date(@contract_locked.end_date)}/
+ assert_select "td.total-budget"
+ end
+
+ assert_select "table#contracts.closed" do
+ assert_select "td.id", :text => /#{@contract_closed.id}/
+ assert_select "td.name", :text => /#{@contract_closed.name}/
+ assert_select "td.account-executive", :text => /#{@contract_closed.account_executive.name}/
+ assert_select "td.end-date", :text => /#{format_date(@contract_closed.end_date)}/
+ assert_select "td.total-budget"
+ end
+
end
should "not list contracts from other projects" do
diff --git a/test/integration/contracts_new_test.rb b/test/integration/contracts_new_test.rb
index 399d970..6bf55c8 100644
--- a/test/integration/contracts_new_test.rb
+++ b/test/integration/contracts_new_test.rb
@@ -52,6 +52,7 @@ class ContractsNewTest < ActionController::IntegrationTest
fill_in "Start", :with => '2010-01-01'
fill_in "End Date", :with => '2010-12-31'
select "Net 30", :from => "Payment Terms"
+ select "Locked", :from => "Status"
click_button "Save Contract"
@@ -64,6 +65,7 @@ class ContractsNewTest < ActionController::IntegrationTest
assert_equal '2010-01-01', @contract.start_date.to_s
assert_equal '2010-12-31', @contract.end_date.to_s
assert_equal 'Net 30', @contract.payment_term.name
+ assert_equal "locked", @contract.status
end
end
diff --git a/test/unit/contract_test.rb b/test/unit/contract_test.rb
index 1eae9a4..5e0242b 100644
--- a/test/unit/contract_test.rb
+++ b/test/unit/contract_test.rb
@@ -17,6 +17,9 @@ class ContractTest < ActiveSupport::TestCase
should_allow_values_for :discount_type, "$", "%", nil, ''
should_not_allow_values_for :discount_type, ["amount", "percent", "bar"]
+ should_allow_values_for :status, "", nil, 'open', 'locked', 'closed'
+ should_not_allow_values_for :status, "other", "things", "1"
+
context "end_date" do
should "be after start_date" do
@contract = Contract.new(:start_date => Date.today, :end_date => Date.yesterday)
@@ -32,6 +35,12 @@ class ContractTest < ActiveSupport::TestCase
assert_equal false, @contract.executed
end
+ should "default status to open" do
+ @contract = Contract.new
+
+ assert_equal "open", @contract.status
+ end
+
context "#labor_budget" do
should "sum all of the labor budgets of the Deliverables" do
contract = Contract.generate!