From 643b15391bf109f3c3df0e20626a39b37498c3cb Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sun, 8 Mar 2026 15:04:57 -0400 Subject: [PATCH] Added support for adding other QBO entities from othe plugins --- README.md | 14 ++++++++------ app/jobs/qbo_sync_dispatcher.rb | 19 ++++++++++++++++++- app/jobs/webhook_process_job.rb | 9 ++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4a3fe2e..d53b5e8 100644 --- a/README.md +++ b/README.md @@ -117,12 +117,14 @@ Adds support for tracking **customer vehicles** associated with Issues. Available hooks: -|Type|Hook| -|--|---| -View Hook|:pdf\_left, { issue: issue } -View Hook|:pdf\_right, { issue: issue } -Hook|process\_invoice\_custom\_fields, { issue: issue, invoice: invoice } -View Hook|:show\_customer\_view\_right, { customer: customer } +|Type|Hook|Note +|--|--|--| +View Hook|:pdf_left, { issue: issue } | Used to add text to left side of PDF +View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF +Hook|process_invoice_custom_fields, { issue: issue, invoice: invoice } | Used to process invoice custom fields +View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view +Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob +Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher --- diff --git a/app/jobs/qbo_sync_dispatcher.rb b/app/jobs/qbo_sync_dispatcher.rb index 792153e..5436f34 100644 --- a/app/jobs/qbo_sync_dispatcher.rb +++ b/app/jobs/qbo_sync_dispatcher.rb @@ -19,6 +19,23 @@ class QboSyncDispatcher # 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! - SYNC_JOBS.each { |job| job.perform_later(full_sync: true) } + + jobs = SYNC_JOBS.dup + + # Allow other plugins to add addtional sync jobs via Hooks + Redmine::Hook.call_hook( :qbo_full_sync ).each do |context| + next unless context + jobs.push context + log "Added additionals QBO Sync Job for #{contex.to_s}" + end + + jobs.each { |job| job.perform_later(full_sync: true) } end + + private + + def self.log(msg) + Rails.logger.info "[QboSyncDispatcher] #{msg}" + end + end \ No newline at end of file diff --git a/app/jobs/webhook_process_job.rb b/app/jobs/webhook_process_job.rb index 46a0ff3..03a0cdc 100644 --- a/app/jobs/webhook_process_job.rb +++ b/app/jobs/webhook_process_job.rb @@ -43,7 +43,14 @@ class WebhookProcessJob < ActiveJob::Base name = entity['name'] id = entity['id']&.to_i - return unless ALLOWED_ENTITIES.include?(name) + entitys = ALLOWED_ENTITIES.dup + # Allow other plugins to add addtional qbo entities via Hooks + Redmine::Hook.call_hook( :qbo_additional_entities ).each do |context| + next unless context + entitys.push context + log "Added additional QBO entities: #{context}" + end + return unless entitys.include?(name) model = name.safe_constantize return unless model