diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index fd37dd0..392ad3b 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -16,6 +16,8 @@ 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 + Estimate.sync_by_doc_number if params[:search] estimate = Estimate.find_by_id(params[:id]) if params[:id] estimate = Estimate.find_by_doc_number(params[:search]) if params[:search] return estimate diff --git a/app/models/estimate.rb b/app/models/estimate.rb index d92c406..487da7b 100644 --- a/app/models/estimate.rb +++ b/app/models/estimate.rb @@ -18,7 +18,7 @@ class Estimate < ActiveRecord::Base # sync all estimates def self.sync - logger.debug "Syncing ALL estimates" + logger.info "Syncing ALL estimates" qbo = Qbo.first estimates = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) @@ -37,13 +37,23 @@ class Estimate < ActiveRecord::Base # sync only one estimate def self.sync_by_id(id) - logger.debug "Syncing estimate #{id}" + logger.info "Syncing estimate #{id}" qbo = Qbo.first qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) process_estimate(service.fetch_by_id(id)) end end + + # sync only one estimate + def self.sync_by_doc_number(number) + logger.info "Syncing estimate by doc number #{number}" + qbo = Qbo.first + qbo.perform_authenticated_request do |access_token| + service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) + process_estimate(service.find_by( :doc_number, number)) + end + end # update an estimate def self.update(id)