From 2d96f6653b18b913c7d5db2f2d6e367d9b7f80ae Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Mon, 29 Feb 2016 09:33:43 -0500 Subject: [PATCH] Update qbo_customer.rb Simplified Customer Deletion --- app/models/qbo_customer.rb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/app/models/qbo_customer.rb b/app/models/qbo_customer.rb index a8a69da..27a7cd3 100644 --- a/app/models/qbo_customer.rb +++ b/app/models/qbo_customer.rb @@ -24,24 +24,14 @@ class QboCustomer < ActiveRecord::Base end def self.update_all - - service = get_base.service - + customers = get_base.service.all # Update the customer table - service.all.each { |customer| + customers.each { |customer| qbo_customer = QboCustomer.find_or_create_by(id: customer.id) - qbo_customer.id = customer.id qbo_customer.name = customer.display_name qbo_customer.save! } - #remove deleted customers - all.each { |customer| - begin - service.fetch_by_id(customer.id) - rescue - delete_all(id: customer.id) - end - } + where.not(customers.map(&:id)).destroy_all end end