Update qbo_customer.rb

Simplified Customer Deletion
This commit is contained in:
2016-02-29 09:33:43 -05:00
parent b4833d7a5f
commit 2d96f6653b

View File

@@ -24,24 +24,14 @@ class QboCustomer < ActiveRecord::Base
end end
def self.update_all def self.update_all
customers = get_base.service.all
service = get_base.service
# Update the customer table # Update the customer table
service.all.each { |customer| customers.each { |customer|
qbo_customer = QboCustomer.find_or_create_by(id: customer.id) qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
qbo_customer.id = customer.id
qbo_customer.name = customer.display_name qbo_customer.name = customer.display_name
qbo_customer.save! qbo_customer.save!
} }
#remove deleted customers #remove deleted customers
all.each { |customer| where.not(customers.map(&:id)).destroy_all
begin
service.fetch_by_id(customer.id)
rescue
delete_all(id: customer.id)
end
}
end end
end end