Fixes work package view hook

pull/6827/head
Hagen Schink 11 years ago
parent fab17c6b59
commit 440bb22095
  1. 40
      lib/open_project/costs/hooks/work_packages_show_attributes.rb

@ -1,9 +1,5 @@
module OpenProject::Costs::Hooks
class WorkPackagesShowHook < Redmine::Hook::ViewListener
#include ActionView::Helpers::TagHelper
#include ActionView::Helpers::NumberHelper
#include ActionView::Helpers::UrlHelper
#include ActionView::Helpers::TextHelper
include ActionView::Context
include WorkPackagesHelper
@ -16,7 +12,7 @@ module OpenProject::Costs::Hooks
attributes.reject!{ |a| a.attribute == :spent_time }
attributes << cost_work_package_attributes(@work_package)
attributes << cost_work_package_attributes
attributes.flatten!
attributes
@ -25,45 +21,39 @@ module OpenProject::Costs::Hooks
private
def cost_entries
@cost_entries ||= @work_package.cost_entries.visible(User.current, @work_package.project)
@work_package.cost_entries.visible(User.current, @work_package.project)
end
def material_costs
return @material_costs if @material_costs
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
cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.collect(&:real_costs).sum
end
def time_entries
@time_entries ||= @work_package.time_entries.visible(User.current, @work_package.project)
@work_package.time_entries.visible(User.current, @work_package.project)
end
def labor_costs
return @labor_costs if @labor_costs
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
time_entries_with_rate.blank? ? nil : time_entries_with_rate.collect(&:real_costs).sum
end
def overall_costs
return @overall_costs if @overall_costs
unless material_costs.nil? && @labor_costs.nil?
@overall_costs = 0
@overall_costs += material_costs unless material_costs.nil?
@overall_costs += labor_costs unless labor_costs.nil?
unless material_costs.nil? && labor_costs.nil?
overall_costs = 0
overall_costs += material_costs unless material_costs.nil?
overall_costs += labor_costs unless labor_costs.nil?
else
@overall_costs = nil
overall_costs = nil
end
end
def cost_work_package_attributes(work_package)
def cost_work_package_attributes
attributes = []
attributes << work_package_show_table_row(:cost_object) do
work_package.cost_object ?
link_to_cost_object(work_package.cost_object) :
@work_package.cost_object ?
link_to_cost_object(@work_package.cost_object) :
empty_element_tag
end
if User.current.allowed_to?(:view_time_entries, @project) ||
@ -74,7 +64,7 @@ module OpenProject::Costs::Hooks
summed_hours = time_entries.sum(&:hours)
summed_hours > 0 ?
link_to(l_hours(summed_hours), work_package_time_entries_path(work_package)) :
link_to(l_hours(summed_hours), work_package_time_entries_path(@work_package)) :
empty_element_tag
end
@ -89,7 +79,7 @@ module OpenProject::Costs::Hooks
User.current.allowed_to?(:view_own_cost_entries, @project)
attributes << work_package_show_table_row(:spent_units) do
summarized_cost_entries(cost_entries, work_package)
summarized_cost_entries(cost_entries, @work_package)
end
end

Loading…
Cancel
Save