mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
2 files changed
+14
-11
No files matched your search
@@ -169,6 +169,18 @@ module RedmineQboBilling
|
|||||||
# Statuses an estimate moves from to Accepted when the work starts (issues are created from it)
|
# Statuses an estimate moves from to Accepted when the work starts (issues are created from it)
|
||||||
ACCEPTABLE_STATUSES = ['', 'Pending'].freeze
|
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
|
AcceptResult = Struct.new(:outcome, :message) do
|
||||||
def accepted?; outcome == :accepted; end
|
def accepted?; outcome == :accepted; end
|
||||||
def failed?; outcome == :failed; end
|
def failed?; outcome == :failed; end
|
||||||
@@ -184,11 +196,7 @@ module RedmineQboBilling
|
|||||||
next [:failed, I18n.t(:notice_estimate_not_found)] if estimate.nil?
|
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)
|
next [:unchanged, estimate.txn_status.to_s] unless ACCEPTABLE_STATUSES.include?(estimate.txn_status.to_s)
|
||||||
|
|
||||||
update = Quickbooks::Model::Estimate.new
|
update = status_update(estimate, 'Accepted')
|
||||||
update.id = estimate.id
|
|
||||||
update.sync_token = estimate.sync_token
|
|
||||||
update.customer_ref = estimate.customer_ref
|
|
||||||
update.txn_status = 'Accepted'
|
|
||||||
update.accepted_date = user.today
|
update.accepted_date = user.today
|
||||||
update.accepted_by = estimate.customer_ref&.name.presence ||
|
update.accepted_by = estimate.customer_ref&.name.presence ||
|
||||||
Customer.find_by(id: estimate.customer_ref&.value)&.name
|
Customer.find_by(id: estimate.customer_ref&.value)&.name
|
||||||
|
|||||||
@@ -270,12 +270,7 @@ module RedmineQboBilling
|
|||||||
# Already Converted or Closed is left as QuickBooks set it
|
# Already Converted or Closed is left as QuickBooks set it
|
||||||
next if estimate.nil? || BILLED_ESTIMATE_STATUSES.include?(estimate.txn_status.to_s)
|
next if estimate.nil? || BILLED_ESTIMATE_STATUSES.include?(estimate.txn_status.to_s)
|
||||||
|
|
||||||
update = Quickbooks::Model::Estimate.new
|
service.update(writer.status_update(estimate, 'Closed'), sparse: true)
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
EstimateSyncService.new.sync_by_id(id)
|
EstimateSyncService.new.sync_by_id(id)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
|||||||
Reference in new issue
Block a user