mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Compare commits
16 Commits
c7a313e9ed
...
2.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e08746611 | |||
| 7eb26facaf | |||
| 9115cc662c | |||
| 9e7c1dbfb2 | |||
| e99f5d2e52 | |||
| 039d1ca993 | |||
| dd9ac3c481 | |||
| 4f789080e7 | |||
| 80fc858a35 | |||
| 6f8d280657 | |||
| 5782cbc166 | |||
| 0729d2ac41 | |||
| 6c6de0ba86 | |||
| 11dbcaf80c | |||
| 95592e542f | |||
| 472bdec4fa |
@@ -142,7 +142,7 @@ class CustomersController < ApplicationController
|
||||
def share
|
||||
|
||||
Thread.new do
|
||||
logger.debug "Removing expired customer tokens"
|
||||
logger.info "Removing expired customer tokens"
|
||||
CustomerToken.remove_expired_tokens
|
||||
ActiveRecord::Base.connection.close
|
||||
end
|
||||
|
||||
@@ -16,6 +16,12 @@ class EstimateController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
||||
|
||||
def get_estimate
|
||||
# Force sync for estimate by doc number
|
||||
begin
|
||||
Estimate.sync_by_doc_number(params[:search]) if params[:search]
|
||||
rescue
|
||||
logger.info "Estimate.find_by_doc_number failed"
|
||||
end
|
||||
estimate = Estimate.find_by_id(params[:id]) if params[:id]
|
||||
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
||||
return estimate
|
||||
|
||||
@@ -26,9 +26,10 @@ class QboController < ApplicationController
|
||||
# Called when the user requests that Redmine to connect to QBO
|
||||
#
|
||||
def authenticate
|
||||
redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
|
||||
logger.info "redirect_uri: " + redirect_uri
|
||||
oauth2_client = Qbo.construct_oauth2_client
|
||||
callback = Setting.host_name + "/qbo/oauth_callback/"
|
||||
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: callback, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
|
||||
grant_url = oauth2_client.auth_code.authorize_url(redirect_uri: redirect_uri, response_type: "code", state: SecureRandom.hex(12), scope: "com.intuit.quickbooks.accounting")
|
||||
redirect_to grant_url
|
||||
end
|
||||
|
||||
@@ -39,7 +40,7 @@ class QboController < ApplicationController
|
||||
if params[:state].present?
|
||||
oauth2_client = Qbo.construct_oauth2_client
|
||||
# use the state value to retrieve from your backend any information you need to identify the customer in your system
|
||||
redirect_uri = Setting.host_name + "/qbo/oauth_callback/"
|
||||
redirect_uri = "https://" + Setting.host_name + qbo_oauth_callback_path
|
||||
if resp = oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
|
||||
|
||||
# Remove the last authentication information
|
||||
@@ -96,7 +97,7 @@ class QboController < ApplicationController
|
||||
id = entity['id'].to_i
|
||||
name = entity['name']
|
||||
|
||||
logger.debug "Casting #{name.constantize} to obj"
|
||||
logger.info "Casting #{name.constantize} to obj"
|
||||
|
||||
# Magicly initialize the correct class
|
||||
obj = name.constantize
|
||||
@@ -123,7 +124,7 @@ class QboController < ApplicationController
|
||||
Qbo.update_time_stamp
|
||||
|
||||
# The webhook doesn't require a response but let's make sure we don't send anything
|
||||
render :nothing => true
|
||||
render :nothing => true, status: 200
|
||||
else
|
||||
render nothing: true, status: 400
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class Estimate < ActiveRecord::Base
|
||||
|
||||
# sync all estimates
|
||||
def self.sync
|
||||
logger.debug "Syncing ALL estimates"
|
||||
logger.info "Syncing ALL estimates"
|
||||
qbo = Qbo.first
|
||||
estimates = qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
@@ -37,7 +37,7 @@ class Estimate < ActiveRecord::Base
|
||||
|
||||
# sync only one estimate
|
||||
def self.sync_by_id(id)
|
||||
logger.debug "Syncing estimate #{id}"
|
||||
logger.info "Syncing estimate #{id}"
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
@@ -45,6 +45,16 @@ class Estimate < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# sync only one estimate
|
||||
def self.sync_by_doc_number(number)
|
||||
logger.info "Syncing estimate by doc number #{number}"
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
process_estimate(service.find_by( :doc_number, number).first)
|
||||
end
|
||||
end
|
||||
|
||||
# update an estimate
|
||||
def self.update(id)
|
||||
# Update the item table
|
||||
|
||||
@@ -17,7 +17,7 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
# sync ALL the invoices
|
||||
def self.sync
|
||||
logger.debug "Syncing all invoices"
|
||||
logger.info "Syncing all invoices"
|
||||
last = Qbo.first.last_sync
|
||||
|
||||
query = "SELECT Id, DocNumber FROM Invoice"
|
||||
@@ -40,7 +40,7 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
#sync by invoice ID
|
||||
def self.sync_by_id(id)
|
||||
logger.debug "Syncing invoice #{id}"
|
||||
logger.info "Syncing invoice #{id}"
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
@@ -58,7 +58,7 @@ class Invoice < ActiveRecord::Base
|
||||
# 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
|
||||
|
||||
logger.debug "Attaching invoice #{invoice.id} to issue #{issue.id}"
|
||||
logger.info "Attaching invoice #{invoice.id} to issue #{issue.id}"
|
||||
|
||||
invoice = Invoice.find_or_create_by(id: invoice.id)
|
||||
|
||||
@@ -105,7 +105,7 @@ class Invoice < 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"
|
||||
logger.info "Comparing custom fields"
|
||||
# TODO break if Invoice.find(invoice.id).cf_sync_confict
|
||||
is_changed = false
|
||||
|
||||
@@ -120,12 +120,12 @@ class Invoice < 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"
|
||||
logger.info " 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
|
||||
cf.string_value = vin.to_s
|
||||
logger.debug "VIN has changed"
|
||||
logger.info "VIN has changed"
|
||||
is_changed = true
|
||||
end
|
||||
|
||||
@@ -155,7 +155,7 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
# Push updates
|
||||
begin
|
||||
logger.debug "Trying to update invoice"
|
||||
logger.info "Trying to update invoice"
|
||||
qbo = Qbo.first
|
||||
qbo.perform_authenticated_request do |access_token|
|
||||
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||
|
||||
@@ -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 -->
|
||||
<script>
|
||||
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= Setting.host_name %>/qbo/authenticate'});
|
||||
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= qbo_authenticate_path %>'});
|
||||
</script>
|
||||
|
||||
<table >
|
||||
|
||||
13
app/views/qbo/webhook.erb
Normal file
13
app/views/qbo/webhook.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<!--
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2024 rick barrette
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<h2>QboController#webhook</h2>
|
||||
2
init.rb
2
init.rb
@@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
name 'Redmine Quickbooks Online plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
|
||||
version '2.0.5'
|
||||
version '2.1.1'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
|
||||
Reference in New Issue
Block a user