hjust 15 years ago
parent ddb194c98d
commit 7697861dc6
  1. 32
      app/models/cost_query.rb
  2. 24
      lib/costs_issue_hook.rb
  3. 21
      lib/costs_issue_patch.rb

@ -103,6 +103,28 @@ class CostQuery < ActiveRecord::Base
self.group_by ||= {}
end
def display_time_entries
# read_attribute("display_time_entries") && (
!self.filters || !self.filters.any? do |f|
f["enabled"] == "1" && f["scope"] == "costs" && f["column_name"] == "cost_type_id" && (
(f["operator"] == "!" && f["values"].include?("")) ||
(f["operator"] == "=" && !f["values"].include?(""))
)
end
# )
end
def display_cost_entries
# read_attribute("display_cost_entries") && (
!self.filters || !self.filters.any? do |f|
f["enabled"] == "1" && f["scope"] == "costs" && f["column_name"] == "cost_type_id" && (
(f["operator"] == "=" && f["values"].all? {|v| v == ""})
)
end
# )
end
def self.operators
# These are the operators used by filter types.
@ -157,7 +179,7 @@ class CostQuery < ActiveRecord::Base
@available_filters = {
:costs => {
"cost_type_id" => { :type => :list_optional, :order => 2, :applies => [:cost_entries], :flags => [], :db_table => CostType.table_name, :db_field => "id", :values => CostType.find(:all, :order => 'name').collect{|s| [s.name, s.id.to_s] }},
"cost_type_id" => { :type => :list, :order => 2, :applies => [:cost_entries], :flags => [], :db_table => CostType.table_name, :db_field => "id", :values => [[l(:field_labor_costs), ""]] + CostType.find(:all, :order => 'name').collect{|s| [s.name, s.id.to_s] }},
"activity_id" => { :type => :list_optional, :order => 3, :applies => [:time_entries], :flags => [], :db_table => TimeEntryActivity.table_name, :db_field => "id", :values => TimeEntryActivity.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] }},
"created_on" => { :type => :date_exact, :applies => [:time_entries, :cost_entries], :flags => [], :order => 4 },
"updated_on" => { :type => :date_exact, :applies => [:time_entries, :cost_entries], :flags => [], :order => 5 },
@ -231,6 +253,10 @@ class CostQuery < ActiveRecord::Base
return match.blank? ? nil : match[0]
end
def clean_filters
end
MAGIC_GROUP_KEYS = [:block, :time, :display, :db_field, :other_group]
def self.grouping_column(*names, &block)
@ -645,9 +671,9 @@ private
sql = ''
case operator
when "="
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" unless value.blank?
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| val.present? ? "'#{connection.quote_string(val)}'" : "NULL"}.join(",") + ")" unless value.blank?
when "!"
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| val.present? ? "'#{connection.quote_string(val)}'" : "NULL"}.join(",") + "))"
when "!*"
sql = "#{db_table}.#{db_field} IS NULL"
sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter

@ -12,8 +12,32 @@ class CostsIssueHook < Redmine::Hook::ViewListener
# Renders a select tag with all the Cost Objects for the bulk edit page
render_on :view_issues_bulk_edit_details_bottom, :partial => 'hooks/view_issues_bulk_edit_details_bottom'
render_on :view_issues_move_bottom, :partial => 'hooks/view_issues_move_bottom'
# Updates the cost object after a move
#
# Context:
# * params => Request parameters
# * issue => Issue to move
# * target_project => Target of the move
# * copy => true, if the issues are copied rather than moved
def controller_issues_move_before_save(context={})
# FIXME: In case of copy==true, this will break stuff if the original issue is saved
case params[:cost_object_id]
when "" # a.k.a "(No change)"
# cost objects HAVE to be changed if move is performed across project boundaries
# as the are project specific
issue.cost_object_id = nil unless issue.project == context[:target_project]
when "none"
issue.cost_object_id = nil
else
issue.cost_object_id = params[:cost_object_id]
end
end
# Renders a select tag with all the Cost Objects for the bulk edit page
#
# Context:

@ -14,8 +14,8 @@ module CostsIssuePatch
has_many :cost_entries, :dependent => :delete_all
# disabled for now, implements part of ticket blocking
#alias_method_chain :validate, :cost_object
alias_method_chain :validate, :cost_object
def spent_hours
# overwritten method
@spent_hours ||= self.time_entries.visible(User.current).sum(:hours) || 0
@ -30,13 +30,16 @@ module CostsIssuePatch
module InstanceMethods
def validate_with_cost_object
if cost_object_id_changed?
if cost_object_id_was.nil?
# formerly unassigned ticket
errors.add :cost_object_id, :activerecord_error_invalid if cost_object.blocked?
else
old_cost_object = CostObject.find(cost_object_id_was)
errors.add :cost_object_id, :activerecord_error_invalid if old_cost_object.blocked?
end
errors.add :cost_object_id, :activerecord_error_invalid unless project.cost_object_ids.include? cost_object_id
## disabled for now, implements part of ticket blocking
# if cost_object_id_was.nil?
# # formerly unassigned ticket
# errors.add :cost_object_id, :activerecord_error_invalid if cost_object.blocked?
# else
# old_cost_object = CostObject.find(cost_object_id_was)
# errors.add :cost_object_id, :activerecord_error_invalid if old_cost_object.blocked?
# end
end
validate_without_cost_object

Loading…
Cancel
Save