diff --git a/README.md b/README.md index d3ba051..b313108 100644 --- a/README.md +++ b/README.md @@ -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. * **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 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. * **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. diff --git a/app/models/estimate.rb b/app/models/estimate.rb index 298f854..a1e07dc 100644 --- a/app/models/estimate.rb +++ b/app/models/estimate.rb @@ -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] diff --git a/app/services/estimate_sync_service.rb b/app/services/estimate_sync_service.rb index defad49..6649a22 100644 --- a/app/services/estimate_sync_service.rb +++ b/app/services/estimate_sync_service.rb @@ -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 diff --git a/app/views/qbo_estimates/_estimate_actions.html.erb b/app/views/qbo_estimates/_estimate_actions.html.erb index 01d76ec..d56a4a7 100644 --- a/app/views/qbo_estimates/_estimate_actions.html.erb +++ b/app/views/qbo_estimates/_estimate_actions.html.erb @@ -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 %> diff --git a/app/views/qbo_estimates/_header.html.erb b/app/views/qbo_estimates/_header.html.erb index 01554d2..78ce036 100644 --- a/app/views/qbo_estimates/_header.html.erb +++ b/app/views/qbo_estimates/_header.html.erb @@ -35,16 +35,6 @@

<% end %> -<% if !invoice && Array(form.invoiced_on).any? %> -
- <%= l(:text_estimate_billed_on) %> - -
-<% end %> <% if form.duplicated_from.present? %>
<%= l(:text_estimate_duplicated_from, number: form.duplicated_from) %>
@@ -53,7 +43,18 @@
<%= l(:text_invoice_from_estimate, number: form.converted_from) %>
<% end %> -<% if form.locked == :linked %> +<% if form.locked == :billed %> +
+ <%= l(:error_estimate_billed) %> + <% if Array(form.invoiced_on).any? %> + + <% end %> +
+<% elsif form.locked == :linked %>
<%= l(:error_estimate_linked_to_issues) %>