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.
pull/6827/head
Christian Rijke 11 years ago
parent 7ce1ac2510
commit 73f5f043d0
  1. 4
      app/models/cost_object.rb
  2. 50
      lib/open_project/costs/patches/work_packages_helper_patch.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",

@ -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 << "<span title=\"#{h(k.name)}\">#{txt}</span>"
end

Loading…
Cancel
Save