From 4ec8ceca1bd0f45ffcb577d2aa4c9389bebccd0f Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 17 May 2016 07:06:22 -0400 Subject: [PATCH] Update customer.rb --- app/models/customer.rb | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index c9b1c23..cee7c51 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -105,26 +105,16 @@ class Customer < ActiveRecord::Base customers = Qbo.get_base(:customer).service.query() - transaction do - # Update the customer table - customers.each { |customer| - - background do - Customer.without_callback(:initialize, :after, :pull) do - Customer.without_callback(:save, :before, :push) do - qbo_customer = Customer.find_or_create_by(id: customer.id) - # only update if diffrent - if qbo_customer.new_record? - qbo_customer.name = customer.display_name - qbo_customer.id = customer.id - qbo_customer.save! - end - end - end - end - } - end - + # Update the customer table + customers.each { |customer| + background do + qbo_customer = Customer.find_or_create_by(id: customer.id) + qbo_customer.update_column(:name, customer.display_name) + qbo_customer.update_column(:id, customer.id) + qbo_customer.save + end + } + # remove deleted customers #where.not(customers.map(&:id)).destroy_all end