kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
12 years ago
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
|
#
|
||
|
# Copyright (C) 2012-2013 the OpenProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
12 years ago
|
class AlternateDate < ActiveRecord::Base
|
||
12 years ago
|
unloadable
|
||
|
|
||
12 years ago
|
self.table_name = 'alternate_dates'
|
||
12 years ago
|
|
||
12 years ago
|
include TimestampsCompatibility
|
||
12 years ago
|
|
||
12 years ago
|
belongs_to :planning_element, :class_name => "PlanningElement",
|
||
12 years ago
|
:foreign_key => 'planning_element_id'
|
||
12 years ago
|
belongs_to :scenario, :class_name => "Scenario",
|
||
12 years ago
|
:foreign_key => 'scenario_id'
|
||
|
|
||
|
# history-related = historic
|
||
|
scope :historic, :conditions => "#{self.table_name}.scenario_id IS NULL"
|
||
|
|
||
|
# scenario-related = scenaric
|
||
|
scope :scenaric, :conditions => "#{self.table_name}.scenario_id IS NOT NULL"
|
||
|
|
||
|
validates_presence_of :start_date, :end_date, :planning_element
|
||
|
|
||
|
delegate :planning_element_type, :planning_element_type_id, :is_milestone?, :to => :planning_element
|
||
|
|
||
|
attr_accessible :start_date, :end_date
|
||
|
|
||
|
validate do
|
||
|
if self.end_date and self.start_date and self.end_date < self.start_date
|
||
|
errors.add :end_date, :greater_than_start_date
|
||
|
end
|
||
|
|
||
|
if self.planning_element.present? and self.is_milestone?
|
||
|
if self.end_date and self.start_date and self.start_date != self.end_date
|
||
|
errors.add :end_date, :not_start_date
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def duration
|
||
|
if start_date >= end_date
|
||
|
1
|
||
|
else
|
||
|
end_date - start_date + 1
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|