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/labor_budget_item.rb

29 lines
855 B

class LaborBudgetItem < ActiveRecord::Base
belongs_to :cost_object
belongs_to :user
include Costs::DeletedUserFallback
validates_length_of :comments, :maximum => 255, :allow_nil => true
validates_presence_of :user
validates_presence_of :cost_object
validates_numericality_of :hours, :allow_nil => false
# user_id correctness is ensured in VariableCostObject#*_labor_budget_item_attributes=
attr_accessible :hours, :comments, :budget, :user_id
def costs
self.budget || self.calculated_costs
end
def calculated_costs(fixed_date = cost_object.fixed_date, project_id = cost_object.project_id)
if user && hours && rate = user.rate_at(fixed_date, project_id)
rate.rate * hours
else
0.0
end
end
def can_view_costs?(usr, project)
usr.allowed_to?(:view_hourly_rates, project, :for => user)
end
end