diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb
index f692e0e..25e3715 100644
--- a/app/controllers/qbo_controller.rb
+++ b/app/controllers/qbo_controller.rb
@@ -46,9 +46,13 @@ class QboController < ApplicationController
redirect_to issue || root_path, flash: { error: e.message }
end
- # Manual sync endpoint to trigger a full synchronization of QuickBooks entities with the local database. Enqueues all relevant sync jobs and redirects to the home page with a notice that syncing has started.
+ # Manual sync endpoint to trigger synchronization of QuickBooks entities
+ # with the local database. Supports full or partial sync depending on
+ # the `full_sync` boolean parameter.
def sync
- QboSyncDispatcher.full_sync!
+ full_sync = ActiveModel::Type::Boolean.new.cast(params[:full_sync])
+ QboSyncDispatcher.sync!(full_sync: full_sync)
+
redirect_to :home, flash: { notice: I18n.t(:label_syncing) }
end
diff --git a/app/jobs/qbo_sync_dispatcher.rb b/app/jobs/qbo_sync_dispatcher.rb
index 69f8b7a..09ea3ec 100644
--- a/app/jobs/qbo_sync_dispatcher.rb
+++ b/app/jobs/qbo_sync_dispatcher.rb
@@ -17,9 +17,17 @@ class QboSyncDispatcher
Employee
].freeze
- # Dispatches all synchronization jobs to perform a full sync of QuickBooks entities with the local database. Each job is enqueued with the `full_sync` flag set to true.
- def self.full_sync!
+ # Dispatches all synchronization jobs to perform a full sync of QuickBooks entities with the local database.
+ # Each job is enqueued with the `full_sync` flag set to true.
+ def self.sync!(full_sync: false)
+ log "Manual Sync initated for #{full_sync ? "full sync" : "incremental sync"}"
+ enque_jobs full_sync: full_sync
+ end
+ private
+
+ # Dynamically enques all sync jobs
+ def self.enque_jobs(full_sync: full_sync)
jobs = SYNC_JOBS.dup
# Allow other plugins to add addtional sync jobs via Hooks
@@ -29,11 +37,9 @@ class QboSyncDispatcher
log "Added additionals QBO Sync Job for #{context.to_s}"
end
- jobs.each { |job| QboSyncJob.perform_later(entity: job, full_sync: true) }
+ jobs.each { |job| QboSyncJob.perform_later(entity: job, full_sync: full_sync) }
end
- private
-
def self.log(msg)
Rails.logger.info "[QboSyncDispatcher] #{msg}"
end
diff --git a/app/views/customers/_search.html.erb b/app/views/customers/_search.html.erb
index f7d66aa..98145bd 100644
--- a/app/views/customers/_search.html.erb
+++ b/app/views/customers/_search.html.erb
@@ -3,3 +3,4 @@
<%= submit_tag t(:label_search) %>
<% end %>
<%= button_to t(:label_new_customer), new_customer_path, method: :get%>
+<%= button_to(t(:label_sync), qbo_sync_path, method: :get) if User.current.admin?%>
diff --git a/app/views/qbo/_settings.html.erb b/app/views/qbo/_settings.html.erb
index 932d9f5..552ef01 100644
--- a/app/views/qbo/_settings.html.erb
+++ b/app/views/qbo/_settings.html.erb
@@ -107,5 +107,5 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI