[#6441] Block editing deliverables on locked and closed contracts

This commit is contained in:
Eric Davis committed 2011-08-10 11:56:08 -07:00
1 parent be37e00f10
commit 495407f127
3 files changed
+98 -1

No files matched your search

+12
View File
@@ -21,12 +21,16 @@ class Deliverable < ActiveRecord::Base
validates_presence_of :manager
validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
validate_on_update :validate_status_changes
validate_on_update :validate_contract_status
# Accessors
include DollarizedAttribute
dollarized_attribute :total
delegate :name, :to => :contract, :prefix => true, :allow_nil => true
delegate "open?", :to => :contract, :prefix => true, :allow_nil => true
delegate "closed?", :to => :contract, :prefix => true, :allow_nil => true
delegate "locked?", :to => :contract, :prefix => true, :allow_nil => true
# Callbacks
def after_initialize
@@ -104,6 +108,14 @@ class Deliverable < ActiveRecord::Base
errors.add_to_base(:cant_update_closed_deliverable) if closed?
end
def validate_contract_status
return if contract_open?
return if change_to_status_only?
errors.add_to_base(:cant_update_locked_contract) if contract_locked?
errors.add_to_base(:cant_update_closed_contract) if contract_closed?
end
# No operation method, useful to clean up logic with an optional message
# for documentation
def noop(message="")