From 66d96c9e4c7a3611668a57220f591f3e93acbea2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 12:47:09 -0400 Subject: [PATCH] Send an estimate's lines with status changes QuickBooks refused the Accepted update with "At least 1 line item is required": a sparse estimate update still needs its lines. Status changes (Accepted when issues are created, Closed when an invoice is saved) now go through EstimateWriter.status_update, which sends the estimate's lines back exactly as QuickBooks returned them, so nothing else changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- lib/redmine_qbo_billing/estimate_writer.rb | 18 +++++++++++++----- lib/redmine_qbo_billing/invoice_writer.rb | 7 +------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/redmine_qbo_billing/estimate_writer.rb b/lib/redmine_qbo_billing/estimate_writer.rb index e72ba91..4a5aeb8 100644 --- a/lib/redmine_qbo_billing/estimate_writer.rb +++ b/lib/redmine_qbo_billing/estimate_writer.rb @@ -169,6 +169,18 @@ module RedmineQboBilling # Statuses an estimate moves from to Accepted when the work starts (issues are created from it) ACCEPTABLE_STATUSES = ['', 'Pending'].freeze + # A sparse update that only changes an estimate's status. QuickBooks still requires the estimate's lines + # in it ("At least 1 line item is required"), so they're sent back exactly as QuickBooks returned them. + def status_update(estimate, status) + update = Quickbooks::Model::Estimate.new + update.id = estimate.id + update.sync_token = estimate.sync_token + update.customer_ref = estimate.customer_ref + update.line_items = Array(estimate.line_items) + update.txn_status = status + update + end + AcceptResult = Struct.new(:outcome, :message) do def accepted?; outcome == :accepted; end def failed?; outcome == :failed; end @@ -184,11 +196,7 @@ module RedmineQboBilling next [:failed, I18n.t(:notice_estimate_not_found)] if estimate.nil? next [:unchanged, estimate.txn_status.to_s] unless ACCEPTABLE_STATUSES.include?(estimate.txn_status.to_s) - update = Quickbooks::Model::Estimate.new - update.id = estimate.id - update.sync_token = estimate.sync_token - update.customer_ref = estimate.customer_ref - update.txn_status = 'Accepted' + update = status_update(estimate, 'Accepted') update.accepted_date = user.today update.accepted_by = estimate.customer_ref&.name.presence || Customer.find_by(id: estimate.customer_ref&.value)&.name diff --git a/lib/redmine_qbo_billing/invoice_writer.rb b/lib/redmine_qbo_billing/invoice_writer.rb index fbe0f50..66543b9 100644 --- a/lib/redmine_qbo_billing/invoice_writer.rb +++ b/lib/redmine_qbo_billing/invoice_writer.rb @@ -270,12 +270,7 @@ module RedmineQboBilling # Already Converted or Closed is left as QuickBooks set it next if estimate.nil? || BILLED_ESTIMATE_STATUSES.include?(estimate.txn_status.to_s) - update = Quickbooks::Model::Estimate.new - update.id = estimate.id - update.sync_token = estimate.sync_token - update.customer_ref = estimate.customer_ref - update.txn_status = 'Closed' - service.update(update, sparse: true) + service.update(writer.status_update(estimate, 'Closed'), sparse: true) end EstimateSyncService.new.sync_by_id(id) rescue StandardError => e