mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Update customer.rb
This commit is contained in:
@@ -105,26 +105,22 @@ class Customer < ActiveRecord::Base
|
|||||||
def self.sync
|
def self.sync
|
||||||
last = Qbo.first.last_sync
|
last = Qbo.first.last_sync
|
||||||
|
|
||||||
background do
|
query = "Select Id, DisplayName From Customer"
|
||||||
|
#query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
|
||||||
|
query << " Order By DisplayName "
|
||||||
|
|
||||||
query = "Select Id, DisplayName From Customer"
|
customers = Qbo.get_base(:customer).service.query_in_batches(query, per_page: 100) do |batch|
|
||||||
query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last
|
batch.each do |customer|
|
||||||
query << " Order By DisplayName "
|
without_callback(:save, :before, :save) do
|
||||||
|
# Update the customer table
|
||||||
customers = Qbo.get_base(:customer).service.query_in_batches(query, per_page: 100) do |batch|
|
qbo_customer = Customer.find_or_create_by(id: customer.id)
|
||||||
batch.each do |customer|
|
qbo_customer.name = customer.display_name
|
||||||
without_callback(:save, :before, :save) do
|
qbo_customer.id = customer.id
|
||||||
# Update the customer table
|
qbo_customer.save
|
||||||
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
|
||||||
#where.not(customers.map(&:id)).destroy_all
|
#where.not(customers.map(&:id)).destroy_all
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user