[#2279] Threw away previous work getting the custom data values for Billable.
They should be only Billable and Overhead. * Hard coded the options for the Billable select instead of dynamically pull the values from the Custom Field * Removed TimeEntryActivity#find_with_billable_values in favor of two new methods to return a TimeEntryActivity if it is billable or overhead. `find_billable_activities` and `find_overhead_activities` * Reworked the TimesheetController hook to use the new methods for finding the TimeEntryActivities * Updated RSpec examples
This commit is contained in:
@@ -24,20 +24,49 @@ module OverheadTimeEntryActivityPatch
|
||||
Setting['plugin_redmine_overhead'] && Setting['plugin_redmine_overhead']['custom_field']
|
||||
end
|
||||
|
||||
def find_with_billable_values(values = [])
|
||||
def billable_value_configured?
|
||||
Setting['plugin_redmine_overhead']['billable_value']
|
||||
end
|
||||
|
||||
def overhead_value_configured?
|
||||
Setting['plugin_redmine_overhead']['overhead_value']
|
||||
end
|
||||
|
||||
def find_billable_activities
|
||||
return [] unless overhead_configured?
|
||||
return [] unless billable_value_configured?
|
||||
|
||||
billable_field = TimeEntryActivity.billable_custom_field
|
||||
if billable_field
|
||||
value = Setting['plugin_redmine_overhead']['billable_value'] == 'true' # convert "true" to true...
|
||||
finder = ARCondition.new
|
||||
finder.add "#{CustomValue.table_name}.customized_type = '#{TimeEntryActivity.class_name}'"
|
||||
finder.add ["#{CustomValue.table_name}.custom_field_id = ?", billable_field.id]
|
||||
finder.add ["#{CustomValue.table_name}.value IN (?)", values]
|
||||
finder.add ["#{CustomValue.table_name}.value IN (?)", value]
|
||||
return TimeEntryActivity.find(:all, :include => :custom_values, :conditions => finder.conditions)
|
||||
else
|
||||
return []
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def find_overhead_activities
|
||||
return [] unless overhead_configured?
|
||||
return [] unless overhead_value_configured?
|
||||
|
||||
billable_field = TimeEntryActivity.billable_custom_field
|
||||
if billable_field
|
||||
value = Setting['plugin_redmine_overhead']['overhead_value'] == 'true' # convert "true" to true...
|
||||
finder = ARCondition.new
|
||||
finder.add "#{CustomValue.table_name}.customized_type = '#{TimeEntryActivity.class_name}'"
|
||||
finder.add ["#{CustomValue.table_name}.custom_field_id = ?", billable_field.id]
|
||||
finder.add ["#{CustomValue.table_name}.value IN (?)", value]
|
||||
|
||||
return TimeEntryActivity.find(:all, :include => :custom_values, :conditions => finder.conditions)
|
||||
else
|
||||
return []
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ class OverheadTimesheetHook < Redmine::Hook::ViewListener
|
||||
|
||||
# Added a new field for filtering based on "billable?"
|
||||
def plugin_timesheet_views_timesheet_form(context={})
|
||||
billable_values = select_values_for_field(TimeEntryActivity.billable_custom_field)
|
||||
if context[:params] &&
|
||||
context[:params][:timesheet] &&
|
||||
context[:params][:timesheet][:billable]
|
||||
@@ -37,15 +36,24 @@ class OverheadTimesheetHook < Redmine::Hook::ViewListener
|
||||
:layout => false,
|
||||
:locals => {
|
||||
:list_size => context[:list_size] || 5,
|
||||
:billable_values => billable_values,
|
||||
:selected_values => selected_values
|
||||
})
|
||||
end
|
||||
|
||||
def plugin_timesheet_controller_report_pre_fetch_time_entries(context = {})
|
||||
if context[:params] && context[:params][:timesheet] && context[:params][:timesheet][:billable]
|
||||
activities = TimeEntryActivity.find_with_billable_values(context[:params][:timesheet][:billable])
|
||||
context[:timesheet].activities = activities.collect(&:id) unless activities.empty?
|
||||
billable_options = context[:params][:timesheet][:billable]
|
||||
activities = []
|
||||
|
||||
if billable_options.include?("billable")
|
||||
activities << TimeEntryActivity.find_billable_activities
|
||||
end
|
||||
|
||||
if billable_options.include?("overhead")
|
||||
activities << TimeEntryActivity.find_overhead_activities
|
||||
end
|
||||
|
||||
context[:timesheet].activities = activities.flatten.uniq.compact.collect(&:id).sort unless activities.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user