Make billed estimates read-only

An estimate that's Converted or Closed in QuickBooks, or linked to an invoice, opens read-only and is
refused on save (this includes redmine_qbo_lineitems' estimates once invoiced). Its page lists the
invoices it's on. Estimates cache their status so lists show View instead of Edit for them.

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 08:34:41 -04:00
1 parent 4732c32409
commit 3304fce92f
10 files changed
+45 -23

No files matched your search

+15 -2
View File
@@ -121,6 +121,7 @@ module RedmineQboBilling
remote = service.fetch_by_id(form.id)
raise Error, I18n.t(:notice_estimate_not_found) unless remote
raise Conflict, I18n.t(:error_estimate_changed_in_quickbooks) if remote.sync_token.to_s != form.sync_token.to_s
raise Error, I18n.t(:error_estimate_billed) if billed?(remote)
raise Error, I18n.t(:error_estimate_has_bundles) if group_lines?(remote)
raise Error, I18n.t(:error_estimate_linked_to_issues) if linked_issues(form.id).any?
@@ -150,6 +151,16 @@ module RedmineQboBilling
# ---- QuickBooks estimate -> form ----
# Statuses QuickBooks gives an estimate that has been turned into an invoice
BILLED_STATUSES = %w[Converted Closed].freeze
# True once the estimate is billed: converted or closed, or linked to an invoice. Billed estimates (including
# redmine_qbo_lineitems' once they're invoiced) can't be changed here.
def billed?(remote)
BILLED_STATUSES.include?(remote.txn_status.to_s) ||
Array(remote.linked_transactions).any? { |t| t.txn_type.to_s == 'Invoice' }
end
def form_from_remote(remote)
EstimateForm.new(
id: remote.id.to_s,
@@ -175,8 +186,10 @@ module RedmineQboBilling
invoiced_on: Array(remote.linked_transactions).select { |t| t.txn_type.to_s == 'Invoice' }.map { |t|
[t.txn_id.to_s, InvoiceWriter.invoice_number(t.txn_id)]
}.uniq,
# Read-only when it has bundles, or once an issue is linked to it (the work is under way)
locked: (:bundles if group_lines?(remote)) || (:linked if linked_issues(remote.id).any?)
# Read-only once it's billed (converted, closed or on an invoice), when it has bundles, or once an issue
# is linked to it (the work is under way)
locked: (:billed if billed?(remote)) || (:bundles if group_lines?(remote)) ||
(:linked if linked_issues(remote.id).any?)
)
end