OpenProject is the leading open source project management software.
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.
 
 
 
 
 
 
openproject/app/models/alternate_date.rb

56 lines
1.6 KiB

#-- 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.
#++
class AlternateDate < ActiveRecord::Base
unloadable
self.table_name = 'alternate_dates'
include TimestampsCompatibility
belongs_to :planning_element, :class_name => "PlanningElement",
:foreign_key => 'planning_element_id'
belongs_to :scenario, :class_name => "Scenario",
: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