mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-20 18:40:37 -05:00
Allow unlocking estimates linked to issues
An estimate attached to an issue was read-only, so changing it after a customer asked for tweaks meant taking it off the work order first. A new global permission, "Edit estimates linked to issues" (on top of Write estimates), shows an "Unlock to edit" button on a linked estimate. After a confirmation the estimate opens for editing, and the issues stay linked when it's saved. EstimateWriter.save still refuses a linked estimate unless it was unlocked by a user with the permission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
22af08cee7
commit
48f92f241f
9 files changed
+118
-4
No files matched your search
@@ -59,9 +59,11 @@ class QboEstimatesController < ApplicationController
|
||||
show_error(e, :new)
|
||||
end
|
||||
|
||||
# ?unlock=1 opens an estimate linked to an issue for editing anyway (after the editor's confirmation)
|
||||
def edit
|
||||
@form = RedmineQboBilling::EstimateWriter.load(params[:id])
|
||||
@linked_issues = RedmineQboBilling::EstimateWriter.linked_issues(@form.id).visible.to_a
|
||||
unlock_form if unlock?
|
||||
rescue *QBO_ERRORS => e
|
||||
flash[:error] = qbo_message(e)
|
||||
redirect_back_or_default home_path
|
||||
@@ -70,9 +72,10 @@ class QboEstimatesController < ApplicationController
|
||||
def update
|
||||
@form = RedmineQboBilling::EstimateForm.from_params(estimate_params, id: params[:id])
|
||||
@form.sales_person = params.dig(:estimate, :sales_person).to_s
|
||||
unlock_form if unlock?
|
||||
return show_invalid(:edit) unless @form.valid?
|
||||
|
||||
saved = RedmineQboBilling::EstimateWriter.save(@form, user: User.current)
|
||||
saved = RedmineQboBilling::EstimateWriter.save(@form, user: User.current, unlock: unlock?)
|
||||
finish_save(saved, l(:notice_estimate_saved_in_quickbooks, number: saved.doc_number))
|
||||
rescue RedmineQboBilling::EstimateWriter::Conflict => e
|
||||
@conflict = true
|
||||
@@ -296,6 +299,21 @@ class QboEstimatesController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
def unlock?
|
||||
params[:unlock].to_s == '1'
|
||||
end
|
||||
|
||||
# Shows an estimate linked to an issue editable, for users allowed to. EstimateWriter.save checks again.
|
||||
def unlock_form
|
||||
return unless RedmineQboBilling.linked_estimate_editor?
|
||||
|
||||
@linked_issues ||= RedmineQboBilling::EstimateWriter.linked_issues(@form.id).visible.to_a
|
||||
return unless @form.locked == :linked || (@form.locked.nil? && @linked_issues.any?)
|
||||
|
||||
@form.locked = nil
|
||||
@form.unlocked = true
|
||||
end
|
||||
|
||||
def save_and_send?
|
||||
params[:save_and_send].present?
|
||||
end
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
<%= hidden_field_tag 'estimate[txn_status]', form.txn_status, id: nil %>
|
||||
<%# Shown again if the page is redisplayed; the saved value is worked out when saving %>
|
||||
<%= hidden_field_tag 'estimate[sales_person]', form.sales_person, id: nil if form.persisted? || form.invoice? %>
|
||||
<%# An estimate linked to an issue opened for editing (Unlock) stays unlocked if the page is shown again %>
|
||||
<%= hidden_field_tag 'unlock', '1', id: nil if !invoice && form.unlocked %>
|
||||
<% if invoice %>
|
||||
<%= hidden_field_tag 'estimate[balance]', form.balance, id: nil %>
|
||||
<%# A paid invoice opened for editing (Unlock) stays unlocked if the page is shown again %>
|
||||
|
||||
@@ -67,6 +67,21 @@
|
||||
<li><%= link_to_issue(issue, truncate: 60) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%# Opened for editing anyway after a confirmation (e.g. the customer asks for changes after the diagnosis) %>
|
||||
<% if RedmineQboBilling.linked_estimate_editor? %>
|
||||
<%= link_to sprite_icon('unlock', l(:button_unlock_estimate)), edit_qbo_estimate_path(form.id, unlock: 1),
|
||||
class: 'icon icon-unlock', id: 'qbo-unlock-estimate',
|
||||
data: { confirm: l(:text_unlock_estimate_confirmation) } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% elsif form.unlocked && !invoice %>
|
||||
<div class="warning qbo-estimate-notice">
|
||||
<%= l(:text_estimate_unlocked) %>
|
||||
<ul>
|
||||
<% Array(@linked_issues).each do |issue| %>
|
||||
<li><%= link_to_issue(issue, truncate: 60) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% elsif form.locked == :paid %>
|
||||
<p class="warning">
|
||||
|
||||
Reference in new issue
Block a user