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
@@ -112,7 +112,8 @@ module RedmineQboBilling
|
||||
# (discount: the discount amount QuickBooks worked out when it was last saved)
|
||||
:billing_address, :total, :total_tax, :discount, :email_status, :txn_status, :duplicated_from,
|
||||
:balance, :converted_from,
|
||||
# Invoices: a paid invoice opened for editing anyway (Unlock), and the amount paid on it
|
||||
# Invoices: a paid invoice opened for editing anyway (Unlock), and the amount paid on it.
|
||||
# Estimates: an estimate linked to an issue opened for editing anyway (Unlock).
|
||||
:unlocked, :amount_paid,
|
||||
# Estimates: the invoices it's billed on ([[id, number], ...])
|
||||
:invoiced_on,
|
||||
|
||||
@@ -105,6 +105,13 @@ module RedmineQboBilling
|
||||
Issue.where(estimate_id: estimate_id.to_s)
|
||||
end
|
||||
|
||||
# An estimate linked to an issue is only changed when unlocked by a user allowed to
|
||||
def check_linked(form, unlock, user)
|
||||
return unless linked_issues(form.id).exists?
|
||||
raise Error, I18n.t(:error_estimate_linked_to_issues) unless unlock
|
||||
raise Error, I18n.t(:error_estimate_linked_not_allowed) unless RedmineQboBilling.linked_estimate_editor?(user)
|
||||
end
|
||||
|
||||
# Loads the estimate from QuickBooks for editing
|
||||
def load(id)
|
||||
remote = QboEstimateService.with_service { |service| service.fetch_by_id(id) }
|
||||
@@ -114,7 +121,9 @@ module RedmineQboBilling
|
||||
|
||||
# Creates or updates the estimate in QuickBooks and returns the saved QuickBooks estimate.
|
||||
# The sales person is the user who creates the estimate; editing keeps the original one.
|
||||
def save(form, user: User.current)
|
||||
# unlock: an estimate linked to an issue may be changed (the user unlocked it, see
|
||||
# RedmineQboBilling.linked_estimate_editor?)
|
||||
def save(form, user: User.current, unlock: false)
|
||||
customer = Customer.find_by(id: form.customer_id)
|
||||
raise Error, I18n.t(:error_estimate_needs_customer) unless customer
|
||||
|
||||
@@ -125,7 +134,7 @@ module RedmineQboBilling
|
||||
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?
|
||||
check_linked(form, unlock, user)
|
||||
|
||||
estimate = Quickbooks::Model::Estimate.new
|
||||
estimate.id = remote.id
|
||||
|
||||
Reference in new issue
Block a user