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

+6
View File
@@ -20,6 +20,12 @@ class Estimate < QboBaseModel
to_s
end
# True once QuickBooks has turned it into an invoice (status cached by the sync). The estimate page also
# checks for a linked invoice; either way a billed estimate can't be changed in Redmine.
def billed?
RedmineQboBilling::EstimateWriter::BILLED_STATUSES.include?(self[:txn_status].to_s)
end
# returns a human readable string
def to_s
return self[:doc_number]
+1
View File
@@ -27,6 +27,7 @@ class EstimateSyncService < SyncServiceBase
map_attributes :doc_number, :txn_date
map_attribute :total_amount, :total
map_attribute :txn_status
# Man-hours: quantities of the labor products/services (plugin settings)
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
map_belongs_to :customer
@@ -1,5 +1,5 @@
<%# Estimates linked to an issue are read-only here, so they get a View link instead of Edit %>
<% if estimate.issues.exists? %>
<%# Billed estimates and estimates linked to an issue are read-only here, so they get a View link instead of Edit %>
<% if estimate.billed? || estimate.issues.exists? %>
<%= link_to sprite_icon('zoom-in', l(:button_view_estimate)), edit_qbo_estimate_path(estimate.id),
class: 'icon-only icon-zoom-in qbo-estimate-edit-link', title: l(:button_view_estimate) %>
<% else %>
+12 -13
View File
@@ -35,16 +35,6 @@
</p>
<% end %>
<% if !invoice && Array(form.invoiced_on).any? %>
<div class="warning qbo-estimate-notice">
<%= l(:text_estimate_billed_on) %>
<ul>
<% form.invoiced_on.each do |invoice_id, number| %>
<li><%= link_to "#{l(:label_invoice)} ##{number}", RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(invoice_id) : invoice_path(invoice_id) %></li>
<% end %>
</ul>
</div>
<% end %>
<% if form.duplicated_from.present? %>
<div class="flash notice"><%= l(:text_estimate_duplicated_from, number: form.duplicated_from) %></div>
@@ -53,7 +43,18 @@
<div class="flash notice"><%= l(:text_invoice_from_estimate, number: form.converted_from) %></div>
<% end %>
<% if form.locked == :linked %>
<% if form.locked == :billed %>
<div class="warning qbo-estimate-notice">
<%= l(:error_estimate_billed) %>
<% if Array(form.invoiced_on).any? %>
<ul>
<% form.invoiced_on.each do |invoice_id, number| %>
<li><%= link_to "#{l(:label_invoice)} ##{number}", RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(invoice_id) : invoice_path(invoice_id) %></li>
<% end %>
</ul>
<% end %>
</div>
<% elsif form.locked == :linked %>
<div class="warning qbo-estimate-notice">
<%= l(:error_estimate_linked_to_issues) %>
<ul>
@@ -66,8 +67,6 @@
<p class="warning"><%= l(:error_invoice_paid) %></p>
<% elsif form.locked == :bundles %>
<p class="warning"><%= l(invoice ? :error_invoice_has_bundles : :error_estimate_has_bundles) %></p>
<% elsif !invoice && %w[Converted Closed].include?(form.txn_status.to_s) && Array(form.invoiced_on).empty? %>
<p class="warning"><%= l(:text_estimate_closed) %></p>
<% end %>
<% if RedmineQboBilling::Company.settings.empty? %>
+1 -1
View File
@@ -4,7 +4,7 @@
<%# Plugins add estimate actions here (e.g. redmine_qbo_calendar's Add appointment) %>
<%= call_hook :view_qbo_estimate_contextual, { estimate_id: @form.id, customer_id: @form.customer_id, vin: @form.vin, doc_number: @form.doc_number } %>
<%# An estimate is billed once: no Create invoice once it's on an invoice, closed or rejected %>
<% if RedmineQboBilling.invoice_writer? && Array(@form.invoiced_on).empty? && !%w[Converted Closed Rejected].include?(@form.txn_status.to_s) %>
<% if RedmineQboBilling.invoice_writer? && @form.locked != :billed && @form.txn_status.to_s != 'Rejected' %>
<%= link_to sprite_icon('document', l(:button_create_invoice)), new_qbo_invoice_path(estimate_id: @form.id), class: 'icon icon-document' %>
<% end %>
<% if User.current.allowed_to?(:create_estimate_issues, nil, global: true) %>