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_id && hours && rate = HourlyRate.at_date_for_user_in_project(fixed_date, user_id, 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