Mark an estimate Accepted when issues are created from it

Creating issues from an estimate means the work is going ahead, so a pending estimate becomes Accepted in
QuickBooks (sparse update with today's accepted date, like closing an estimate) and the local estimate is
synced, so its status badge updates. Accepted, Closed, Converted and Rejected estimates are left alone. A
failure is logged and doesn't affect the created issues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 12:36:05 -04:00
1 parent ec6fecbd85
commit 338b4db237
4 files changed
+32 -1

No files matched your search

+1 -1
View File
@@ -106,7 +106,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, custom fields and messages, dated today, with the current user as sales person.
* **Read-only once linked to an issue**: an estimate that an issue is linked to can be viewed, emailed and duplicated, but not changed, so the work doesn't drift from what was quoted. The list shows a View link for these instead of Edit.
* **Read-only once billed**: an estimate that's Converted or Closed in QuickBooks, or linked to an invoice, can't be changed here either (including redmine_qbo_lineitems' estimates once they're invoiced). Its page lists the invoices it's on; it can still be viewed, emailed and duplicated, and it shows View instead of Edit in lists.
* **Create issues** from an estimate's labor lines (moved here from redmine_qbo_calendar): each line with one of the **labor products/services** (e.g. Labor) becomes an issue with the line's description as subject and its quantity as estimated hours. Pick the project, trackers, templates and shared custom fields first. Lines already turned into issues can't be created twice, and issues from the same estimate are related to each other. Opened from an appointment, the issues get the appointment's dates, technician and vehicle.
* **Create issues** from an estimate's labor lines (moved here from redmine_qbo_calendar): each line with one of the **labor products/services** (e.g. Labor) becomes an issue with the line's description as subject and its quantity as estimated hours. Pick the project, trackers, templates and shared custom fields first. Lines already turned into issues can't be created twice, and issues from the same estimate are related to each other. Creating issues marks a pending estimate **Accepted** in QuickBooks (dated today), since the work is going ahead; estimates that are already accepted, closed, converted or rejected keep their status. Opened from an appointment, the issues get the appointment's dates, technician and vehicle.
* **Email** the estimate with QuickBooks' own estimate email, with **Save and send** or the Email link.
* The page follows QuickBooks' estimate screen: customer, customer email, billing address, estimate date, expiration date, estimate number, then the product/service lines (#, product/service, description, qty, rate, amount, tax), the message displayed on the estimate, the memo, and the totals.
* Lines work like QuickBooks: the product list opens when the box is clicked, picking a product fills in its description, rate and tax, typing an amount works out the rate, a spare empty line is always at the bottom, and lines are reordered by dragging them by the handle.
@@ -96,7 +96,10 @@ class QboEstimatesController < ApplicationController
if created.any?
Redmine::Hook.call_hook(:qbo_billing_issues_created, { estimate: @estimate, issues: created, params: params })
# The work is going ahead: a pending estimate becomes Accepted in QuickBooks
accepted = RedmineQboBilling::EstimateWriter.accept(@estimate.id, user: User.current)
flash[:notice] = l(:notice_estimate_issues_created, count: created.size)
flash[:notice] += " #{l(:notice_estimate_accepted, number: @estimate.doc_number)}" if accepted
redirect_to @return_path
else
# Rebuild the fields so the form keeps what was entered
+1
View File
@@ -269,6 +269,7 @@ en:
label_estimate_line_already_created: "Already created"
label_issue_template: "Template"
label_no_issue_template: "(no template)"
notice_estimate_accepted: "Estimate #%{number} is now Accepted in QuickBooks."
notice_estimate_issues_created:
one: "1 issue created from the estimate"
other: "%{count} issues created from the estimate"
@@ -166,6 +166,33 @@ module RedmineQboBilling
end
end
# Statuses an estimate moves from to Accepted when the work starts (issues are created from it)
ACCEPTABLE_STATUSES = ['', 'Pending'].freeze
# Marks the estimate Accepted in QuickBooks, dated today, when issues are created from it (the customer
# went ahead with the work). Only a pending estimate changes; Accepted, Closed, Converted or Rejected ones
# are left as they are. Returns true when it changed. A failure is logged, not raised: the issues stand.
def accept(estimate_id, user: User.current)
accepted = QboEstimateService.with_service do |service|
estimate = service.fetch_by_id(estimate_id)
next false if estimate.nil? || !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.accepted_date = user.today
service.update(update, sparse: true)
true
end
sync_local(Struct.new(:id).new(estimate_id)) if accepted
accepted
rescue StandardError => e
Rails.logger.warn "[RedmineQboBilling] Could not mark estimate #{estimate_id} accepted: #{e.message}"
false
end
# Emails the estimate; QuickBooks uses its own estimate email template
def send_email(id, email)
sent = QboEstimateService.with_service { |service| service.send_estimate(id, email) }