Save new estimates and invoices as drafts

A draft is kept in Redmine only, however incomplete, so nothing is in QuickBooks
until it's saved from the editor. QuickBooks can't apply a deposit to an invoice
that's still being written, which made it read-only. Saving to QuickBooks deletes
the draft.

Drafts are listed on the customer's page, on a Drafts page linked from Customers,
and on a new invoice or estimate for a customer who already has one. Anyone with
Write invoices (or Write estimates) can continue or delete invoice (or estimate)
drafts. Adds the qbo_drafts table (migration 052).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 10:33:03 -05:00
1 parent a1fb88e77c
commit c8e2d2d92e
17 files changed
+365 -7

No files matched your search

@@ -0,0 +1,75 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
# Drafts on the new estimate and new invoice editors (see QboDraft). "Save draft" keeps what's filled in, even
# if it isn't complete, and reopens it (new?draft_id=). Saving to QuickBooks deletes the draft.
module QboDraftHandling
extend ActiveSupport::Concern
private
# The draft named by draft_id (in the URL, or the editor's hidden field), if the user may open it
def find_draft(document)
@draft = (QboDraft.visible.for_document(document).find_by(id: params[:draft_id]) if params[:draft_id].present?)
end
# The editor form filled in from a draft, with the details the editor shows but doesn't post
def form_from_draft(draft)
form = draft.form
customer = Customer.find_by(id: form.customer_id) if form.customer_id.present?
if customer
form.billing_address = RedmineQboBilling::EstimateWriter.customer_address(customer)
form.customer_name = customer.name if form.customer_name.blank?
end
# Invoices keep the sales person shown on the editor (e.g. from an estimate); estimates are always the user's
form.sales_person = (draft.invoice? && draft.fields['sales_person'].presence) || User.current.name
form.lines = form.lines.reject(&:blank?)
form.lines += Array.new([2 - form.lines.size, 1].max) { RedmineQboBilling::EstimateForm::Line.new(quantity: '', taxable: true) }
form
end
# Saves what's on the editor as a draft (no checks: a draft can be missing anything) and reopens it
def save_draft(document, fields)
draft = @draft || QboDraft.new(document: document)
fields = fields.to_h.stringify_keys
draft.fields = fields
draft.customer_id = (Customer.where(id: fields['customer_id']).pick(:id) if fields['customer_id'].present?)
draft.user = User.current
draft.save!
flash[:notice] = l(:notice_qbo_draft_saved)
redirect_to draft_editor_path(draft)
end
# Saved to QuickBooks: the draft isn't needed any more
def discard_draft
@draft&.destroy
@draft = nil
end
# A new document for a customer who already has drafts of it: the editor points them out
def load_customer_drafts(document, customer_id)
@customer_drafts =
if @draft.nil? && customer_id.present?
QboDraft.visible.for_document(document).where(customer_id: customer_id).newest_first.to_a
else
[]
end
end
# A draft_id that's gone (e.g. finished or deleted by someone else): say so and list the drafts
def draft_missing
flash[:error] = l(:error_qbo_draft_not_found)
redirect_to qbo_drafts_path
end
def draft_editor_path(draft)
draft.invoice? ? new_qbo_invoice_path(draft_id: draft.id) : new_qbo_estimate_path(draft_id: draft.id)
end
end
+31
View File
@@ -0,0 +1,31 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
# Estimate and invoice drafts (QboDraft): all of them, and deleting one. Drafts are continued on the new
# estimate/invoice editor (new?draft_id=). Users see the drafts of the documents they may write.
class QboDraftsController < ApplicationController
before_action :authorize_global
def index
@drafts = QboDraft.visible.includes(:customer, :user).newest_first.to_a
end
def destroy
draft = QboDraft.visible.find_by(id: params[:id])
if draft
draft.destroy
flash[:notice] = l(:notice_qbo_draft_deleted)
else
flash[:error] = l(:error_qbo_draft_not_found)
end
redirect_back_or_default qbo_drafts_path
end
end
+11 -2
View File
@@ -10,6 +10,7 @@
# Writes, edits and emails QuickBooks estimates from Redmine, on a page laid out like QuickBooks' estimate screen. # Writes, edits and emails QuickBooks estimates from Redmine, on a page laid out like QuickBooks' estimate screen.
class QboEstimatesController < ApplicationController class QboEstimatesController < ApplicationController
include QboDraftHandling
before_action :require_admin, only: :refresh_company before_action :require_admin, only: :refresh_company
before_action :authorize_global, except: :refresh_company before_action :authorize_global, except: :refresh_company
@@ -25,26 +26,34 @@ class QboEstimatesController < ApplicationController
# redmine_qbo raises plain errors when QuickBooks isn't connected or the token can't be refreshed # redmine_qbo raises plain errors when QuickBooks isn't connected or the token can't be refreshed
RuntimeError].freeze RuntimeError].freeze
# A blank estimate, or a copy of another one (?duplicate=<estimate id>) # A blank estimate, a copy of another one (?duplicate=<estimate id>), or a draft (?draft_id=, see QboDraft)
def new def new
if params[:duplicate].present? if params[:draft_id].present?
return draft_missing unless find_draft('estimate')
@form = form_from_draft(@draft)
elsif params[:duplicate].present?
@form = RedmineQboBilling::EstimateWriter.duplicate_form(params[:duplicate], user: User.current) @form = RedmineQboBilling::EstimateWriter.duplicate_form(params[:duplicate], user: User.current)
else else
customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present? customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present?
@form = RedmineQboBilling::EstimateWriter.new_form(customer: customer, user: User.current) @form = RedmineQboBilling::EstimateWriter.new_form(customer: customer, user: User.current)
end end
load_customer_drafts('estimate', @form.customer_id)
rescue *QBO_ERRORS => e rescue *QBO_ERRORS => e
flash[:error] = qbo_message(e) flash[:error] = qbo_message(e)
redirect_back_or_default home_path redirect_back_or_default home_path
end end
def create def create
find_draft('estimate')
return save_draft('estimate', estimate_params) if params[:save_draft].present?
@form = RedmineQboBilling::EstimateForm.from_params(estimate_params) @form = RedmineQboBilling::EstimateForm.from_params(estimate_params)
# Shown again if the save fails; the sales person is always the user creating the estimate # Shown again if the save fails; the sales person is always the user creating the estimate
@form.sales_person = User.current.name @form.sales_person = User.current.name
return show_invalid(:new) unless @form.valid? return show_invalid(:new) unless @form.valid?
saved = RedmineQboBilling::EstimateWriter.save(@form, user: User.current) saved = RedmineQboBilling::EstimateWriter.save(@form, user: User.current)
discard_draft
finish_save(saved, l(:notice_estimate_saved_in_quickbooks, number: saved.doc_number)) finish_save(saved, l(:notice_estimate_saved_in_quickbooks, number: saved.doc_number))
rescue *QBO_ERRORS => e rescue *QBO_ERRORS => e
show_error(e, :new) show_error(e, :new)
+15 -1
View File
@@ -11,6 +11,7 @@
# Writes, edits and emails QuickBooks invoices from Redmine, with the same editor as estimates, plus importing # Writes, edits and emails QuickBooks invoices from Redmine, with the same editor as estimates, plus importing
# billable time and open estimates. The customer and product searches are QboEstimatesController's. # billable time and open estimates. The customer and product searches are QboEstimatesController's.
class QboInvoicesController < ApplicationController class QboInvoicesController < ApplicationController
include QboDraftHandling
before_action :authorize_global before_action :authorize_global
before_action :require_sender_for_save_and_send, only: [:create, :update] before_action :require_sender_for_save_and_send, only: [:create, :update]
@@ -18,8 +19,15 @@ class QboInvoicesController < ApplicationController
QBO_ERRORS = QboEstimatesController::QBO_ERRORS QBO_ERRORS = QboEstimatesController::QBO_ERRORS
# A blank invoice, or one made from an estimate (?estimate_id=<estimate id>) # A blank invoice, one made from an estimate (?estimate_id=<estimate id>), or a draft (?draft_id=, see
# QboDraft). A draft stays in Redmine, so QuickBooks can't apply a deposit to it while it's being written.
def new def new
if params[:draft_id].present?
return draft_missing unless find_draft('invoice')
@form = form_from_draft(@draft)
return
end
@form = @form =
if params[:estimate_id].present? if params[:estimate_id].present?
RedmineQboBilling::InvoiceWriter.from_estimate(params[:estimate_id], user: User.current) RedmineQboBilling::InvoiceWriter.from_estimate(params[:estimate_id], user: User.current)
@@ -27,18 +35,24 @@ class QboInvoicesController < ApplicationController
customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present? customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present?
RedmineQboBilling::InvoiceWriter.new_form(customer: customer, user: User.current) RedmineQboBilling::InvoiceWriter.new_form(customer: customer, user: User.current)
end end
load_customer_drafts('invoice', @form.customer_id)
rescue *QBO_ERRORS => e rescue *QBO_ERRORS => e
flash[:error] = qbo_message(e) flash[:error] = qbo_message(e)
redirect_back_or_default home_path redirect_back_or_default home_path
end end
def create def create
find_draft('invoice')
# The sales person shown on the editor is kept with the draft
return save_draft('invoice', invoice_params.to_h.merge('sales_person' => params.dig(:estimate, :sales_person).to_s)) if params[:save_draft].present?
@form = RedmineQboBilling::EstimateForm.from_params(invoice_params, document: 'invoice') @form = RedmineQboBilling::EstimateForm.from_params(invoice_params, document: 'invoice')
# Display only (e.g. the estimate's sales person); InvoiceWriter.save works out what's saved # Display only (e.g. the estimate's sales person); InvoiceWriter.save works out what's saved
@form.sales_person = params.dig(:estimate, :sales_person).presence || User.current.name @form.sales_person = params.dig(:estimate, :sales_person).presence || User.current.name
return show_invalid(:new) unless @form.valid? return show_invalid(:new) unless @form.valid?
saved = RedmineQboBilling::InvoiceWriter.save(@form, user: User.current) saved = RedmineQboBilling::InvoiceWriter.save(@form, user: User.current)
discard_draft
finish_save(saved, l(:notice_invoice_saved_in_quickbooks, number: saved.doc_number)) finish_save(saved, l(:notice_invoice_saved_in_quickbooks, number: saved.doc_number))
rescue *QBO_ERRORS => e rescue *QBO_ERRORS => e
show_error(e, :new) show_error(e, :new)
+74
View File
@@ -0,0 +1,74 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
# A new estimate or invoice saved part way, in Redmine only. Nothing is in QuickBooks until it's saved from
# the editor, so QuickBooks can't apply a deposit to an invoice that's still being written. Drafts are shared:
# anyone with Write estimates (or Write invoices) can continue or delete any estimate (or invoice) draft.
class QboDraft < ApplicationRecord
DOCUMENTS = %w[estimate invoice].freeze
belongs_to :customer, optional: true
# Who saved it last
belongs_to :user, optional: true
validates :document, inclusion: { in: DOCUMENTS }
scope :newest_first, -> { order(updated_at: :desc, id: :desc) }
scope :for_document, ->(document) { where(document: document.to_s) }
# The drafts a user may open: estimate drafts need Write estimates, invoice drafts Write invoices
scope :visible, lambda { |user = User.current|
documents = []
documents << 'estimate' if RedmineQboBilling.writer?(user)
documents << 'invoice' if RedmineQboBilling.invoice_writer?(user)
where(document: documents)
}
def self.writable_document?(document, user = User.current)
case document.to_s
when 'estimate' then RedmineQboBilling.writer?(user)
when 'invoice' then RedmineQboBilling.invoice_writer?(user)
else false
end
end
# The editor's fields as posted (estimate[...])
def fields
parsed = JSON.parse(data.presence || '{}')
parsed.is_a?(Hash) ? parsed : {}
rescue JSON::ParserError
{}
end
def fields=(hash)
self.data = hash.to_h.to_json
end
# The editor form, filled in as it was saved
def form
RedmineQboBilling::EstimateForm.from_params(fields, document: document)
end
def invoice?
document == 'invoice'
end
def customer_name
customer&.name.presence || fields['customer_name'].presence
end
def subtotal
form.subtotal
end
def line_count
form.filled_lines.count { |line| !line.subtotal? }
end
end
+5
View File
@@ -5,6 +5,11 @@
<% if User.current.allowed_to?(:add_customers, nil, global: true) %> <% if User.current.allowed_to?(:add_customers, nil, global: true) %>
<%= link_to sprite_icon('add', l(:label_new_customer)), new_customer_path, class: 'icon icon-add' %> <%= link_to sprite_icon('add', l(:label_new_customer)), new_customer_path, class: 'icon icon-add' %>
<% end %> <% end %>
<%# Estimate and invoice drafts, for users who may write either %>
<% if RedmineQboBilling.writer? || RedmineQboBilling.invoice_writer? %>
<% draft_count = QboDraft.visible.count %>
<%= link_to sprite_icon('document', "#{l(:label_qbo_drafts)} (#{draft_count})"), qbo_drafts_path, class: 'icon icon-document' %>
<% end %>
<% if User.current.admin? %> <% if User.current.admin? %>
<%= link_to sprite_icon('reload', l(:label_sync)), qbo_sync_path, class: 'icon icon-reload' %> <%= link_to sprite_icon('reload', l(:label_sync)), qbo_sync_path, class: 'icon icon-reload' %>
<% end %> <% end %>
+7
View File
@@ -58,6 +58,13 @@
</div> </div>
</div> </div>
<%# Estimate and invoice drafts, kept in Redmine until they're saved to QuickBooks %>
<% customer_drafts = QboDraft.visible.where(customer_id: @customer.id).includes(:user).newest_first.to_a %>
<% if customer_drafts.any? %>
<h4><%= l(:label_qbo_drafts) %>:</h4>
<%= render partial: 'qbo_drafts/list', locals: { drafts: customer_drafts, show_customer: false } %>
<% end %>
</div> </div>
<div class="splitcontentleft"> <div class="splitcontentleft">
@@ -0,0 +1,18 @@
<%# On the new estimate/invoice editor: the draft being continued, or the customer's other drafts of this
document so a second one isn't started by accident %>
<% draft = local_assigns[:draft] %>
<% drafts = local_assigns[:drafts] || [] %>
<% if draft %>
<div class="flash notice qbo-draft-notice">
<%= l(:text_qbo_editing_draft, user: h(draft.user&.name || l(:label_user_anonymous)), age: time_tag(draft.updated_at)).html_safe %>
</div>
<% elsif drafts.any? %>
<div class="warning qbo-estimate-notice qbo-draft-notice">
<%= l(drafts.first.invoice? ? :text_qbo_customer_has_invoice_drafts : :text_qbo_customer_has_estimate_drafts, count: drafts.size) %>
<% drafts.each do |other| %>
<%= link_to l(:text_qbo_draft_link, user: other.user&.name || l(:label_user_anonymous),
subtotal: number_to_currency(other.subtotal), date: format_time(other.updated_at)),
other.invoice? ? new_qbo_invoice_path(draft_id: other.id) : new_qbo_estimate_path(draft_id: other.id) %>
<% end %>
</div>
<% end %>
+40
View File
@@ -0,0 +1,40 @@
<%# Estimate and invoice drafts (QboDraft) with Continue and Delete. show_customer: false on a customer's page. %>
<% show_customer = local_assigns.fetch(:show_customer, true) %>
<table class="list qbo-drafts">
<thead>
<tr>
<th><%= l(:label_qbo_draft_document) %></th>
<% if show_customer %><th><%= l(:field_customer) %></th><% end %>
<th class="qbo-draft-number"><%= l(:label_qbo_draft_lines) %></th>
<th class="qbo-draft-number"><%= l(:label_subtotal) %></th>
<th><%= l(:label_qbo_draft_saved_by) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% drafts.each do |draft| %>
<tr>
<td><%= link_to l(draft.invoice? ? :label_qbo_invoice_draft : :label_qbo_estimate_draft),
draft.invoice? ? new_qbo_invoice_path(draft_id: draft.id) : new_qbo_estimate_path(draft_id: draft.id) %></td>
<% if show_customer %>
<td><%= draft.customer ? link_to(draft.customer.name, customer_path(draft.customer)) : (draft.customer_name || '–') %></td>
<% end %>
<td class="qbo-draft-number"><%= draft.line_count %></td>
<td class="qbo-draft-number"><%= number_to_currency(draft.subtotal) %></td>
<td><%= l(:text_qbo_draft_saved_by, user: h(draft.user&.name || l(:label_user_anonymous)), age: time_tag(draft.updated_at)).html_safe %></td>
<td class="buttons">
<%= link_to sprite_icon('edit', l(:button_qbo_continue_draft)),
draft.invoice? ? new_qbo_invoice_path(draft_id: draft.id) : new_qbo_estimate_path(draft_id: draft.id),
class: 'icon icon-edit' %>
<%= link_to sprite_icon('del', l(:button_delete)), qbo_draft_path(draft), method: :delete,
data: { confirm: l(:text_are_you_sure) }, class: 'icon icon-del' %>
</td>
</tr>
<% end %>
</tbody>
</table>
<style>
table.qbo-drafts td, table.qbo-drafts th { text-align: left; }
table.qbo-drafts .qbo-draft-number { text-align: right; white-space: nowrap; }
table.qbo-drafts td.buttons { white-space: nowrap; }
</style>
+11
View File
@@ -0,0 +1,11 @@
<% html_title l(:label_qbo_drafts) %>
<h2><%= link_to l(:label_customers), customers_path %> &#187; <%= l(:label_qbo_drafts) %></h2>
<p class="info"><%= l(:text_qbo_drafts_info) %></p>
<% if @drafts.any? %>
<%= render partial: 'qbo_drafts/list', locals: { drafts: @drafts } %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
+12
View File
@@ -10,6 +10,8 @@
settings_read = company.settings.present? settings_read = company.settings.present?
# The same editor writes estimates and invoices # The same editor writes estimates and invoices
invoice = form.invoice? invoice = form.invoice?
# The draft being continued (QboDraft), if any; new documents can be saved as drafts
draft = local_assigns[:draft]
sender = invoice ? RedmineQboBilling.invoice_sender? : RedmineQboBilling.sender? sender = invoice ? RedmineQboBilling.invoice_sender? : RedmineQboBilling.sender?
cancel_path = customer ? customer_path(customer) : home_path cancel_path = customer ? customer_path(customer) : home_path
form_url = form_url =
@@ -38,6 +40,7 @@
warn_unsaved: User.current.pref.warn_on_leaving_unsaved != '0' warn_unsaved: User.current.pref.warn_on_leaving_unsaved != '0'
}) do %> }) do %>
<%= hidden_field_tag 'estimate[sync_token]', form.sync_token, id: nil %> <%= hidden_field_tag 'estimate[sync_token]', form.sync_token, id: nil %>
<%= hidden_field_tag 'draft_id', draft.id, id: nil if draft %>
<%= hidden_field_tag 'estimate[total_tax]', form.total_tax, id: nil %> <%= hidden_field_tag 'estimate[total_tax]', form.total_tax, id: nil %>
<%= hidden_field_tag 'estimate[discount]', form.discount, id: nil %> <%= hidden_field_tag 'estimate[discount]', form.discount, id: nil %>
<%= hidden_field_tag 'estimate[email_status]', form.email_status, id: nil %> <%= hidden_field_tag 'estimate[email_status]', form.email_status, id: nil %>
@@ -283,6 +286,15 @@
<%= link_to l(:button_cancel), cancel_path, class: 'qbo-button qbo-button-dark', id: 'qbo-estimate-cancel' %> <%= link_to l(:button_cancel), cancel_path, class: 'qbo-button qbo-button-dark', id: 'qbo-estimate-cancel' %>
<% unless form.locked %> <% unless form.locked %>
<span class="qbo-estimate-actions-save"> <span class="qbo-estimate-actions-save">
<% unless form.persisted? %>
<%# Kept in Redmine only, however incomplete (QboDraftHandling) %>
<% if draft %>
<%= link_to l(:button_qbo_delete_draft), qbo_draft_path(draft), method: :delete,
data: { confirm: l(:text_are_you_sure) }, class: 'qbo-button qbo-button-dark', id: 'qbo-delete-draft' %>
<% end %>
<%= submit_tag l(:button_qbo_save_draft), name: 'save_draft', class: 'qbo-button qbo-button-dark',
id: 'qbo-save-draft', formnovalidate: true %>
<% end %>
<%= submit_tag l(:button_save), name: 'save', class: 'qbo-button qbo-button-dark' %> <%= submit_tag l(:button_save), name: 'save', class: 'qbo-button qbo-button-dark' %>
<% if sender %> <% if sender %>
<%= submit_tag l(:button_save_and_send), name: 'save_and_send', class: 'qbo-button qbo-button-primary', <%= submit_tag l(:button_save_and_send), name: 'save_and_send', class: 'qbo-button qbo-button-primary',
+2 -1
View File
@@ -1,4 +1,5 @@
<% html_title l(:label_new_estimate) %> <% html_title l(:label_new_estimate) %>
<%= render partial: 'qbo_estimates/header', locals: { form: @form } %> <%= render partial: 'qbo_estimates/header', locals: { form: @form } %>
<%= render partial: 'qbo_estimates/form', locals: { form: @form } %> <%= render partial: 'qbo_drafts/editor_notice', locals: { draft: @draft, drafts: @customer_drafts } %>
<%= render partial: 'qbo_estimates/form', locals: { form: @form, draft: @draft } %>
+2 -1
View File
@@ -1,5 +1,6 @@
<% html_title l(:label_new_invoice) %> <% html_title l(:label_new_invoice) %>
<%= render partial: 'qbo_estimates/header', locals: { form: @form } %> <%= render partial: 'qbo_estimates/header', locals: { form: @form } %>
<%= render partial: 'qbo_drafts/editor_notice', locals: { draft: @draft, drafts: @customer_drafts } %>
<%= render partial: 'qbo_invoices/open_issues', locals: { customer: (Customer.find_by(id: @form.customer_id) if @form.customer_id.present?) } %> <%= render partial: 'qbo_invoices/open_issues', locals: { customer: (Customer.find_by(id: @form.customer_id) if @form.customer_id.present?) } %>
<%= render partial: 'qbo_estimates/form', locals: { form: @form } %> <%= render partial: 'qbo_estimates/form', locals: { form: @form, draft: @draft } %>
+24
View File
@@ -130,6 +130,30 @@ en:
button_open_in_quickbooks: "Open in QuickBooks" button_open_in_quickbooks: "Open in QuickBooks"
button_refresh_quickbooks_fields: "Refresh QuickBooks fields" button_refresh_quickbooks_fields: "Refresh QuickBooks fields"
label_qbo_hidden_custom_fields: "Hide QuickBooks custom fields" label_qbo_hidden_custom_fields: "Hide QuickBooks custom fields"
# Estimate and invoice drafts
label_qbo_drafts: "Drafts"
label_qbo_draft_document: "Draft"
label_qbo_draft_lines: "Lines"
label_qbo_draft_saved_by: "Last saved"
label_qbo_estimate_draft: "Estimate draft"
label_qbo_invoice_draft: "Invoice draft"
button_qbo_save_draft: "Save draft"
button_qbo_delete_draft: "Delete draft"
button_qbo_continue_draft: "Continue"
notice_qbo_draft_saved: "Draft saved. It's kept in Redmine only, until you save it to QuickBooks."
notice_qbo_draft_deleted: "Draft deleted."
error_qbo_draft_not_found: "That draft is gone. It may have been finished or deleted."
text_qbo_draft_saved_by: "%{user}, %{age} ago"
text_qbo_editing_draft: "Draft, not in QuickBooks yet. Last saved by %{user}, %{age} ago. Save it to send it to QuickBooks; that deletes the draft."
text_qbo_customer_has_estimate_drafts:
one: "This customer has an estimate draft:"
other: "This customer has %{count} estimate drafts:"
text_qbo_customer_has_invoice_drafts:
one: "This customer has an invoice draft:"
other: "This customer has %{count} invoice drafts:"
text_qbo_draft_link: "%{subtotal}, saved by %{user} %{date}"
text_qbo_drafts_info: "New estimates and invoices saved as drafts. They're kept in Redmine only, so nothing is in QuickBooks (and no deposit is applied to an invoice) until a draft is saved from the editor."
text_qbo_sales_person_field: "filled in with the sales person" text_qbo_sales_person_field: "filled in with the sales person"
text_qbo_hidden_custom_fields: "Ticked fields are left off estimates and invoices. QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so tick ones you no longer use (e.g. a renamed \"Sales Rep old\"). The sales person goes in the first field shown whose name has \"sales\" or \"rep\" in it." text_qbo_hidden_custom_fields: "Ticked fields are left off estimates and invoices. QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so tick ones you no longer use (e.g. a renamed \"Sales Rep old\"). The sales person goes in the first field shown whose name has \"sales\" or \"rep\" in it."
button_reload_estimate: "Reload the estimate" button_reload_estimate: "Reload the estimate"
+3
View File
@@ -68,6 +68,9 @@ resources :qbo_invoices, only: [:new, :create, :edit, :update] do
end end
end end
# Estimate and invoice drafts, kept in Redmine until they're saved to QuickBooks (continued on the editors)
resources :qbo_drafts, only: [:index, :destroy]
# Receive payment pages, and a customer's payments (/qbo_payments?customer_id=) # Receive payment pages, and a customer's payments (/qbo_payments?customer_id=)
resources :qbo_payments, only: [:index, :new, :create, :show] do resources :qbo_payments, only: [:index, :new, :create, :show] do
member do member do
+31
View File
@@ -0,0 +1,31 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of 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.
# Estimate and invoice drafts: what's filled in on the editor, kept in Redmine until it's saved to QuickBooks
class CreateQboDrafts < ActiveRecord::Migration[7.0]
def up
return if table_exists?(:qbo_drafts)
create_table :qbo_drafts do |t|
t.string :document, null: false, limit: 20
t.bigint :customer_id
# Who saved it last
t.integer :user_id
# The editor's fields, as posted (JSON)
t.text :data, size: :medium
t.timestamps
end
add_index :qbo_drafts, [:document, :customer_id]
end
def down
drop_table :qbo_drafts if table_exists?(:qbo_drafts)
end
end
+4 -2
View File
@@ -40,11 +40,13 @@ Redmine::Plugin.register :redmine_qbo do
# Billing (global): estimates, invoices, payments, issues from estimates # Billing (global): estimates, invoices, payments, issues from estimates
# customer_info and items feed the customer details and product/service search on the estimate/invoice editor # customer_info and items feed the customer details and product/service search on the estimate/invoice editor
permission :write_estimates, { qbo_estimates: [:new, :create, :edit, :update, :customer_info, :items] }, global: true # Drafts (QboDraft): each user sees the drafts of the documents they may write
permission :write_estimates, { qbo_estimates: [:new, :create, :edit, :update, :customer_info, :items],
qbo_drafts: [:index, :destroy] }, global: true
permission :send_estimates, { qbo_estimates: [:send_email] }, global: true permission :send_estimates, { qbo_estimates: [:send_email] }, global: true
permission :create_estimate_issues, { qbo_estimates: [:issues_preview, :create_issues] }, global: true permission :create_estimate_issues, { qbo_estimates: [:issues_preview, :create_issues] }, global: true
permission :write_invoices, { qbo_invoices: [:new, :create, :edit, :update, :import_options], permission :write_invoices, { qbo_invoices: [:new, :create, :edit, :update, :import_options],
qbo_estimates: [:customer_info, :items] }, global: true qbo_estimates: [:customer_info, :items], qbo_drafts: [:index, :destroy] }, global: true
permission :send_invoices, { qbo_invoices: [:send_email] }, global: true permission :send_invoices, { qbo_invoices: [:send_email] }, global: true
permission :view_payments, { qbo_payments: [:index, :show, :pdf] }, global: true permission :view_payments, { qbo_payments: [:index, :show, :pdf] }, global: true
permission :receive_payments, { qbo_payments: [:index, :new, :create, :show, :pdf, :open_invoices], permission :receive_payments, { qbo_payments: [:index, :new, :create, :show, :pdf, :open_invoices],