From 4fb424faa8c0b89f23663b9dcdc97856cbf7ff13 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Tue, 20 Aug 2024 07:14:37 -0400 Subject: [PATCH] Only sync by doc number if not in database --- app/controllers/estimate_controller.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index 06d4c2b..f7ffbfa 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -16,12 +16,15 @@ class EstimateController < ApplicationController skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? } def get_estimate - # Force sync for estimate by doc number - begin - Estimate.sync_by_doc_number(params[:search]) if params[:search] - rescue - logger.info "Estimate.find_by_doc_number failed" + # Force sync for estimate by doc number if not found + if Estimate.find_by_doc_number(params[:search]).nil? + begin + Estimate.sync_by_doc_number(params[:search]) if params[:search] + rescue + logger.info "Estimate.find_by_doc_number failed" + end end + estimate = Estimate.find_by_id(params[:id]) if params[:id] estimate = Estimate.find_by_doc_number(params[:search]) if params[:search] return estimate