Cache invoices' sales tax and the day they were paid in full

New invoices columns tax_amount and paid_on, filled in by the invoice
sync. An invoice is paid in full on the later of its date and the
dates of the payments and credit memos applied to it (local payments
first; QuickBooks only for ones not synced yet and credit memos), so
reports such as the monthly sales commission don't have to read
invoices from QuickBooks. A full sync fills them in for older
invoices; it now syncs payments before invoices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-17 18:34:21 -05:00
1 parent 4f6f81c87a
commit 5b6c1ed2c2
5 files changed
+170 -2

No files matched your search

@@ -0,0 +1,20 @@
#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.
# An invoice's sales tax and the day it was paid in full, cached like its total and balance, so reports (e.g.
# redmine_qbo_commission's monthly paid sales) don't have to read invoices from QuickBooks. A full invoice sync
# fills them in for invoices synced before.
class AddInvoiceTaxAndPaidOn < ActiveRecord::Migration[7.0]
def change
add_column :invoices, :tax_amount, :decimal, precision: 15, scale: 2 unless column_exists?(:invoices, :tax_amount)
add_column :invoices, :paid_on, :date unless column_exists?(:invoices, :paid_on)
add_index :invoices, :paid_on unless index_exists?(:invoices, :paid_on)
end
end