From 19acfbc76f0ef6d71c8ae40c2b0075db80033d57 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Mon, 21 Feb 2022 08:51:01 -0500 Subject: [PATCH] Added logging --- app/controllers/qbo_controller.rb | 6 +++--- app/models/qbo_estimate.rb | 5 ++++- app/models/qbo_invoice.rb | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index 0c19656..ec06c99 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -92,7 +92,7 @@ class QboController < ApplicationController # Quickbooks Webhook Callback def qbo_webhook - logger.debug "Quickbooks is calling webhook" + logger.info "Quickbooks is calling webhook" # check the payload signature = request.headers['intuit-signature'] @@ -149,14 +149,14 @@ class QboController < ApplicationController render nothing: true, status: 400 end - logger.debug "Quickbooks webhook complete" + logger.info "Quickbooks webhook complete" end # # Synchronizes the QboCustomer table with QBO # def sync - logger.debug "Syncing EVERYTHING" + logger.info "Syncing EVERYTHING" # Update info in background Thread.new do if Qbo.exists? diff --git a/app/models/qbo_estimate.rb b/app/models/qbo_estimate.rb index 615a774..4bb370a 100644 --- a/app/models/qbo_estimate.rb +++ b/app/models/qbo_estimate.rb @@ -23,7 +23,8 @@ class QboEstimate < ActiveRecord::Base end # sync all estimates - def self.sync + def self.sync + logger.debug "Syncing ALL estimates" estimates = get_base.all estimates.each { |estimate| process_estimate(estimate) @@ -35,6 +36,7 @@ class QboEstimate < ActiveRecord::Base # sync only one estimate def self.sync_by_id(id) + logger.debug "Syncing estimate #{id}" process_estimate(get_base.fetch_by_id(id)) end @@ -49,6 +51,7 @@ class QboEstimate < ActiveRecord::Base # process an estimate into the database def self.process_estimate(estimate) + logger.info "Processing estimate #{estimate.id}" qbo_estimate = find_or_create_by(id: estimate.id) qbo_estimate.doc_number = estimate.doc_number qbo_estimate.customer_id = estimate.customer_ref.value diff --git a/app/models/qbo_invoice.rb b/app/models/qbo_invoice.rb index 7a92641..74e5321 100644 --- a/app/models/qbo_invoice.rb +++ b/app/models/qbo_invoice.rb @@ -71,7 +71,7 @@ class QboInvoice < ActiveRecord::Base # processes the invoice into the database def self.process_invoice(invoice) - logger.debug "Processing invoice" + logger.info "Processing invoice #{invoice.id}" # Load the invoice into the database qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id) @@ -104,6 +104,7 @@ class QboInvoice < ActiveRecord::Base # this condions causes an infinite loop as the webhook is called when an invoice is updated # TODO maybe add a cf_sync_confict flag to invoices def self.compare_custom_fields(issue, invoice) + logger.debug "Comparing custom fields" # TODO break if QboInvoice.find(invoice.id).cf_sync_confict is_changed = false @@ -118,7 +119,7 @@ class QboInvoice < ActiveRecord::Base # Only update if blank to prevent infite loops # TODO check cf_sync_confict flag once implemented if cf.string_value.to_s.blank? - + logger.debug " VIN was blank, updating the invoice vin in quickbooks" vin = Vehicle.find(issue.vehicles_id).vin break if vin.nil? if not cf.string_value.to_s.eql? vin