|
|
|
@ -22,6 +22,13 @@ module OpenProject::Costs::Patches::QueryPatch |
|
|
|
|
include ActionView::Helpers::NumberHelper |
|
|
|
|
alias :super_value :value |
|
|
|
|
|
|
|
|
|
def initialize(name, options = {}) |
|
|
|
|
super |
|
|
|
|
|
|
|
|
|
@sum_function = options[:summable] |
|
|
|
|
self.summable = @sum_function.respond_to?(:call) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def value(work_package) |
|
|
|
|
number_to_currency(work_package.send(name)) |
|
|
|
|
end |
|
|
|
@ -39,7 +46,7 @@ module OpenProject::Costs::Patches::QueryPatch |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def sum_of(work_packages) |
|
|
|
|
work_packages.map { |wp| real_value(wp) }.compact.reduce(:+) |
|
|
|
|
@sum_function.call(work_packages) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -51,9 +58,26 @@ module OpenProject::Costs::Patches::QueryPatch |
|
|
|
|
# Same as typing in the class |
|
|
|
|
base.class_eval do |
|
|
|
|
add_available_column(QueryColumn.new(:cost_object_subject)) |
|
|
|
|
add_available_column(CurrencyQueryColumn.new(:material_costs, summable: true)) |
|
|
|
|
add_available_column(CurrencyQueryColumn.new(:labor_costs, summable: true)) |
|
|
|
|
add_available_column(CurrencyQueryColumn.new(:overall_costs, summable: true)) |
|
|
|
|
|
|
|
|
|
add_available_column(CurrencyQueryColumn.new( |
|
|
|
|
:material_costs, |
|
|
|
|
summable: -> (work_packages) { |
|
|
|
|
CostEntry.costs_of(work_packages: work_packages) |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
add_available_column(CurrencyQueryColumn.new( |
|
|
|
|
:labor_costs, |
|
|
|
|
summable: -> (work_packages) { |
|
|
|
|
TimeEntry.costs_of(work_packages: work_packages) |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
add_available_column(CurrencyQueryColumn.new( |
|
|
|
|
:overall_costs, |
|
|
|
|
summable: -> (work_packages) { |
|
|
|
|
labor_costs = TimeEntry.costs_of(work_packages: work_packages) |
|
|
|
|
material_costs = CostEntry.costs_of(work_packages: work_packages) |
|
|
|
|
labor_costs + material_costs |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
Queries::WorkPackages::Filter.add_filter_type_by_field('cost_object_id', 'list_optional') |
|
|
|
|
|
|
|
|
|