Added QBO Employee setting to the User.

This allows the a QBO Employee ID to be assigned to a redmine user
This commit is contained in:
2016-01-09 00:51:02 -05:00
parent e45ff68cfa
commit 7abf20f35d
6 changed files with 64 additions and 19 deletions

View File

@@ -10,6 +10,7 @@
class QboEmployee < ActiveRecord::Base class QboEmployee < ActiveRecord::Base
unloadable unloadable
has_many :users
attr_accessible :name attr_accessible :name
validates_presence_of :id, :name validates_presence_of :id, :name
@@ -25,5 +26,4 @@ class QboEmployee < ActiveRecord::Base
qbo_employee.save! qbo_employee.save!
} }
end end
end end

View File

@@ -13,3 +13,4 @@ en:
# my_label: "My label" # my_label: "My label"
field_qbo_customer: "Customer" field_qbo_customer: "Customer"
field_qbo_item: "Item" field_qbo_item: "Item"
field_qbo_employee: "Employee"

View File

@@ -0,0 +1,15 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class UpdateUsers < ActiveRecord::Migration
def change
add_reference :users, :qbo_employee, index: true
end
end

View File

@@ -13,6 +13,7 @@ Redmine::Plugin.register :redmine_qbo do
require_dependency 'issues_form_hook_listener' require_dependency 'issues_form_hook_listener'
require_dependency 'issues_save_hook_listener' require_dependency 'issues_save_hook_listener'
require_dependency 'issues_show_hook_listener' require_dependency 'issues_show_hook_listener'
require_dependency 'users_show_hook_listener'
name 'Redmine Quickbooks Online plugin' name 'Redmine Quickbooks Online plugin'
author 'Rick Barrette' author 'Rick Barrette'
@@ -22,9 +23,10 @@ Redmine::Plugin.register :redmine_qbo do
author_url 'http://rickbarrette.org' author_url 'http://rickbarrette.org'
settings :default => {'empty' => true}, :partial => 'qbo/settings' settings :default => {'empty' => true}, :partial => 'qbo/settings'
# Add qbo_customer to the safe Issue Attributes list # Add safe attributes
Issue.safe_attributes 'qbo_customer_id' Issue.safe_attributes 'qbo_customer_id'
Issue.safe_attributes 'qbo_item_id' Issue.safe_attributes 'qbo_item_id'
User.safe_attributes 'qbo_employee_id'
# We are playing in the sandbox # We are playing in the sandbox
Quickbooks.sandbox_mode = true Quickbooks.sandbox_mode = true

View File

@@ -29,11 +29,13 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
minutesDecimal = (( issue.spent_hours - hours) * 60) minutesDecimal = (( issue.spent_hours - hours) * 60)
minutes = minutesDecimal.to_i minutes = minutesDecimal.to_i
employee_id = User.find_by_id(issue.assigned_to_id).qbo_employee_id
# If the issue is closed, then create a new billable time activty for the customer # If the issue is closed, then create a new billable time activty for the customer
# TODO Add configuration settings for employee_id, hourly_rate, item_id # TODO Add configuration settings for employee_id, hourly_rate, item_id
if issue.status.is_closed? and not issue.qbo_customer_id.nil? and not issue.qbo_item_id.nil? then if issue.status.is_closed? and not issue.qbo_customer_id.nil? and not issue.qbo_item_id.nil? and not employee_id.nil? then
time_entry.description = issue.subject time_entry.description = "Ticket ##{issue.id}: #{issue.subject}"
time_entry.employee_id = 59 time_entry.employee_id = employee_id
time_entry.customer_id = issue.qbo_customer_id time_entry.customer_id = issue.qbo_customer_id
time_entry.billable_status = "Billable" time_entry.billable_status = "Billable"
time_entry.hours = hours time_entry.hours = hours

View File

@@ -0,0 +1,25 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class UsersShowHookListener < Redmine::Hook::ViewListener
# View User
def view_users_form(context={})
selected = ""
# Check to see if there is a quickbooks user attached to the issue
if not context[:user].qbo_employee_id.nil? then
selected = context[:user].qbo_employee_id
end
# Generate the drop down list of quickbooks contacts
return "<p>#{context[:form].select :qbo_employee_id, QboEmployee.all.pluck(:name, :id), :selected => selected, include_blank: true}</p>"
end
end