Added methods to calculate the costs of an issue.

Also reintroduced Issue list columns (originally removed in r373)

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@389 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 7931c4fa63
commit ba5382ce07
  1. 20
      lib/issue_patch.rb
  2. 5
      lib/query_patch.rb

@ -44,6 +44,26 @@ module IssuePatch
validate_without_cost_object validate_without_cost_object
end end
def material_costs
@material_costs ||= cost_entries.visible(User.current, self.project).sum("CASE
WHEN #{CostEntry.table_name}.overridden_costs IS NULL THEN
#{CostEntry.table_name}.costs
ELSE
#{CostEntry.table_name}.overridden_costs END")
end
def labor_costs
@labor_costs ||= time_entries.visible(User.current, self.project).sum("CASE
WHEN #{TimeEntry.table_name}.overridden_costs IS NULL THEN
#{TimeEntry.table_name}.costs
ELSE
#{TimeEntry.table_name}.overridden_costs END")
end
def overall_costs
labor_costs + material_costs
end
# Wraps the association to get the Cost Object subject. Needed for the # Wraps the association to get the Cost Object subject. Needed for the
# Query and filtering # Query and filtering
def cost_object_subject def cost_object_subject

@ -12,6 +12,11 @@ module QueryPatch
base.class_eval do base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development unloadable # Send unloadable so it will not be unloaded in development
base.add_available_column(QueryColumn.new(:cost_object_subject))
base.add_available_column(QueryColumn.new(:material_costs))
base.add_available_column(QueryColumn.new(:labor_costs))
base.add_available_column(QueryColumn.new(:overall_costs))
unless instance_methods.include? "available_filters_without_costs" unless instance_methods.include? "available_filters_without_costs"
alias_method_chain :available_filters, :costs alias_method_chain :available_filters, :costs
end end

Loading…
Cancel
Save