From ef7faee6850528883103f96d44a4e514a6b54047 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 27 Jan 2026 20:50:54 -0500 Subject: [PATCH] Process updates from the hooks --- app/models/invoice.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index dfb3ef6..264895c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -112,15 +112,15 @@ class Invoice < ActiveRecord::Base logger.debug "Calling :process_invoice_custom_fields hook" context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice } - unless context.nil? - logger.debug "We have a context!" - context= context.first - issue = context[:issue] - invoice = context[:invoice] - is_changed = context[:is_changed] + # Process updates from the hooks + context.each do |c| + unless c.nil? + logger.debug "Invoice.compare_custom_fields: We have a responce from a hook" + push_updates c[:invoice] if c[:is_changed] + end end - # Custom Values + # Process Issue Custom Values begin value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id) @@ -137,13 +137,17 @@ class Invoice < ActiveRecord::Base # Nothing to do here, there is no match end - # Push updates + push_updates invoice if is_changed + end + + # pushes invoice updates + def self.push_updates(invoice) begin - logger.info "Trying to update invoice" + logger.info "Invoice.push_updates" qbo = Qbo.first qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) - service.update(invoice) if is_changed + service.update invoice end rescue # Do nothing, probaly custome field sync confict on the invoice.