From 327d59d380c6f93013abf51c3271d04516433011 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 24 May 2016 11:35:13 -0400 Subject: [PATCH] Update customer.rb --- app/models/customer.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 7526afd..1576642 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -20,7 +20,9 @@ class Customer < ActiveRecord::Base validates_presence_of :id, :name after_initialize :pull - before_save :push + #before_save :push + + alias_method_chain :save, :push self.primary_key = :id @@ -108,14 +110,12 @@ class Customer < ActiveRecord::Base query = "Select Id, DisplayName From Customer" query << " Where Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last - without_callback(:save, :before, :save) do - Qbo.get_base(:customer).service.query(query).each do |customer| - Customer.transaction do - 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 + Qbo.get_base(:customer).service.query(query).each do |customer| + Customer.transaction do + qbo_customer = Customer.find_or_create_by(id: customer.id) + qbo_customer.name = customer.display_name + qbo_customer.id = customer.id + qbo_customer.save_without_push end end @@ -151,7 +151,7 @@ class Customer < ActiveRecord::Base end # Push the updates - def push + def save_with_push begin #tries ||= 3 @details = Qbo.get_base(:customer).service.update(@details)