[#5482] Add issue grouping by contract
This commit is contained in:
@@ -14,6 +14,34 @@ module RedmineContracts
|
||||
alias_method_chain :sql_for_field, :contract
|
||||
|
||||
alias_method_chain :issues, :deliverable
|
||||
alias_method_chain :issues, :contract
|
||||
|
||||
# Override Query#count_by_group to allow adding include options like
|
||||
# Query#issues
|
||||
# TODO: core bug: Query#issue_count_by_group doesn't allow setting
|
||||
# options like Query#issue does.
|
||||
def issue_count_by_group(options={})
|
||||
includes = ([:status, :project] + (options[:include] || [])).uniq
|
||||
|
||||
r = nil
|
||||
if grouped?
|
||||
begin
|
||||
# Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
|
||||
r = Issue.count(:group => group_by_statement, :include => includes, :conditions => statement)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
r = {nil => issue_count}
|
||||
end
|
||||
c = group_by_column
|
||||
if c.is_a?(QueryCustomFieldColumn)
|
||||
r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
|
||||
end
|
||||
end
|
||||
r
|
||||
rescue ::ActiveRecord::StatementInvalid => e
|
||||
raise ::Query::StatementInvalid.new(e.message)
|
||||
end
|
||||
|
||||
alias_method_chain :issue_count_by_group, :contract
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,8 +123,26 @@ module RedmineContracts
|
||||
issues_without_deliverable(options)
|
||||
end
|
||||
|
||||
# TODO: core bug: Query#issue_count_by_group doesn't allow setting
|
||||
# options like Query#issue does.
|
||||
# Add the contracts into the includes
|
||||
#
|
||||
# Used with grouping
|
||||
def issues_with_contract(options={})
|
||||
options[:include] ||= []
|
||||
options[:include] << {:deliverable => :contract}
|
||||
|
||||
issues_without_contract(options)
|
||||
end
|
||||
|
||||
# Add the contracts into the includes
|
||||
#
|
||||
# Used with grouping
|
||||
def issue_count_by_group_with_contract(options={})
|
||||
options[:include] ||= []
|
||||
options[:include] << {:deliverable => :contract}
|
||||
|
||||
issue_count_by_group_without_contract(options)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user