diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb index d97e35ee6a..46bd650db1 100644 --- a/lib/issue_patch.rb +++ b/lib/issue_patch.rb @@ -44,6 +44,26 @@ module IssuePatch validate_without_cost_object 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 # Query and filtering def cost_object_subject diff --git a/lib/query_patch.rb b/lib/query_patch.rb index 8441835a9f..1c1575ae22 100644 --- a/lib/query_patch.rb +++ b/lib/query_patch.rb @@ -12,6 +12,11 @@ module QueryPatch base.class_eval do 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" alias_method_chain :available_filters, :costs end