mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
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:
@@ -10,8 +10,9 @@
|
||||
|
||||
class QboEmployee < ActiveRecord::Base
|
||||
unloadable
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
has_many :users
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
|
||||
def self.update_all
|
||||
qbo = Qbo.first
|
||||
@@ -25,5 +26,4 @@ class QboEmployee < ActiveRecord::Base
|
||||
qbo_employee.save!
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -13,3 +13,4 @@ en:
|
||||
# my_label: "My label"
|
||||
field_qbo_customer: "Customer"
|
||||
field_qbo_item: "Item"
|
||||
field_qbo_employee: "Employee"
|
||||
|
||||
15
db/migrate/006_update_users.rb
Normal file
15
db/migrate/006_update_users.rb
Normal 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
|
||||
4
init.rb
4
init.rb
@@ -13,6 +13,7 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
require_dependency 'issues_form_hook_listener'
|
||||
require_dependency 'issues_save_hook_listener'
|
||||
require_dependency 'issues_show_hook_listener'
|
||||
require_dependency 'users_show_hook_listener'
|
||||
|
||||
name 'Redmine Quickbooks Online plugin'
|
||||
author 'Rick Barrette'
|
||||
@@ -22,9 +23,10 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
author_url 'http://rickbarrette.org'
|
||||
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_item_id'
|
||||
User.safe_attributes 'qbo_employee_id'
|
||||
|
||||
# We are playing in the sandbox
|
||||
Quickbooks.sandbox_mode = true
|
||||
|
||||
@@ -28,23 +28,25 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
hours = issue.spent_hours.to_i
|
||||
minutesDecimal = (( issue.spent_hours - hours) * 60)
|
||||
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
|
||||
# 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
|
||||
time_entry.description = issue.subject
|
||||
time_entry.employee_id = 59
|
||||
time_entry.customer_id = issue.qbo_customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = issue.qbo_item_id
|
||||
time_entry.start_time = issue.start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
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 = "Ticket ##{issue.id}: #{issue.subject}"
|
||||
time_entry.employee_id = employee_id
|
||||
time_entry.customer_id = issue.qbo_customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = issue.qbo_item_id
|
||||
time_entry.start_time = issue.start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
25
lib/users_show_hook_listener.rb
Normal file
25
lib/users_show_hook_listener.rb
Normal 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
|
||||
Reference in New Issue
Block a user