diff --git a/init.rb b/init.rb index 91b3ac4..886a840 100644 --- a/init.rb +++ b/init.rb @@ -30,7 +30,7 @@ Redmine::Plugin.register :redmine_qbo do TimeEntry.safe_attributes 'qbo_billed' # We are playing in the sandbox - Quickbooks.sandbox_mode = true + #Quickbooks.sandbox_mode = true # Register QBO top menu item menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks' diff --git a/lib/issues_form_hook_listener.rb b/lib/issues_form_hook_listener.rb index a63d091..29be2da 100644 --- a/lib/issues_form_hook_listener.rb +++ b/lib/issues_form_hook_listener.rb @@ -16,7 +16,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener selected = "" QboCustomers.update_all - QboItem.update_all + #QboItem.update_all # Check to see if there is a quickbooks user attached to the issue if not context[:issue].qbo_customer_id.nil? then diff --git a/lib/issues_save_hook_listener.rb b/lib/issues_save_hook_listener.rb index 68cc017..474bba6 100644 --- a/lib/issues_save_hook_listener.rb +++ b/lib/issues_save_hook_listener.rb @@ -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) item_service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token) time_entry = Quickbooks::Model::TimeActivity.new - item = item_service.fetch_by_id issue.qbo_item_id - + # Get unbilled time entries spent_time = issue.time_entries.where(qbo_billed: [false, nil]) 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 # 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 + item = item_service.fetch_by_id issue.qbo_item_id time_entry.description = "#{issue.tracker} ##{issue.id}: #{issue.subject}" time_entry.employee_id = employee_id time_entry.customer_id = issue.qbo_customer_id diff --git a/lib/issues_show_hook_listener.rb b/lib/issues_show_hook_listener.rb index 52005a7..f8df436 100644 --- a/lib/issues_show_hook_listener.rb +++ b/lib/issues_show_hook_listener.rb @@ -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") - # Check to see if there is a quickbooks user attached to the issue - if not context[:issue].qbo_customer_id.nil? then - value = QboItem.find_by_id(context[:issue].qbo_item_id).name + value = "" + + # 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 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")