Added Estimate.sync_by_doc_number

This commit is contained in:
2024-08-19 22:30:34 -04:00
parent 4f789080e7
commit dd9ac3c481
2 changed files with 14 additions and 2 deletions

View File

@@ -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

View File

@@ -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)