Update customer.rb

This commit is contained in:
2016-05-17 13:28:41 -04:00
parent c72d375aea
commit fd8ca2d44d

View File

@@ -105,20 +105,24 @@ class Customer < ActiveRecord::Base
def self.sync def self.sync
last = Qbo.first.last_sync last = Qbo.first.last_sync
query = "Select Id, DisplayName From Customer" background do
query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
query << " Order By DisplayName "
customers = Qbo.get_base(:customer).service.query_in_batches(query, per_page: 100) do |batch| query = "Select Id, DisplayName From Customer"
batch.each do |customer| query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
without_callback(:save, :before, :save) do query << " Order By DisplayName "
# Update the customer table
qbo_customer = Customer.find_or_create_by(id: customer.id) customers = Qbo.get_base(:customer).service.query_in_batches(query, per_page: 100) do |batch|
qbo_customer.name = customer.display_name batch.each do |customer|
qbo_customer.id = customer.id without_callback(:save, :before, :save) do
qbo_customer.save # Update the customer table
qbo_customer = Customer.find_or_create_by(id: customer.id)
qbo_customer.name = customer.display_name
qbo_customer.id = customer.id
qbo_customer.save
end
end end
end end
end end
# remove deleted customers # remove deleted customers