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.
90 lines
2.9 KiB
90 lines
2.9 KiB
11 years ago
|
#-- copyright
|
||
5 years ago
|
# OpenProject is an open source project management software.
|
||
|
# Copyright (C) 2012-2020 the OpenProject GmbH
|
||
11 years ago
|
#
|
||
5 years ago
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
11 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
5 years ago
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
11 years ago
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
5 years ago
|
#
|
||
|
# See docs/COPYRIGHT.rdoc for more details.
|
||
11 years ago
|
#++
|
||
|
|
||
5 years ago
|
class LaborBudgetItem < ApplicationRecord
|
||
4 years ago
|
belongs_to :budget
|
||
15 years ago
|
belongs_to :user
|
||
9 years ago
|
belongs_to :principal, foreign_key: 'user_id'
|
||
|
|
||
4 years ago
|
include ::Costs::DeletedUserFallback
|
||
15 years ago
|
|
||
9 years ago
|
validates_length_of :comments, maximum: 255, allow_nil: true
|
||
15 years ago
|
validates_presence_of :user
|
||
4 years ago
|
validates_presence_of :budget
|
||
9 years ago
|
validates_numericality_of :hours, allow_nil: false
|
||
13 years ago
|
|
||
12 years ago
|
include ActiveModel::ForbiddenAttributesProtection
|
||
4 years ago
|
# user_id correctness is ensured in Budget#*_labor_budget_item_attributes=
|
||
13 years ago
|
|
||
8 years ago
|
def self.visible(user, project)
|
||
4 years ago
|
table = arel_table
|
||
8 years ago
|
|
||
|
view_allowed = Project.allowed_to(user, :view_hourly_rates).select(:id)
|
||
8 years ago
|
view_own_allowed = Project.allowed_to(user, :view_own_hourly_rate).select(:id)
|
||
8 years ago
|
|
||
|
view_or_view_own = table[:project_id]
|
||
|
.in(view_allowed.arel)
|
||
|
.or(table[:project_id]
|
||
|
.in(view_own_allowed.arel)
|
||
|
.and(table[:user_id].eq(user.id)))
|
||
|
|
||
4 years ago
|
scope = includes([{ budget: :project }, :user])
|
||
8 years ago
|
.references(:projects)
|
||
4 years ago
|
.where(view_or_view_own)
|
||
8 years ago
|
|
||
|
if project
|
||
4 years ago
|
scope.where(budget: { projects_id: project.id })
|
||
8 years ago
|
end
|
||
12 years ago
|
end
|
||
|
|
||
4 years ago
|
scope :visible_costs, lambda { |*args|
|
||
8 years ago
|
visible((args.first || User.current), args[1])
|
||
12 years ago
|
}
|
||
|
|
||
15 years ago
|
def costs
|
||
4 years ago
|
amount || calculated_costs
|
||
15 years ago
|
end
|
||
13 years ago
|
|
||
4 years ago
|
def overridden_costs?
|
||
|
amount.present?
|
||
7 years ago
|
end
|
||
|
|
||
4 years ago
|
def calculated_costs(fixed_date = budget.fixed_date, project_id = budget.project_id)
|
||
|
if user_id && hours && (rate = HourlyRate.at_date_for_user_in_project(fixed_date, user_id, project_id))
|
||
15 years ago
|
rate.rate * hours
|
||
13 years ago
|
else
|
||
15 years ago
|
0.0
|
||
|
end
|
||
15 years ago
|
end
|
||
13 years ago
|
|
||
12 years ago
|
def costs_visible_by?(usr)
|
||
4 years ago
|
usr.allowed_to?(:view_hourly_rates, budget.project) ||
|
||
|
(usr.id == user_id && usr.allowed_to?(:view_own_hourly_rate, budget.project))
|
||
15 years ago
|
end
|
||
13 years ago
|
end
|