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.
74 lines
2.6 KiB
74 lines
2.6 KiB
15 years ago
|
require_dependency 'issues_controller'
|
||
|
|
||
12 years ago
|
module OpenProject::Costs::Patches::IssuesControllerPatch
|
||
15 years ago
|
def self.included(base) # :nodoc:
|
||
|
base.send(:include, InstanceMethods)
|
||
|
|
||
|
base.class_eval do
|
||
15 years ago
|
alias_method_chain :show, :entries
|
||
15 years ago
|
alias_method_chain :destroy, :entries
|
||
12 years ago
|
|
||
15 years ago
|
helper :issues
|
||
15 years ago
|
end
|
||
12 years ago
|
|
||
15 years ago
|
end
|
||
|
|
||
|
module InstanceMethods
|
||
|
# Authorize the user for the requested action
|
||
|
def show_with_entries
|
||
15 years ago
|
@cost_entries = @issue.cost_entries.visible(User.current, @issue.project)
|
||
15 years ago
|
cost_entries_with_rate = @cost_entries.select{|c| c.costs_visible_by?(User.current)}
|
||
|
@material_costs = cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.collect(&:real_costs).sum
|
||
12 years ago
|
|
||
15 years ago
|
@time_entries = @issue.time_entries.visible(User.current, @issue.project)
|
||
15 years ago
|
time_entries_with_rate = @time_entries.select{|c| c.costs_visible_by?(User.current)}
|
||
|
@labor_costs = time_entries_with_rate.blank? ? nil : time_entries_with_rate.collect(&:real_costs).sum
|
||
12 years ago
|
|
||
12 years ago
|
unless @material_costs.nil? && @labor_costs.nil?
|
||
15 years ago
|
@overall_costs = 0
|
||
|
@overall_costs += @material_costs unless @material_costs.nil?
|
||
|
@overall_costs += @labor_costs unless @labor_costs.nil?
|
||
|
else
|
||
|
@overall_costs = nil
|
||
|
end
|
||
12 years ago
|
|
||
15 years ago
|
show_without_entries
|
||
|
end
|
||
12 years ago
|
|
||
15 years ago
|
def destroy_with_entries
|
||
|
@entries = CostEntry.all(:conditions => ['issue_id IN (?)', @issues])
|
||
|
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
|
||
15 years ago
|
unless @entries.blank? && @hours == 0
|
||
15 years ago
|
case params[:todo]
|
||
|
when 'destroy'
|
||
|
# nothing to do
|
||
|
when 'nullify'
|
||
|
TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
|
||
|
CostEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
|
||
|
when 'reassign'
|
||
|
reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
|
||
|
if reassign_to.nil?
|
||
|
flash.now[:error] = l(:error_issue_not_found_in_project)
|
||
|
return
|
||
|
else
|
||
|
TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||
|
CostEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
|
||
|
end
|
||
|
else
|
||
|
unless params[:format] == 'xml'
|
||
|
# display the destroy form if it's a user request
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
@issues.each(&:destroy)
|
||
|
respond_to do |format|
|
||
|
format.html { redirect_to :action => 'index', :project_id => @project }
|
||
|
format.xml { head :ok }
|
||
|
end
|
||
|
end
|
||
15 years ago
|
end
|
||
|
end
|
||
|
|
||
12 years ago
|
IssuesController.send(:include, OpenProject::Costs::Patches::IssuesControllerPatch)
|