comparison app/models/.svn/text-base/version.rb.svn-base @ 511:107d36338b70 live

Merge from branch "cannam"
author Chris Cannam
date Thu, 14 Jul 2011 10:43:07 +0100
parents 0c939c159af4
children
comparison
equal deleted inserted replaced
451:a9f6345cb43d 511:107d36338b70
31 validates_length_of :name, :maximum => 60 31 validates_length_of :name, :maximum => 60
32 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true 32 validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
33 validates_inclusion_of :status, :in => VERSION_STATUSES 33 validates_inclusion_of :status, :in => VERSION_STATUSES
34 validates_inclusion_of :sharing, :in => VERSION_SHARINGS 34 validates_inclusion_of :sharing, :in => VERSION_SHARINGS
35 35
36 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
36 named_scope :open, :conditions => {:status => 'open'} 37 named_scope :open, :conditions => {:status => 'open'}
37 named_scope :visible, lambda {|*args| { :include => :project, 38 named_scope :visible, lambda {|*args| { :include => :project,
38 :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } 39 :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
39 40
40 # Returns true if +user+ or current user is allowed to view the version 41 # Returns true if +user+ or current user is allowed to view the version
41 def visible?(user=User.current) 42 def visible?(user=User.current)
42 user.allowed_to?(:view_issues, self.project) 43 user.allowed_to?(:view_issues, self.project)
43 end 44 end
44 45
45 def start_date 46 def start_date
46 effective_date 47 @start_date ||= fixed_issues.minimum('start_date')
47 end 48 end
48 49
49 def due_date 50 def due_date
50 effective_date 51 effective_date
51 end 52 end
75 end 76 end
76 77
77 def behind_schedule? 78 def behind_schedule?
78 if completed_pourcent == 100 79 if completed_pourcent == 100
79 return false 80 return false
80 elsif due_date && fixed_issues.present? && fixed_issues.minimum('start_date') # TODO: should use #start_date but that method is wrong... 81 elsif due_date && start_date
81 start_date = fixed_issues.minimum('start_date')
82 done_date = start_date + ((due_date - start_date+1)* completed_pourcent/100).floor 82 done_date = start_date + ((due_date - start_date+1)* completed_pourcent/100).floor
83 return done_date <= Date.today 83 return done_date <= Date.today
84 else 84 else
85 false # No issues so it's not late 85 false # No issues so it's not late
86 end 86 end