[#2281] Added TimeEntryActivity#billable? query method which will lookup
the settings and the current custom values of the TimeEntryActivity.
This commit is contained in:
7
init.rb
7
init.rb
@@ -1,5 +1,12 @@
|
||||
require 'redmine'
|
||||
|
||||
# Patches to the Redmine core.
|
||||
require 'dispatcher'
|
||||
require 'overhead_time_entry_activity_patch'
|
||||
Dispatcher.to_prepare do
|
||||
TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch)
|
||||
end
|
||||
|
||||
Redmine::Plugin.register :redmine_overhead do
|
||||
name 'Overhead plugin'
|
||||
author 'Eric Davis'
|
||||
|
||||
42
lib/overhead_time_entry_activity_patch.rb
Normal file
42
lib/overhead_time_entry_activity_patch.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
require_dependency 'time_entry_activity'
|
||||
|
||||
module OverheadTimeEntryActivityPatch
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
# Is the Activity Billable, based on it's custom data?
|
||||
def billable?
|
||||
if Setting['plugin_redmine_overhead'] && Setting['plugin_redmine_overhead']['custom_field']
|
||||
billable_field = TimeEntryActivityCustomField.find_by_id(Setting['plugin_redmine_overhead']['custom_field'])
|
||||
|
||||
if billable_field && field = self.custom_value_for(billable_field)
|
||||
if billable_field.field_format == 'bool'
|
||||
setting = (Setting['plugin_redmine_overhead']['billable_value'] == "true") ? true : false
|
||||
activity_field = (field.value == "1") ? true : false
|
||||
return activity_field == setting
|
||||
else
|
||||
return field.value == Setting['plugin_redmine_overhead']['billable_value']
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
77
spec/lib/overhead_time_entry_activity_patch_spec.rb
Normal file
77
spec/lib/overhead_time_entry_activity_patch_spec.rb
Normal file
@@ -0,0 +1,77 @@
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe TimeEntryActivity, 'billable?' do
|
||||
before(:each) do
|
||||
@activity = TimeEntryActivity.new
|
||||
|
||||
end
|
||||
|
||||
describe 'with a boolean Custom Field' do
|
||||
before(:each) do
|
||||
@custom_field = mock_model(TimeEntryActivityCustomField)
|
||||
@custom_field.should_receive(:field_format).and_return("bool")
|
||||
TimeEntryActivityCustomField.should_receive(:find_by_id).and_return(@custom_field)
|
||||
|
||||
Setting.should_receive(:[]).with('plugin_redmine_overhead').at_least(:once).and_return do
|
||||
{
|
||||
"custom_field"=> @custom_field.id.to_s,
|
||||
"billable_value"=>"true",
|
||||
"overhead_value"=>"false"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be true if the current Billing Status value is the Billable value' do
|
||||
@activity.should_receive(:custom_value_for).with(@custom_field).and_return do
|
||||
mock_model(CustomValue, :value => "1")
|
||||
end
|
||||
|
||||
@activity.billable?.should be_true
|
||||
end
|
||||
|
||||
it 'should be false if the current Billing Status value is a different Billable value' do
|
||||
@activity.should_receive(:custom_value_for).with(@custom_field).and_return do
|
||||
mock_model(CustomValue, :value => "0")
|
||||
end
|
||||
|
||||
@activity.billable?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a list Custom Field' do
|
||||
before(:each) do
|
||||
@custom_field = mock_model(TimeEntryActivityCustomField)
|
||||
@custom_field.should_receive(:field_format).and_return("list")
|
||||
TimeEntryActivityCustomField.should_receive(:find_by_id).and_return(@custom_field)
|
||||
|
||||
Setting.should_receive(:[]).with('plugin_redmine_overhead').at_least(:once).and_return do
|
||||
{
|
||||
"custom_field"=> @custom_field.id.to_s,
|
||||
"billable_value"=>"is Billable",
|
||||
"overhead_value"=>"is not Billable"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be true if the current Billing Status value is the Billable value' do
|
||||
@activity.should_receive(:custom_value_for).with(@custom_field).and_return do
|
||||
mock_model(CustomValue, :value => "is Billable")
|
||||
end
|
||||
|
||||
@activity.billable?.should be_true
|
||||
end
|
||||
|
||||
it 'should be false if the current Billing Status value is a different Billable value' do
|
||||
@activity.should_receive(:custom_value_for).with(@custom_field).and_return do
|
||||
mock_model(CustomValue, :value => "is not Billable")
|
||||
end
|
||||
|
||||
@activity.billable?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be false if the Billing Status is not configured' do
|
||||
@activity.billable?.should be_false
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user