mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
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:
10 files changed
+45
-23
No files matched your search
@@ -105,6 +105,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
||||||
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, VIN and messages, dated today, with the current user as sales person.
|
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, VIN 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 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. 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.
|
* **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.
|
* 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.
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ class Estimate < QboBaseModel
|
|||||||
to_s
|
to_s
|
||||||
end
|
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
|
# returns a human readable string
|
||||||
def to_s
|
def to_s
|
||||||
return self[:doc_number]
|
return self[:doc_number]
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class EstimateSyncService < SyncServiceBase
|
|||||||
|
|
||||||
map_attributes :doc_number, :txn_date
|
map_attributes :doc_number, :txn_date
|
||||||
map_attribute :total_amount, :total
|
map_attribute :total_amount, :total
|
||||||
|
map_attribute :txn_status
|
||||||
# Man-hours: quantities of the labor products/services (plugin settings)
|
# Man-hours: quantities of the labor products/services (plugin settings)
|
||||||
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
map_attribute(:hours) { |remote| RedmineQboBilling::ManHours.hours(remote) }
|
||||||
map_belongs_to :customer
|
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 %>
|
<%# Billed estimates and estimates linked to an issue are read-only here, so they get a View link instead of Edit %>
|
||||||
<% if estimate.issues.exists? %>
|
<% if estimate.billed? || estimate.issues.exists? %>
|
||||||
<%= link_to sprite_icon('zoom-in', l(:button_view_estimate)), edit_qbo_estimate_path(estimate.id),
|
<%= 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) %>
|
class: 'icon-only icon-zoom-in qbo-estimate-edit-link', title: l(:button_view_estimate) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -35,16 +35,6 @@
|
|||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% 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? %>
|
<% if form.duplicated_from.present? %>
|
||||||
<div class="flash notice"><%= l(:text_estimate_duplicated_from, number: form.duplicated_from) %></div>
|
<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>
|
<div class="flash notice"><%= l(:text_invoice_from_estimate, number: form.converted_from) %></div>
|
||||||
<% end %>
|
<% 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">
|
<div class="warning qbo-estimate-notice">
|
||||||
<%= l(:error_estimate_linked_to_issues) %>
|
<%= l(:error_estimate_linked_to_issues) %>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -66,8 +67,6 @@
|
|||||||
<p class="warning"><%= l(:error_invoice_paid) %></p>
|
<p class="warning"><%= l(:error_invoice_paid) %></p>
|
||||||
<% elsif form.locked == :bundles %>
|
<% elsif form.locked == :bundles %>
|
||||||
<p class="warning"><%= l(invoice ? :error_invoice_has_bundles : :error_estimate_has_bundles) %></p>
|
<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 %>
|
<% end %>
|
||||||
|
|
||||||
<% if RedmineQboBilling::Company.settings.empty? %>
|
<% if RedmineQboBilling::Company.settings.empty? %>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<%# Plugins add estimate actions here (e.g. redmine_qbo_calendar's Add appointment) %>
|
<%# 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 } %>
|
<%= 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 %>
|
<%# 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' %>
|
<%= link_to sprite_icon('document', l(:button_create_invoice)), new_qbo_invoice_path(estimate_id: @form.id), class: 'icon icon-document' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if User.current.allowed_to?(:create_estimate_issues, nil, global: true) %>
|
<% if User.current.allowed_to?(:create_estimate_issues, nil, global: true) %>
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ en:
|
|||||||
error_estimate_changed_in_quickbooks: "This estimate was changed in QuickBooks after you opened it, so it wasn't saved."
|
error_estimate_changed_in_quickbooks: "This estimate was changed in QuickBooks after you opened it, so it wasn't saved."
|
||||||
error_estimate_field_invalid: "%{field} is not valid"
|
error_estimate_field_invalid: "%{field} is not valid"
|
||||||
error_estimate_linked_to_issues: "This estimate is linked to these issues, so it can't be changed here. Duplicate it to make a new estimate:"
|
error_estimate_linked_to_issues: "This estimate is linked to these issues, so it can't be changed here. Duplicate it to make a new estimate:"
|
||||||
|
error_estimate_billed: "This estimate has been billed (turned into an invoice), so it can't be changed here. Duplicate it to make a new estimate."
|
||||||
error_estimate_has_bundles: "This estimate has bundles, which can only be edited in QuickBooks."
|
error_estimate_has_bundles: "This estimate has bundles, which can only be edited in QuickBooks."
|
||||||
error_estimate_line_description: "Line %{line} needs a description, a product or service, or a rate"
|
error_estimate_line_description: "Line %{line} needs a description, a product or service, or a rate"
|
||||||
error_estimate_line_number: "Line %{line} has a quantity or rate that isn't a number"
|
error_estimate_line_number: "Line %{line} has a quantity or rate that isn't a number"
|
||||||
@@ -177,7 +178,6 @@ en:
|
|||||||
text_clear_all_lines_confirmation: "Clear all lines?"
|
text_clear_all_lines_confirmation: "Clear all lines?"
|
||||||
text_email_estimate_confirmation: "Email estimate #%{number} to %{email}?"
|
text_email_estimate_confirmation: "Email estimate #%{number} to %{email}?"
|
||||||
text_estimate_duplicated_from: "Copied from estimate #%{number}. It's saved as a new estimate."
|
text_estimate_duplicated_from: "Copied from estimate #%{number}. It's saved as a new estimate."
|
||||||
text_estimate_closed: "This estimate is closed (it was turned into an invoice). Changes here won't change the invoice."
|
|
||||||
text_estimate_expiration_days: "New estimates get an expiration date this many days after the estimate date, e.g. 30. Leave blank for no expiration date."
|
text_estimate_expiration_days: "New estimates get an expiration date this many days after the estimate date, e.g. 30. Leave blank for no expiration date."
|
||||||
text_estimate_reload: "Reloading shows the latest version from QuickBooks; changes made on this page will be lost."
|
text_estimate_reload: "Reloading shows the latest version from QuickBooks; changes made on this page will be lost."
|
||||||
text_estimate_send_needs_email: "Enter the customer's email to send it."
|
text_estimate_send_needs_email: "Enter the customer's email to send it."
|
||||||
@@ -231,7 +231,6 @@ en:
|
|||||||
error_estimate_already_invoiced: "Estimate #%{number} is already billed on invoice #%{invoice}."
|
error_estimate_already_invoiced: "Estimate #%{number} is already billed on invoice #%{invoice}."
|
||||||
error_estimate_closed_billed: "Estimate #%{number} is already billed (%{status})."
|
error_estimate_closed_billed: "Estimate #%{number} is already billed (%{status})."
|
||||||
error_estimate_rejected: "Estimate #%{number} was rejected, so it can't be billed."
|
error_estimate_rejected: "Estimate #%{number} was rejected, so it can't be billed."
|
||||||
text_estimate_billed_on: "This estimate is billed on:"
|
|
||||||
error_invoice_changed_in_quickbooks: "This invoice was changed in QuickBooks after you opened it, so it wasn't saved."
|
error_invoice_changed_in_quickbooks: "This invoice was changed in QuickBooks after you opened it, so it wasn't saved."
|
||||||
error_invoice_has_bundles: "This invoice has bundles, which can only be edited in QuickBooks."
|
error_invoice_has_bundles: "This invoice has bundles, which can only be edited in QuickBooks."
|
||||||
error_invoice_not_saved: "QuickBooks didn't save the invoice"
|
error_invoice_not_saved: "QuickBooks didn't save the invoice"
|
||||||
|
|||||||
@@ -9,12 +9,14 @@
|
|||||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
# Cached report figures: each estimate's total, and the man-hours on estimates and invoices (quantities of the
|
# Cached from QuickBooks by the sync and the webhook: each estimate's total and status (Converted or Closed
|
||||||
# products/services set as "Replaced by imported time"). Filled in by the sync and the webhook.
|
# estimates are billed, so they're shown as View instead of Edit), and the man-hours on estimates and invoices
|
||||||
|
# (quantities of the labor products/services) for the business report.
|
||||||
class AddEstimateTotalsAndHours < ActiveRecord::Migration[7.0]
|
class AddEstimateTotalsAndHours < ActiveRecord::Migration[7.0]
|
||||||
def up
|
def up
|
||||||
add_column :estimates, :total_amount, :decimal, precision: 15, scale: 2 unless column_exists?(:estimates, :total_amount)
|
add_column :estimates, :total_amount, :decimal, precision: 15, scale: 2 unless column_exists?(:estimates, :total_amount)
|
||||||
add_column :estimates, :hours, :float unless column_exists?(:estimates, :hours)
|
add_column :estimates, :hours, :float unless column_exists?(:estimates, :hours)
|
||||||
|
add_column :estimates, :txn_status, :string unless column_exists?(:estimates, :txn_status)
|
||||||
add_column :invoices, :hours, :float unless column_exists?(:invoices, :hours)
|
add_column :invoices, :hours, :float unless column_exists?(:invoices, :hours)
|
||||||
add_index :estimates, :txn_date unless index_exists?(:estimates, :txn_date)
|
add_index :estimates, :txn_date unless index_exists?(:estimates, :txn_date)
|
||||||
add_index :invoices, :txn_date unless index_exists?(:invoices, :txn_date)
|
add_index :invoices, :txn_date unless index_exists?(:invoices, :txn_date)
|
||||||
@@ -24,6 +26,7 @@ class AddEstimateTotalsAndHours < ActiveRecord::Migration[7.0]
|
|||||||
remove_index :invoices, :txn_date if index_exists?(:invoices, :txn_date)
|
remove_index :invoices, :txn_date if index_exists?(:invoices, :txn_date)
|
||||||
remove_index :estimates, :txn_date if index_exists?(:estimates, :txn_date)
|
remove_index :estimates, :txn_date if index_exists?(:estimates, :txn_date)
|
||||||
remove_column :invoices, :hours if column_exists?(:invoices, :hours)
|
remove_column :invoices, :hours if column_exists?(:invoices, :hours)
|
||||||
|
remove_column :estimates, :txn_status if column_exists?(:estimates, :txn_status)
|
||||||
remove_column :estimates, :hours if column_exists?(:estimates, :hours)
|
remove_column :estimates, :hours if column_exists?(:estimates, :hours)
|
||||||
remove_column :estimates, :total_amount if column_exists?(:estimates, :total_amount)
|
remove_column :estimates, :total_amount if column_exists?(:estimates, :total_amount)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ module RedmineQboBilling
|
|||||||
remote = service.fetch_by_id(form.id)
|
remote = service.fetch_by_id(form.id)
|
||||||
raise Error, I18n.t(:notice_estimate_not_found) unless remote
|
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 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_has_bundles) if group_lines?(remote)
|
||||||
raise Error, I18n.t(:error_estimate_linked_to_issues) if linked_issues(form.id).any?
|
raise Error, I18n.t(:error_estimate_linked_to_issues) if linked_issues(form.id).any?
|
||||||
|
|
||||||
@@ -150,6 +151,16 @@ module RedmineQboBilling
|
|||||||
|
|
||||||
# ---- QuickBooks estimate -> form ----
|
# ---- 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)
|
def form_from_remote(remote)
|
||||||
EstimateForm.new(
|
EstimateForm.new(
|
||||||
id: remote.id.to_s,
|
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|
|
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)]
|
[t.txn_id.to_s, InvoiceWriter.invoice_number(t.txn_id)]
|
||||||
}.uniq,
|
}.uniq,
|
||||||
# Read-only when it has bundles, or once an issue is linked to it (the work is under way)
|
# Read-only once it's billed (converted, closed or on an invoice), when it has bundles, or once an issue
|
||||||
locked: (:bundles if group_lines?(remote)) || (:linked if linked_issues(remote.id).any?)
|
# 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
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module RedmineQboBilling
|
|||||||
# Estimates in these states can still be imported (Converted/Closed ones are already invoiced, Rejected ones lost)
|
# Estimates in these states can still be imported (Converted/Closed ones are already invoiced, Rejected ones lost)
|
||||||
OPEN_ESTIMATE_STATUSES = ['', 'Pending', 'Accepted'].freeze
|
OPEN_ESTIMATE_STATUSES = ['', 'Pending', 'Accepted'].freeze
|
||||||
# How QuickBooks marks an invoiced estimate: Converted when it made the invoice, Closed when closed by hand
|
# How QuickBooks marks an invoiced estimate: Converted when it made the invoice, Closed when closed by hand
|
||||||
BILLED_ESTIMATE_STATUSES = %w[Converted Closed].freeze
|
BILLED_ESTIMATE_STATUSES = EstimateWriter::BILLED_STATUSES
|
||||||
# How far back to look for billable time if QuickBooks won't filter time activities by customer
|
# How far back to look for billable time if QuickBooks won't filter time activities by customer
|
||||||
TIME_LOOKBACK = 400
|
TIME_LOOKBACK = 400
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user