mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
It's in Production!
Made some tweaks and error checks
This commit is contained in:
2
init.rb
2
init.rb
@@ -30,7 +30,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
TimeEntry.safe_attributes 'qbo_billed'
|
TimeEntry.safe_attributes 'qbo_billed'
|
||||||
|
|
||||||
# We are playing in the sandbox
|
# We are playing in the sandbox
|
||||||
Quickbooks.sandbox_mode = true
|
#Quickbooks.sandbox_mode = true
|
||||||
|
|
||||||
# Register QBO top menu item
|
# Register QBO top menu item
|
||||||
menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks'
|
menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks'
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
|||||||
selected = ""
|
selected = ""
|
||||||
|
|
||||||
QboCustomers.update_all
|
QboCustomers.update_all
|
||||||
QboItem.update_all
|
#QboItem.update_all
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
# Check to see if there is a quickbooks user attached to the issue
|
||||||
if not context[:issue].qbo_customer_id.nil? then
|
if not context[:issue].qbo_customer_id.nil? then
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
|||||||
time_service = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
time_service = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||||
item_service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
item_service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||||
time_entry = Quickbooks::Model::TimeActivity.new
|
time_entry = Quickbooks::Model::TimeActivity.new
|
||||||
item = item_service.fetch_by_id issue.qbo_item_id
|
|
||||||
|
|
||||||
# Get unbilled time entries
|
# Get unbilled time entries
|
||||||
spent_time = issue.time_entries.where(qbo_billed: [false, nil])
|
spent_time = issue.time_entries.where(qbo_billed: [false, nil])
|
||||||
spent_hours ||= spent_time.sum(:hours) || 0
|
spent_hours ||= spent_time.sum(:hours) || 0
|
||||||
@@ -44,6 +43,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
|||||||
# 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? and not employee_id.nil? and spent_hours > 0 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? and spent_hours > 0 then
|
||||||
|
item = item_service.fetch_by_id issue.qbo_item_id
|
||||||
time_entry.description = "#{issue.tracker} ##{issue.id}: #{issue.subject}"
|
time_entry.description = "#{issue.tracker} ##{issue.id}: #{issue.subject}"
|
||||||
time_entry.employee_id = employee_id
|
time_entry.employee_id = employee_id
|
||||||
time_entry.customer_id = issue.qbo_customer_id
|
time_entry.customer_id = issue.qbo_customer_id
|
||||||
|
|||||||
@@ -22,9 +22,13 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
|||||||
|
|
||||||
output = content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes")
|
output = content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes")
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
value = ""
|
||||||
if not context[:issue].qbo_customer_id.nil? then
|
|
||||||
value = QboItem.find_by_id(context[:issue].qbo_item_id).name
|
# Check to see if there is a quickbooks item attached to the issue
|
||||||
|
if not context[:issue].qbo_customer_id.nil? then
|
||||||
|
if not QboItem.find_by_id(context[:issue].qbo_item_id).nil? then
|
||||||
|
value = QboItem.find_by_id(context[:issue].qbo_item_id).name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes")
|
output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes")
|
||||||
|
|||||||
Reference in New Issue
Block a user