diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 8cd4026..8216693 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -64,10 +64,15 @@ class QboController < ApplicationController def bill i = Issue.find_by_id params[:id] if i.customer - i.bill_time - redirect_to i, flash: { notice: I18n.t(:label_billed_success) + i.customer.name } + billed = i.bill_time + + if i.bill_time + redirect_to i, flash: { notice: I18n.t( :label_billed_success ) + i.customer.name } + else + redirect_to i, flash: { error: I18n.t(:label_billing_error) } + end else - redirect_to i, flash: { error: I18n.t(:label_billing_error) } + redirect_to i, flash: { error: I18n.t(:label_billing_error_no_customer) } end end diff --git a/config/locales/en.yml b/config/locales/en.yml index e42e1d1..39931a2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -74,7 +74,8 @@ en: label_connected: "Successfully connected to Quickbooks" label_error: "Error" label_billed_success: "Successfully Billed " - label_billing_error: "Cannot bill without a customer assigned" + label_billing_error: "Customer could not be billed, check for Customer or Assignee and try again" + label_billing_error_no_customer: "Cannot bill without a customer assigned" label_qbo_sync_success: "Successfully synced to Quickbooks" label_hours: "Hours" label_oauth2_refresh_token_expires_at: "Refresh Token Expires At" diff --git a/lib/redmine_qbo/patches/issue_patch.rb b/lib/redmine_qbo/patches/issue_patch.rb index 26e5949..1c08656 100644 --- a/lib/redmine_qbo/patches/issue_patch.rb +++ b/lib/redmine_qbo/patches/issue_patch.rb @@ -44,10 +44,9 @@ module RedmineQbo # Create billable time entries def bill_time logger.debug "QBO: Billing time for issue ##{id}" - return unless status.is_closed? - return if assigned_to.nil? - return unless Qbo.first - return unless customer + return false if assigned_to.nil? + return false unless Qbo.first + return false unless customer Thread.new do spent_time = time_entries.where(billed: [false, nil]) @@ -102,6 +101,7 @@ module RedmineQbo end end end + return true end end