mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Logging & exception handler for updating invoices
This commit is contained in:
@@ -88,6 +88,8 @@ class QboController < ApplicationController
|
|||||||
# Quickbooks Webhook Callback
|
# Quickbooks Webhook Callback
|
||||||
def qbo_webhook
|
def qbo_webhook
|
||||||
|
|
||||||
|
logger.debug "Quickbooks is calling webhook"
|
||||||
|
|
||||||
# check the payload
|
# check the payload
|
||||||
signature = request.headers['intuit-signature']
|
signature = request.headers['intuit-signature']
|
||||||
key = Setting.plugin_redmine_qbo['settingsWebhookToken']
|
key = Setting.plugin_redmine_qbo['settingsWebhookToken']
|
||||||
@@ -111,6 +113,8 @@ class QboController < ApplicationController
|
|||||||
# TODO rename all other models!
|
# TODO rename all other models!
|
||||||
name.prepend("Qbo") if not name.eql? "Customer"
|
name.prepend("Qbo") if not name.eql? "Customer"
|
||||||
|
|
||||||
|
logger.debug "Casting #{name.constantize} to obj"
|
||||||
|
|
||||||
# Magicly initialize the correct class
|
# Magicly initialize the correct class
|
||||||
obj = name.constantize
|
obj = name.constantize
|
||||||
|
|
||||||
@@ -122,7 +126,13 @@ class QboController < ApplicationController
|
|||||||
obj.destroy(id)
|
obj.destroy(id)
|
||||||
#if not then update!
|
#if not then update!
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
obj.sync_by_id(id)
|
obj.sync_by_id(id)
|
||||||
|
rescue => e
|
||||||
|
logger.error "Failed to call sync_by_id on obj"
|
||||||
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.join("\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -134,12 +144,15 @@ class QboController < ApplicationController
|
|||||||
else
|
else
|
||||||
render nothing: true, status: 400
|
render nothing: true, status: 400
|
||||||
end
|
end
|
||||||
|
|
||||||
|
logger.debug "Quickbooks webhook complete"
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Synchronizes the QboCustomer table with QBO
|
# Synchronizes the QboCustomer table with QBO
|
||||||
#
|
#
|
||||||
def sync
|
def sync
|
||||||
|
logger.debug "Syncing EVERYTHING"
|
||||||
# Update info in background
|
# Update info in background
|
||||||
Thread.new do
|
Thread.new do
|
||||||
if Qbo.exists?
|
if Qbo.exists?
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
|
|
||||||
# sync ALL the invoices
|
# sync ALL the invoices
|
||||||
def self.sync
|
def self.sync
|
||||||
|
logger.debug "Syncing all invoices"
|
||||||
last = Qbo.first.last_sync
|
last = Qbo.first.last_sync
|
||||||
|
|
||||||
query = "SELECT Id, DocNumber FROM Invoice"
|
query = "SELECT Id, DocNumber FROM Invoice"
|
||||||
@@ -42,6 +43,7 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
|
|
||||||
#sync by invoice ID
|
#sync by invoice ID
|
||||||
def self.sync_by_id(id)
|
def self.sync_by_id(id)
|
||||||
|
logger.debug "Syncing invoice #{id}"
|
||||||
#update the information in the database
|
#update the information in the database
|
||||||
invoice = get_base.fetch_by_id(id)
|
invoice = get_base.fetch_by_id(id)
|
||||||
process_invoice invoice
|
process_invoice invoice
|
||||||
@@ -56,6 +58,8 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
# skip this issue if the issue customer is not the same as the invoice customer
|
# skip this issue if the issue customer is not the same as the invoice customer
|
||||||
return if issue.customer_id != invoice.customer_ref.value.to_i
|
return if issue.customer_id != invoice.customer_ref.value.to_i
|
||||||
|
|
||||||
|
logger.debug "Attaching invoice #{invoice.id} to issue #{issue.id}"
|
||||||
|
|
||||||
# Load the invoice into the database
|
# Load the invoice into the database
|
||||||
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
|
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
|
||||||
qbo_invoice.doc_number = invoice.doc_number
|
qbo_invoice.doc_number = invoice.doc_number
|
||||||
@@ -73,6 +77,7 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
|
|
||||||
# processes the invoice into the system
|
# processes the invoice into the system
|
||||||
def self.process_invoice(invoice)
|
def self.process_invoice(invoice)
|
||||||
|
logger.debug "Processing invoice"
|
||||||
# Check the private notes
|
# Check the private notes
|
||||||
if not invoice.private_note.nil?
|
if not invoice.private_note.nil?
|
||||||
invoice.private_note.scan(/#(\w+)/).flatten.each { |issue|
|
invoice.private_note.scan(/#(\w+)/).flatten.each { |issue|
|
||||||
@@ -105,6 +110,7 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
break if vin.nil?
|
break if vin.nil?
|
||||||
if not cf.string_value.to_s.eql? vin
|
if not cf.string_value.to_s.eql? vin
|
||||||
cf.string_value = vin.to_s
|
cf.string_value = vin.to_s
|
||||||
|
logger.debug "VIN has changed"
|
||||||
is_changed = true
|
is_changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -149,7 +155,15 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
|
|
||||||
# Push updates
|
# Push updates
|
||||||
#invoice.sync_token += 1 if is_changed
|
#invoice.sync_token += 1 if is_changed
|
||||||
|
begin
|
||||||
|
if is_changed
|
||||||
|
logger.debug "Trying to update invoice"
|
||||||
get_base.update(invoice) if is_changed
|
get_base.update(invoice) if is_changed
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
#do nothing
|
||||||
|
logger.fatal "Failed to update invoice"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
|
|
||||||
<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
|
<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
|
||||||
<script>
|
<script>
|
||||||
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= qbo_authenticate_url %>'});
|
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= Setting.host_name %>/qbo/authenticate '});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<table >
|
<table >
|
||||||
|
|||||||
Reference in New Issue
Block a user