Compare commits

...

5 Commits

Author SHA1 Message Date
9f9810686f removed logging 2026-03-03 20:36:23 -05:00
f041e1bce4 Added logging for completed pull 2026-03-03 20:05:19 -05:00
d44d5e2fb7 Fixed log prefix 2026-03-03 19:54:50 -05:00
4403267abb Moved QBO fetch from customer model into service 2026-03-03 19:49:36 -05:00
be400c2b2a Added logging for errors when editing 2026-03-03 19:22:15 -05:00
3 changed files with 26 additions and 17 deletions

View File

@@ -98,8 +98,9 @@ class CustomersController < ApplicationController
def edit
@customer = Customer.find_by_id(params[:id])
return render_404 unless @customer
rescue
flash[:error] = t :notice_customer_not_found
rescue => e
log "Failed to edit customer"
flash[:error] = e.message
render_404
end

View File

@@ -164,9 +164,9 @@ class Customer < ActiveRecord::Base
# Push the updates
def save_with_push
qbo = QboConnectionService.current!
log "Starting push for customer ##{self.id}..."
CustomerPushService.new(qbo: qbo, customer: self).push()
qbo = QboConnectionService.current!
CustomerService.new(qbo: qbo, customer: self).push()
save_without_push
end
@@ -180,16 +180,7 @@ class Customer < ActiveRecord::Base
return Quickbooks::Model::Customer.new unless id.present?
log "Fetching details for customer ##{id} from QBO..."
qbo = QboConnectionService.current!
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(
company_id: qbo.realm_id,
access_token: access_token
)
service.fetch_by_id(id)
end
rescue => e
log "Fetch failed for #{id}: #{e.message}"
Quickbooks::Model::Customer.new
CustomerService.new(qbo: qbo, customer: self).pull()
end
# Log messages with the entity type for better traceability

View File

@@ -8,7 +8,7 @@
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class CustomerPushService
class CustomerService
# Initializes the service with a QBO client and an optional customer record. The QBO client is used to communicate with QuickBooks Online, while the customer record contains the data that needs to be pushed to QBO. If no customer is provided, the service will not perform any operations.
def initialize(qbo:, customer: nil)
@@ -18,7 +18,24 @@ class CustomerPushService
@customer = customer
end
# Pushes the customer data to QuickBooks Online. This method handles the communication with QBO, including authentication and error handling. It uses the QBO client to send the customer data and logs the process for monitoring and debugging purposes. If the push is successful, it returns the customer record; otherwise, it logs the error and returns false.
# Pulls the customer data from QuickBooks Online.
def pull
return Quickbooks::Model::Customer.new unless @customer.present?
log "Fetching details for customer ##{@customer.id} from QBO..."
qbo = QboConnectionService.current!
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Customer.new(
company_id: qbo.realm_id,
access_token: access_token
)
service.fetch_by_id(@customer.id)
end
rescue => e
log "Fetch failed for #{@customer.id}: #{e.message}"
Quickbooks::Model::Customer.new
end
# Pushes the customer data to QuickBooks Online. This method handles the communication with QBO, including authentication and error handling. It uses the QBO client to send the customer data and logs the process for monitoring and debugging purposes. If the push is successful, it returns the customer record; otherwise, it logs the error and returns false.
def push
log "Pushing customer ##{@customer.id} to QBO..."
@@ -39,7 +56,7 @@ class CustomerPushService
# Log messages with the entity type for better traceability
def log(msg)
Rails.logger.info "[CustomerPushService] #{msg}"
Rails.logger.info "[CustomerService] #{msg}"
end
end