From 3a2d50ae8d354a805465d9553e2790adf18759ed Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 13:50:15 -0400 Subject: [PATCH] Move items, accounts and estimate writing to redmine_qbo_billing The QuickBooks product/service list and income accounts (models, syncs, admin pages, routes, settings) now live in redmine_qbo_billing, which this plugin requires. The closing-an-issue estimate is written through RedmineQboBilling::EstimateWriter.create_estimate, so estimate building isn't duplicated; it now also gets the customer email, VIN, default message and expiration date. Migrations: 002 now only links line items to items (skipped where the column exists). 003 and 004 are removed; billing's migrations find the existing items and accounts tables and leave them alone, so nothing is dropped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- README.md | 11 ++- app/controllers/accounts_controller.rb | 37 -------- app/controllers/items_controller.rb | 106 ---------------------- app/jobs/bill_line_items_job.rb | 48 ++++------ app/models/account.rb | 41 --------- app/models/item.rb | 68 -------------- app/services/account_sync_service.rb | 23 ----- app/services/item_service.rb | 26 ------ app/services/item_sync_service.rb | 35 ------- app/views/accounts/index.html.erb | 37 -------- app/views/items/_form.html.erb | 50 ---------- app/views/items/edit.html.erb | 3 - app/views/items/index.html.erb | 56 ------------ app/views/items/new.html.erb | 5 - app/views/items/show.html.erb | 44 --------- app/views/line_items/_settings.html.erb | 39 -------- config/locales/en.yml | 24 ----- config/routes.rb | 23 ----- db/migrate/002_create_items.rb | 19 ++-- db/migrate/003_update_items.rb | 16 ---- db/migrate/004_create_accounts.rb | 26 ------ init.rb | 11 ++- lib/line_items/hooks/qbo_hook_listener.rb | 37 -------- lib/redmine_qbo_line_items.rb | 6 -- 24 files changed, 43 insertions(+), 748 deletions(-) delete mode 100644 app/controllers/accounts_controller.rb delete mode 100644 app/controllers/items_controller.rb delete mode 100644 app/models/account.rb delete mode 100644 app/models/item.rb delete mode 100644 app/services/account_sync_service.rb delete mode 100644 app/services/item_service.rb delete mode 100644 app/services/item_sync_service.rb delete mode 100644 app/views/accounts/index.html.erb delete mode 100644 app/views/items/_form.html.erb delete mode 100644 app/views/items/edit.html.erb delete mode 100644 app/views/items/index.html.erb delete mode 100644 app/views/items/new.html.erb delete mode 100644 app/views/items/show.html.erb delete mode 100644 app/views/line_items/_settings.html.erb delete mode 100644 config/routes.rb delete mode 100644 db/migrate/003_update_items.rb delete mode 100644 db/migrate/004_create_accounts.rb delete mode 100644 lib/line_items/hooks/qbo_hook_listener.rb diff --git a/README.md b/README.md index d3d931c..7c5d934 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh * **Redmine:** 6.1+ * **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) (must be installed and configured) - + +* **Billing Plugin:** [Redmine QuickBooks Billing](https://github.com/rickbarrette/redmine_qbo_billing). It holds the QuickBooks product/service list, the income accounts, and the estimate writing this plugin uses. + --- @@ -20,6 +22,7 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh | Plugin Version | Redmine Version | Parent Plugin Version | | --- | --- | --- | | 2026.3.8+ | 6.1.x | 2026.3.9+ | +| 2026.11.0+ | 7.0.x | 2026.10.1+, with redmine_qbo_billing 2026.10.0+ | --- @@ -86,9 +89,11 @@ Before using this plugin: 2. Ensure your **QuickBooks Online** company file is connected. -3. Sync Accounts & Items via plugin settings +3. Install redmine_qbo_billing, then sync accounts and items and set the default income account for new items in its plugin settings -4. Set default income account for new items via plugin settings +### Upgrading from a version that managed items and accounts + +Items and accounts moved to redmine_qbo_billing. Install redmine_qbo_billing next to this plugin and run the plugin migrations as usual: billing finds the existing `items` and `accounts` tables and keeps using them, so no data is moved or lost. The Items and Accounts pages keep their URLs. --- diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb deleted file mode 100644 index 99f6f13..0000000 --- a/app/controllers/accounts_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -#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. - -class AccountsController < ApplicationController - layout 'admin' - menu_item :redmine_qbo_lineitems - - # Accounts come from QuickBooks; choosing the default and syncing are admin-only - before_action :require_admin - - def index - @accounts = Account.where(classification: 'Revenue').order(:name) - end - - def set_default - account = Account.find_by(id: params[:default_account_id]) - - if account&.update(default: true) - flash[:notice] = l(:notice_default_account_updated) - else - flash[:error] = l(:error_default_account_not_selected) - end - redirect_to accounts_path - end - - def sync - Account.sync - redirect_to :home, flash: { notice: I18n.t(:label_syncing) } - end -end \ No newline at end of file diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb deleted file mode 100644 index a2d8637..0000000 --- a/app/controllers/items_controller.rb +++ /dev/null @@ -1,106 +0,0 @@ -#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. - -class ItemsController < ApplicationController - layout 'admin' - menu_item :redmine_qbo_lineitems - - # The item catalog is pushed to QuickBooks, so managing it is admin-only. The autocomplete feeds the - # line item form on issues and is allowed with the "Add line items" or "Edit line items" permission. - before_action :require_admin, except: :autocomplete - before_action :authorize_global, only: :autocomplete - before_action :find_item, only: [:show, :edit, :update, :destroy] - - # Used for autocomplete form - def autocomplete - term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s) - - items = Item.where("description LIKE :t OR name LIKE :t OR sku LIKE :t", t: "%#{term}%") - .where(active: true) - .order(:description) - .limit(20) - - render json: items.map { |i| - { id: i.id, name: i.name, sku: i.sku, description: i.description, price: i.unit_price } - } - end - - def create - @item = Item.new(item_params) - - if @item.save - redirect_to item_path(@item), notice: l(:notice_successful_create) - else - render :new, status: :unprocessable_entity - end - rescue => e - log "Unexpected error creating item: #{e.message}" - - # Regex now matches across line breaks - existing_id = e.message[/Duplicate Name Exists Error:[\s\S]*Id=(\d+)/, 1]&.to_i - - if existing_id - flash[:error] = "Name already exists. Redirecting to existing item." - redirect_to item_path(existing_id) - else - flash[:error] = e.message - redirect_to new_item_path - end - end - - def destroy - @item.destroy - redirect_to items_path, notice: l(:notice_successful_delete) - end - - def edit - end - - def index - @items = Item.order(:name) - end - - def new - @item = Item.new - end - - def show - end - - def sync - Item.sync - redirect_to :home, flash: { notice: I18n.t(:label_syncing) } - end - - def update - if @item.update(item_params) - redirect_to item_path(@item), notice: l(:notice_successful_update) - else - render :edit, status: :unprocessable_entity - end - end - - private - - def find_item - @item = Item.find(params[:id]) - rescue ActiveRecord::RecordNotFound - render_404 - end - - def item_params - params.require(:item).permit(:name, :description, :sku, :unit_price, :active, :account_id, :type, :taxable) - end - - def log(msg) - Rails.logger.info "[ItemsController] #{msg}" - end - -end \ No newline at end of file diff --git a/app/jobs/bill_line_items_job.rb b/app/jobs/bill_line_items_job.rb index d06c216..7aad48f 100644 --- a/app/jobs/bill_line_items_job.rb +++ b/app/jobs/bill_line_items_job.rb @@ -24,10 +24,7 @@ class BillLineItemsJob < ActiveJob::Base unbilled_entries = issue.line_items.where(billed: [false, nil]).lock return if unbilled_entries.blank? - qbo = QboConnectionService.current! - qbo.perform_authenticated_request do |access_token| - create_estimate(issue, unbilled_entries, access_token, qbo) - end + create_estimate(issue, unbilled_entries) # Only mark billed AFTER successful QBO creation unbilled_entries.update_all(billed: true) @@ -42,35 +39,28 @@ class BillLineItemsJob < ActiveJob::Base private - # Create an Estimate record in QBO for each unbilled line item - def create_estimate(issue, unbilled_entries, access_token, qbo) - log "Creating Estimate records in QBO for #{issue.customer.name} from issue ##{issue.id}" - - estimate = Quickbooks::Model::Estimate.new(customer_id: issue.customer.id) - estimate_service = Quickbooks::Service::Estimate.new( company_id: qbo.realm_id, access_token: access_token) + # Creates the QuickBooks estimate with redmine_qbo_billing, which writes every estimate: a first line + # saying where the lines came from, then the unbilled line items. The VIN comes from the issue's vehicle. + def create_estimate(issue, unbilled_entries) + log "Creating estimate in QBO for #{issue.customer.name} from issue ##{issue.id}" memo = "Added from: #{issue.tracker} ##{issue.id}: #{issue.subject}" - estimate.private_note = memo - estimate.line_items << Quickbooks::Model::InvoiceLineItem.new(description: memo, detail_type: 'DescriptionOnly' ) - - unbilled_entries.each do |item| - log "Creating Line Item for #{item.description}" - line = Quickbooks::Model::InvoiceLineItem.new - line.amount = item.line_total - line.description = item.description - line.sales_item! do |detail| - detail.unit_price = item.unit_price - detail.quantity = item.quantity - # Assign "TAX" only if the item is taxable or unknown - if item.item.nil? || item.item.taxable - detail.tax_code_ref = Quickbooks::Model::BaseReference.new("TAX") - end - end - estimate.line_items << line + lines = [{ description: memo }] + unbilled_entries.each do |entry| + lines << { + item_id: entry.item_id, + description: entry.description, + quantity: entry.quantity, + rate: entry.unit_price, + # Taxable unless the item says otherwise (or the line has no item) + taxable: entry.item.nil? || entry.item.taxable != false + } end - e = estimate_service.create(estimate) - log "Created estimate ##{e.doc_number}" + vin = issue.respond_to?(:vehicle) ? issue.vehicle&.vin : nil + estimate = RedmineQboBilling::EstimateWriter.create_estimate(customer: issue.customer, lines: lines, + private_note: memo, vin: vin) + log "Created estimate ##{estimate.doc_number}" end def log(msg) diff --git a/app/models/account.rb b/app/models/account.rb deleted file mode 100644 index 1aef2a5..0000000 --- a/app/models/account.rb +++ /dev/null @@ -1,41 +0,0 @@ -#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. - -class Account < QboBaseModel - has_many :items - validates_presence_of :id, :name - self.primary_key = :id - qbo_sync push: false - before_save :clear_other_defaults, if: :default? - - # Returns the account marked as default - def self.get_default - find_by(default: true) - end - - # Returns QBO Refrence object for the account - def ref - r = Quickbooks::Model::BaseReference.new - r.value = id - r.name = name - return r - end - - def to_s - name - end - - private - - def clear_other_defaults - Account.where.not(id: id).update_all(default: false) - end - -end \ No newline at end of file diff --git a/app/models/item.rb b/app/models/item.rb deleted file mode 100644 index d9a5f87..0000000 --- a/app/models/item.rb +++ /dev/null @@ -1,68 +0,0 @@ -#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. - -class Item < QboBaseModel - belongs_to :account, optional: true - - validates_presence_of :id, :description - validates :unit_price, numericality: { greater_than_or_equal_to: 0 } - self.primary_key = :id - self.inheritance_column = :_type_disabled - qbo_sync push: true - after_initialize :set_defaults, if: :new_record? - before_destroy :make_inactive - - # Updates Both local & remote DB account ref (a blank or unknown account leaves QBO's ref unchanged) - def account_id=(id) - account = Account.find_by(id: id) if id.present? - details.income_account_ref = account.ref if account - super - end - - # Updates Both local & remote DB description - def description=(s) - details.description = s - super - end - - # Updates Both local & remote DB name - def name=(s) - details.name = s - super - end - - def make_inactive - details.active = false - push_to_qbo - end - - def set_defaults - self.taxable = true if taxable.nil? - end - - # Updates Both local & remote DB sku - def sku=(s) - details.sku = s - super - end - - # Updates Both local & remote DB type - def type=(s) - details.type = s.to_s - super - end - - # Updates Both local & remote DB price - def unit_price=(s) - details.unit_price = s - super - end - -end \ No newline at end of file diff --git a/app/services/account_sync_service.rb b/app/services/account_sync_service.rb deleted file mode 100644 index f7bea75..0000000 --- a/app/services/account_sync_service.rb +++ /dev/null @@ -1,23 +0,0 @@ -#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. - -class AccountSyncService < SyncServiceBase - - private - - # Specify the local model this service syncs - def self.model_class - Account - end - - map_attribute :active, :active? - map_attributes :classification, :description, :id, :name - -end \ No newline at end of file diff --git a/app/services/item_service.rb b/app/services/item_service.rb deleted file mode 100644 index e19e108..0000000 --- a/app/services/item_service.rb +++ /dev/null @@ -1,26 +0,0 @@ -#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. - -class ItemService < ServiceBase - - private - - def build_qbo_remote - log "Building new QBO Item" - # New items default to a non-inventory item in the default income account; the item form then - # sets the type and account the user chose. - item = Quickbooks::Model::Item.new - item.type = Quickbooks::Model::Item::NON_INVENTORY_TYPE - default_account = Account.get_default - item.income_account_ref = default_account.ref if default_account - item - end - -end \ No newline at end of file diff --git a/app/services/item_sync_service.rb b/app/services/item_sync_service.rb deleted file mode 100644 index a963e52..0000000 --- a/app/services/item_sync_service.rb +++ /dev/null @@ -1,35 +0,0 @@ -#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. - -class ItemSyncService < SyncServiceBase - - private - - # Specify the local model this service syncs - def self.model_class - Item - end - - # Specify a page size of 20, as the API only returns 20 items at a time. - def self.page_size - 20 - end - - map_attribute :active, :active? - map_attribute :taxable, :taxable? - # Items without an income account (e.g. categories), or whose account hasn't synced yet, get none - # instead of failing the whole sync; the next sync fills it in. - map_attribute :account do |remote| - account_id = remote.income_account_ref&.value - account_id.present? ? Account.find_by(id: account_id.to_i) : nil - end - map_attributes :description, :id, :name, :sku, :type, :unit_price - -end \ No newline at end of file diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb deleted file mode 100644 index c476dd5..0000000 --- a/app/views/accounts/index.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -

<%= l(:label_accounts) %>

- -<%= form_tag set_default_accounts_path, method: :patch do %> -
- - - - - - - - - - - - - <% @accounts.each do |account| %> - "> - - - - - - - <% end %> - -
<%= l(:label_default) %><%= l(:field_name) %><%= l(:field_description) %><%= l(:field_classification) %><%= l(:field_active) %>
- <%= radio_button_tag "default_account_id", account.id, account.default %> - <%= account.name %><%= truncate(account.description, length: 80) %><%= account.classification %> - <%= checked_image account.active %> -
-
- -

- <%= submit_tag l(:button_save), class: 'button-small' %> -

-<% end %> \ No newline at end of file diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb deleted file mode 100644 index e181d47..0000000 --- a/app/views/items/_form.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -<%= labelled_form_for @item do |f| %> - <%= error_messages_for 'item' %> - -
-

- <%= f.text_field :name, required: true, size: 60 %> -

- -

- <%= f.text_field :sku, size: 30 %> -

- -

- <%= f.text_area :description, rows: 4, class: 'wiki-edit' %> -

- -

- <%= f.text_field :unit_price, - class: "price-field", - inputmode: "decimal", - autocomplete: "off"%> -

- -

- <%= f.check_box :taxable %> -

- -

- <%= f.label :account_id, l(:label_account) %> - <%= f.collection_select :account_id, - Account.where(classification: 'Revenue').order(:name), - :id, - :name, - { selected: @item.account_id || Account.get_default&.id, include_blank: true } %> -

- -

- <%= f.select :type, - Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] }, - { selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE } %> -

- -

- <%= f.check_box :active %> -

-
- - <%= submit_tag l(:button_save) %> - <%= link_to l(:button_cancel), items_path if controller.action_name == 'edit' %> -<% end %> \ No newline at end of file diff --git a/app/views/items/edit.html.erb b/app/views/items/edit.html.erb deleted file mode 100644 index 254136c..0000000 --- a/app/views/items/edit.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

<%=t(:label_edit_item)%>

- -<%= render "form" %> \ No newline at end of file diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb deleted file mode 100644 index 79d3d26..0000000 --- a/app/views/items/index.html.erb +++ /dev/null @@ -1,56 +0,0 @@ -
- <%= link_to l(:label_item_new), new_item_path, class: 'icon icon-add' %> -
- -

<%= l(:label_items) %>

- -<% if @items.any? %> -
- - - - - - - - - - - - - - <% @items.each do |item| %> - "> - - - - - - - - - <% end %> - -
<%= l(:field_name) %><%= l(:field_sku) %><%= l(:field_description) %><%= l(:field_unit_price) %><%= l(:field_taxable) %><%= l(:field_active) %>
<%= link_to item.name, item_path(item) %><%= item.sku %><%= truncate(item.description, length: 60) %><%= number_to_currency(item.unit_price) %> - <% if item.taxable %> - <%= l(:general_text_Yes) %> - <% else %> - <%= l(:general_text_No) %> - <% end %> - - <% if item.active %> - <%= l(:general_text_Yes) %> - <% else %> - <%= l(:general_text_No) %> - <% end %> - - <%= link_to l(:button_edit), edit_item_path(item), class: 'icon icon-edit' %> - <%= link_to l(:button_delete), item_path(item), - method: :delete, - data: { confirm: l(:text_are_you_sure) }, - class: 'icon icon-del' %> -
-
-<% else %> -

<%= l(:label_no_data) %>

-<% end %> \ No newline at end of file diff --git a/app/views/items/new.html.erb b/app/views/items/new.html.erb deleted file mode 100644 index f2e4270..0000000 --- a/app/views/items/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

<%=t(:label_item_new)%>

- -<%= render "form" %> - -<%= link_to t(:label_back), items_path %> \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb deleted file mode 100644 index 6cbcba0..0000000 --- a/app/views/items/show.html.erb +++ /dev/null @@ -1,44 +0,0 @@ -
- <%= link_to l(:button_edit), edit_item_path(@item), class: 'icon icon-edit' %> - <%= link_to l(:button_back), items_path, class: 'icon icon-list' %> -
- -

<%= t(:item) %># <%= @item.id %> <%= @item.name %>

- -
-
-
-

<%=t(:field_sku)%>: <%= @item.sku.presence || "-" %>

-

<%=t(:label_type)%>: <%= @item.type.presence || "-" %>

-

<%=t(:field_unit_price)%>: <%= number_to_currency(@item.unit_price) %>

-
- -
-

<%=t(:label_account)%>: <%= @item.account&.name || "-" %>

-

- <%=t(:field_taxable)%>: - <% if @item.taxable %> - <%=t(:yes)%> - <% else %> - <%=t(:no)%> - <% end %> -

-

- <%=t(:label_active)%>: - <% if @item.active %> - <%=t(:yes)%> - <% else %> - <%=t(:no)%> - <% end %> -

-
-
- -
- -

<%=t(:label_description)%>:

-
- <%= @item.description.presence || "No description provided".html_safe %> -
-
-
\ No newline at end of file diff --git a/app/views/line_items/_settings.html.erb b/app/views/line_items/_settings.html.erb deleted file mode 100644 index d74df87..0000000 --- a/app/views/line_items/_settings.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -
-

- - <%= Item.count %> - - (@ <%= Item.last_sync %>) - -

-

- - <%= Account.count %> - - (@ <%= Account.last_sync %>) - -

-

- - <%= Qbo.exists? ? Qbo.last_sync : l(:label_never_synced) %> -

-

- - <%= Account.get_default %> -

-
- -
- <%= l(:label_management_and_sync) %> - -
- <%= link_to t(:label_sync_now_items), sync_items_path, class: 'button icon icon-reload' %> - <%= link_to t(:label_sync_now_accounts), sync_accounts_path, class: 'button icon icon-reload' %> -
- -
- <%= link_to t(:label_items), items_path, class: 'icon icon-list' %> - | - <%= link_to t(:label_accounts), accounts_path, class: 'icon icon-list' %> -
-
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 07e08c3..21f2500 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,40 +11,16 @@ # English strings go here for Rails i18n # Usage I18n.t(:label) en: - field_classification: "Classification" - field_sku: "SKU" - field_taxable: "Taxable" - field_unit_price: "Unit Price" - label_active: "Activie" - label_account: "Account" - label_accounts: "Accounts" - label_back: "Back" - label_account_count: "Number of Accounts:" - label_default_account: "Default Item Income Account" label_description: "Description" - label_edit_item: "Edit Item" - label_item: "Item" - label_item_count: "Item Count:" - label_items: "Items" label_line_items: "Line Items" label_price: "Unit Price" - label_item_new: "New Item" - label_no: "No" label_qty: "Quantity" label_remove: "Remove" label_running_total: "Running Total" - label_sync_now_accounts: "Sync Accounts" - label_sync_now_items: "Sync Items" - label_type: "Type" label_total: "Total" - label_yes: "Yes" notice_added_from: "Added from issue #" - error_default_account_not_selected: "Select an account to make it the default." label_billed: "Billed" - label_management_and_sync: "Management & Synchronization" - label_never_synced: "Never synced" - notice_default_account_updated: "Default account updated." text_line_item_billed: "Already added to a QuickBooks estimate, so it can't be changed or removed." diff --git a/config/routes.rb b/config/routes.rb deleted file mode 100644 index 7174538..0000000 --- a/config/routes.rb +++ /dev/null @@ -1,23 +0,0 @@ -#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. - -resources :items do - collection do - get :autocomplete - get :sync - end -end - -resources :accounts do - collection do - patch :set_default - get :sync - end -end \ No newline at end of file diff --git a/db/migrate/002_create_items.rb b/db/migrate/002_create_items.rb index 3c5db50..2d10235 100644 --- a/db/migrate/002_create_items.rb +++ b/db/migrate/002_create_items.rb @@ -8,19 +8,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. +# Links each line item to a QuickBooks item. The items table itself now belongs to redmine_qbo_billing +# (which Redmine migrates first); databases that ran the old version of this migration already have both. class CreateItems < ActiveRecord::Migration[7.0] - def change - create_table :items do |t| - t.text :description, null: false - t.decimal :unit_price, - precision: 15, - scale: 4, - null: false, - default: 0 - t.boolean :active, default: true, null: false - t.timestamps - end + def up + add_reference :line_items, :item, foreign_key: true unless column_exists?(:line_items, :item_id) + end - add_reference :line_items, :item, foreign_key: true + def down + remove_reference :line_items, :item, foreign_key: true if column_exists?(:line_items, :item_id) end end \ No newline at end of file diff --git a/db/migrate/003_update_items.rb b/db/migrate/003_update_items.rb deleted file mode 100644 index a749a90..0000000 --- a/db/migrate/003_update_items.rb +++ /dev/null @@ -1,16 +0,0 @@ -#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. - -class UpdateItems < ActiveRecord::Migration[7.0] - def change - add_column :items, :name, :string, null: false - add_column :items, :sku, :string - end -end \ No newline at end of file diff --git a/db/migrate/004_create_accounts.rb b/db/migrate/004_create_accounts.rb deleted file mode 100644 index b58fb22..0000000 --- a/db/migrate/004_create_accounts.rb +++ /dev/null @@ -1,26 +0,0 @@ -#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. - -class CreateAccounts < ActiveRecord::Migration[7.0] - def change - create_table :accounts do |t| - t.text :name, null: false - t.text :description - t.boolean :active, default: true, null: false - t.boolean :default, default: false, null: false - t.text :classification - t.timestamps - end - - add_reference :items, :account, foreign_key: true - add_column :items, :type, :string - add_column :items, :taxable, :boolean, null: true - end -end \ No newline at end of file diff --git a/init.rb b/init.rb index 5ba9810..328a25a 100644 --- a/init.rb +++ b/init.rb @@ -18,7 +18,6 @@ Redmine::Plugin.register :redmine_qbo_lineitems do url 'https://github.com/rickbarrette/redmine_qbo_lineitems' author_url 'https://barrettefabrication.com' requires_redmine version_or_higher: '6.1.0' - settings partial: 'line_items/settings' # Ensure redmine_qbo is installed begin @@ -26,6 +25,14 @@ Redmine::Plugin.register :redmine_qbo_lineitems do rescue Redmine::PluginNotFound raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)' end + + # The QuickBooks product/service list, accounts and estimate writing live in redmine_qbo_billing + # (it sorts before this plugin, so Redmine has already loaded it) + begin + requires_redmine_plugin :redmine_qbo_billing, version_or_higher: '2026.10.0' + rescue Redmine::PluginNotFound + raise 'Please install the redmine_qbo_billing plugin (https://github.com/rickbarrette/redmine_qbo_billing)' + end # Line items can be submitted with an issue only by users who may add, edit or delete them. # Which changes are applied is checked per line in Issue#line_items_attributes= (see IssuePatch). @@ -34,7 +41,7 @@ Redmine::Plugin.register :redmine_qbo_lineitems do } # Global Permissions. Line items live on issues; these control what users can do with them there. - # Managing the QBO item catalog, accounts and syncs is admin-only. + # The item search (redmine_qbo_billing's items#autocomplete) feeds the line item form. permission :view_line_items, {}, global: true permission :add_line_items, { items: [:autocomplete] }, global: true permission :edit_line_items, { items: [:autocomplete] }, global: true diff --git a/lib/line_items/hooks/qbo_hook_listener.rb b/lib/line_items/hooks/qbo_hook_listener.rb deleted file mode 100644 index e365d6f..0000000 --- a/lib/line_items/hooks/qbo_hook_listener.rb +++ /dev/null @@ -1,37 +0,0 @@ -#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. - -module LineItems - module Hooks - - class QboHookListener < Redmine::Hook::Listener - - # Called by WebhookProcessJob - def qbo_additional_entities(context={}) - log "Added QBO Item to allowed webook entities" - return ["Item", "Account"] - end - - # Called by the QboSyncDispatcher - def qbo_full_sync (context={}) - log "Adding Account and Item to QBO sync dispatcher" - # Accounts first: items reference their income account - return [Account, Item] - end - - private - - def log(msg) - Rails.logger.info "[QboHookListener] #{msg}" - end - - end - end -end \ No newline at end of file diff --git a/lib/redmine_qbo_line_items.rb b/lib/redmine_qbo_line_items.rb index 41b12bd..76145ac 100644 --- a/lib/redmine_qbo_line_items.rb +++ b/lib/redmine_qbo_line_items.rb @@ -16,13 +16,7 @@ module RedmineQboLineItems Issue.prepend LineItems::Patches::IssuePatch # Hooks - LineItems::Hooks::QboHookListener LineItems::Hooks::ViewHookListener - - # Administration menu extension - Redmine::MenuManager.map :admin_menu do |menu| - menu.push :redmine_qbo_lineitems, { controller: 'items', action: 'index' }, icon: 'list', caption: :label_items, html: { class: 'icon icon-list' } - end end end end \ No newline at end of file