Updated to quickbooks-ruby-base and added QboEstimate

This commit is contained in:
2016-01-12 20:55:56 -05:00
parent a10b075ab8
commit ddb4f40486
6 changed files with 63 additions and 26 deletions

View File

@@ -10,11 +10,12 @@
class Qbo < ActiveRecord::Base
unloadable
validates_presence_of :token, :secret, :realmId, :token_expires_at, :reconnect_token_at
validates_presence_of :qb_token, :qb_secret, :company_id, :token_expires_at, :reconnect_token_at
QB_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey']
QB_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
# Quickbooks Config Info
$qb_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
@@ -22,16 +23,15 @@ class Qbo < ActiveRecord::Base
:access_token_path => "/oauth/v1/get_access_token"
})
def self.get_auth_token
qbo = first
return OAuth::AccessToken.new($qb_oauth_consumer, qbo.token, qbo.secret)
# Configure quickbooks-ruby-base to access our database
Quickbooks::Base.configure do |c|
c.persistent_token = 'qb_token'
c.persistent_secret = 'qb_secret'
c.persistent_company_id = 'company_id'
end
def self.get_oauth_consumer
return $qb_oauth_consumer
end
def self.get_realm_id
return first.realmId
# Get the QBO account
def self.get_account
first
end
end

View File

@@ -14,12 +14,17 @@ class QboCustomers < ActiveRecord::Base
attr_accessible :name
validates_presence_of :id, :name
def self.update_all
qbo = Qbo.first
service = Quickbooks::Service::Customer.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
def self.get_base
Quickbooks::Base.new(Qbo.get_account, :employee)
end
def self.get_customer (id)
get_base.service.find_by_id(id)
end
def self.update_all
# Update the customer table
service.all.each { |customer|
get_base.service.all.each { |customer|
qbo_customer = QboCustomers.find_or_create_by(id: customer.id)
qbo_customer.id = customer.id
qbo_customer.name = customer.display_name

View File

@@ -14,12 +14,13 @@ class QboEmployee < ActiveRecord::Base
attr_accessible :name
validates_presence_of :id, :name
def self.update_all
qbo = Qbo.first
service = Quickbooks::Service::Employee.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
def self.get_base
Quickbooks::Base.new(Qbo.get_account, :employee)
end
def self.update_all
# Update the item table
service.all.each { |employee|
get_base.service.all.each { |employee|
qbo_employee = QboEmployee.find_or_create_by(id: employee.id)
qbo_employee.name = employee.display_name
qbo_employee.id = employee.id

View File

@@ -0,0 +1,30 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 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.
class QboEstimate < ActiveRecord::Base
unloadable
has_many :issues
attr_accessible :doc_number
validates_presence_of :id, :doc_number
def self.get_base
Quickbooks::Base.new(Qbo.get_account, :estimate)
end
def self.update_all
# Update the item table
get_base.service.all.each { |estimate|
qbo_estimate = QboItem.find_or_create_by(id: estimate.id)
qbo_estimate.name = estimate.doc_number
qbo_estimate.id = estimate.id
qbo_estimate.save!
}
end
end

View File

@@ -14,12 +14,13 @@ class QboItem < ActiveRecord::Base
attr_accessible :name
validates_presence_of :id, :name
def self.update_all
qbo = Qbo.first
service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
def self.get_base
Quickbooks::Base.new(Qbo.get_account, :item)
end
def self.update_all
# Update the item table
service.find_by(:type, "Service").each { |item|
get_base.service.find_by(:type, "Service").each { |item|
qbo_item = QboItem.find_or_create_by(id: item.id)
qbo_item.name = item.name
qbo_item.id = item.id

View File

@@ -21,7 +21,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
# if this is a quote, lets create a new estimate based off estimated hours
if issue.tracker.name = "Quote" and issue.status.name = "New" and issue.custom_field_value(CustomField.find_by_name("Estimate").id).empty? then
item_service = Quickbooks::Service::Item.new(:company_id => Qbo.get_realm_id, :access_token => Qbo.get_auth_token)
item_service = QboItem.get_base.service
estimate = Quickbooks::Model::Estimate .new
estimate .customer_id = issue.qbo_customer_id