Sync services and other items without a description or rate

QuickBooks only requires an item's name, but the local Item required a description and a rate, so
services such as Labor (often with neither) failed validation and were silently skipped by the sync.
Name is now the only requirement; a missing description syncs as blank and a missing rate as 0.
Product/service pickers and the labor setting list sellable items only (no Categories or Bundles).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 09:34:22 -04:00
1 parent 06a78ebccb
commit bf7c7b0905
6 files changed
+18 -6

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ class ItemsController < ApplicationController
term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s) 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}%") items = Item.where("description LIKE :t OR name LIKE :t OR sku LIKE :t", t: "%#{term}%")
.where(active: true) .merge(Item.sellable)
.order(:description) .order(:description)
.limit(20) .limit(20)
+1 -1
View File
@@ -125,7 +125,7 @@ class QboEstimatesController < ApplicationController
def items def items
term = "%#{ActiveRecord::Base.sanitize_sql_like(params[:q].to_s.strip)}%" term = "%#{ActiveRecord::Base.sanitize_sql_like(params[:q].to_s.strip)}%"
items = Item.where(active: true) items = Item.sellable
.where("name LIKE :t OR sku LIKE :t OR description LIKE :t", t: term) .where("name LIKE :t OR sku LIKE :t OR description LIKE :t", t: term)
.order(:name) .order(:name)
.limit(25) .limit(25)
+9 -1
View File
@@ -11,8 +11,16 @@
class Item < QboBaseModel class Item < QboBaseModel
belongs_to :account, optional: true belongs_to :account, optional: true
validates_presence_of :id, :description # QuickBooks only requires a name: services such as Labor often have no description or rate
validates_presence_of :id, :name
validates :unit_price, numericality: { greater_than_or_equal_to: 0 } validates :unit_price, numericality: { greater_than_or_equal_to: 0 }
# QuickBooks item types that can't go on an estimate or invoice line themselves
UNSELLABLE_TYPES = %w[Category Group].freeze
# Active products/services that can go on a line (services, non-inventory and inventory items), for the
# pickers and the labor products/services setting
scope :sellable, -> { where(active: true).where.not(type: UNSELLABLE_TYPES).or(where(active: true, type: nil)) }
self.primary_key = :id self.primary_key = :id
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
qbo_sync push: true qbo_sync push: true
+5 -1
View File
@@ -30,6 +30,10 @@ class ItemSyncService < SyncServiceBase
account_id = remote.income_account_ref&.value account_id = remote.income_account_ref&.value
account_id.present? ? Account.find_by(id: account_id.to_i) : nil account_id.present? ? Account.find_by(id: account_id.to_i) : nil
end end
map_attributes :description, :id, :name, :sku, :type, :unit_price map_attributes :id, :name, :sku, :type
# Services such as Labor often have no description or rate in QuickBooks; they sync as blank and 0
# instead of failing validation and being skipped
map_attribute(:description) { |remote| remote.description.to_s }
map_attribute(:unit_price) { |remote| remote.unit_price || 0 }
end end
+1 -1
View File
@@ -11,7 +11,7 @@
<label for="settings_labor_item_ids"><%= l(:label_labor_items) %></label> <label for="settings_labor_item_ids"><%= l(:label_labor_items) %></label>
<%= hidden_field_tag 'settings[labor_item_ids][]', '', id: nil %> <%= hidden_field_tag 'settings[labor_item_ids][]', '', id: nil %>
<%= select_tag 'settings[labor_item_ids][]', <%= select_tag 'settings[labor_item_ids][]',
options_from_collection_for_select(Item.where(active: true).order(:name), :id, :name, options_from_collection_for_select(Item.sellable.order(:name), :id, :name,
RedmineQboBilling::LaborItems.item_ids), RedmineQboBilling::LaborItems.item_ids),
multiple: true, size: 8, id: 'settings_labor_item_ids' %> multiple: true, size: 8, id: 'settings_labor_item_ids' %>
<em class="info"><%= l(:text_labor_items) %></em> <em class="info"><%= l(:text_labor_items) %></em>
+1 -1
View File
@@ -55,7 +55,7 @@ module RedmineQboBilling
return chosen if chosen.any? return chosen if chosen.any?
list = codes list = codes
Item.where(active: true).pluck(:id, :name).select { |_, name| name_matches?(name, list) }.map { |id, _| id.to_s } Item.sellable.pluck(:id, :name).select { |_, name| name_matches?(name, list) }.map { |id, _| id.to_s }
rescue StandardError rescue StandardError
[] []
end end