Update qbo_customer.rb

Added Transaction
This commit is contained in:
2016-03-31 09:08:56 -04:00
parent 39a2e1564f
commit d33eba2b20

View File

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