From 73f5f043d058cb3458a5aa2a4b21e757212cf596 Mon Sep 17 00:00:00 2001 From: Christian Rijke Date: Fri, 20 Sep 2013 15:07:28 +0200 Subject: [PATCH] Upgrade costs plugin after migration. - Use work_package parameter to pass the work package to the summarize method - Access journal directly in acts_as_journalized. --- app/models/cost_object.rb | 4 +- .../patches/work_packages_helper_patch.rb | 50 ++++++++----------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/models/cost_object.rb b/app/models/cost_object.rb index 9aa79ebac9..d3fcc64d95 100644 --- a/app/models/cost_object.rb +++ b/app/models/cost_object.rb @@ -15,8 +15,8 @@ class CostObject < ActiveRecord::Base acts_as_attachable :after_remove => :attachment_removed acts_as_journalized :event_type => 'cost-object', - :event_title => Proc.new {|o| "#{l(:label_cost_object)} ##{o.journaled.id}: #{o.subject}"}, - :event_url => Proc.new {|o| {:controller => 'cost_objects', :action => 'show', :id => o.journaled.id}}, + :event_title => Proc.new {|o| "#{l(:label_cost_object)} ##{o.id}: #{o.subject}"}, + :event_url => Proc.new {|o| {:controller => 'cost_objects', :action => 'show', :id => o.id}}, :activity_type => superclass.plural_name, :activity_find_options => {:include => [:project, :author]}, :activity_timestamp => "#{table_name}.updated_on", diff --git a/lib/open_project/costs/patches/work_packages_helper_patch.rb b/lib/open_project/costs/patches/work_packages_helper_patch.rb index 6da03ad93b..a55c7e95dd 100644 --- a/lib/open_project/costs/patches/work_packages_helper_patch.rb +++ b/lib/open_project/costs/patches/work_packages_helper_patch.rb @@ -7,47 +7,41 @@ module OpenProject::Costs::Patches::WorkPackagesHelperPatch attributes = [] attributes << work_package_show_table_row(:cost_object) do - work_package.cost_object ? - link_to_cost_object(work_package.cost_object) : - "-" - end + work_package.cost_object ? + link_to_cost_object(work_package.cost_object) : + "-" + end if User.current.allowed_to?(:view_time_entries, @project) || - User.current.allowed_to?(:view_own_time_entries, @project) + User.current.allowed_to?(:view_own_time_entries, @project) attributes << work_package_show_table_row(:spent_hours) do - #TODO: put inside controller or model - summed_hours = @time_entries.sum(&:hours) + # TODO: put inside controller or model + summed_hours = @time_entries.sum(&:hours) - summed_hours > 0 ? - link_to(l_hours(summed_hours), work_package_time_entries_path(work_package)) : - "-" - end + summed_hours > 0 ? + link_to(l_hours(summed_hours), work_package_time_entries_path(work_package)) : + "-" + end end - attributes << work_package_show_table_row(:overall_costs) do - @overall_costs.nil? ? - "-" : - number_to_currency(@overall_costs) - end + @overall_costs.nil? ? + "-" : + number_to_currency(@overall_costs) + end if User.current.allowed_to?(:view_cost_entries, @project) || - User.current.allowed_to?(:view_own_cost_entries, @project) + User.current.allowed_to?(:view_own_cost_entries, @project) attributes << work_package_show_table_row(:spent_units) do - - summed_costs = summarized_cost_entries(@cost_entries) - - #summed_costs > 0 ? - summed_costs# : - # "-" - end + summarized_cost_entries(@cost_entries, work_package) + end end attributes end - def summarized_cost_entries(cost_entries, create_link=true) + def summarized_cost_entries(cost_entries, work_package, create_link=true) last_cost_type = "" return "-" if cost_entries.blank? @@ -72,10 +66,10 @@ module OpenProject::Costs::Patches::WorkPackagesHelperPatch # TODO why does this have project_id, work_package_id and cost_type_id params? str_array << link_to(txt, { :controller => '/costlog', :action => 'index', - :project_id => @work_package.project, - :work_package_id => @work_package, + :project_id => work_package.project, + :work_package_id => work_package, :cost_type_id => k }, - { :title => k.name }) + { :title => k.name }) else str_array << "#{txt}" end