Files
redmine_qbo_lineitems/app/services/item_sync_service.rb
T
Claude 39f6b64049 Polish: permissions, billed-line locking, sync and billing fixes
Permissions
- Item catalog and accounts pages, and their syncs, are admin-only (they
  push to / pull from QuickBooks); shown in the Administration layout
- Item autocomplete is allowed with Add or Edit line items
- Permissions now map to real actions (they pointed at a non-existent
  line_items controller); line_items_attributes is only accepted from
  users with a line item permission
- Line item changes are checked on the server: adding, editing and
  deleting each need their permission, and billed lines (already on a
  QBO estimate) can't be changed or removed

Bugs
- Billing on close now runs from an Issue after_commit, so closing via
  bulk edit or the context menu bills too (replaces the save hook);
  the job takes an issue id
- Full sync runs Accounts before Items, and item sync no longer fails
  when an item has no income account or its account hasn't synced
- New QBO items default to Non-inventory in the default income account
  (the account ref was being assigned to the item type)
- Choosing a blank account on an item no longer raises; set_default
  handles no selection
- Item autocomplete escapes item names, SKUs and descriptions (they were
  inserted into the page as HTML)
- Items list showed "translation missing" for Yes/No

Polish
- Fractional quantities allowed (0.5 hrs, 2.5 qts)
- Billed lines show a Billed badge and are read-only; remove button only
  where allowed; add button only with Add line items
- Removed dead code (Item belongs_to :issue, Item#ref, no-op in new,
  swallowed errors); validation failures return 422

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
2026-10-28 22:37:41 -04:00

35 lines
1.8 KiB
Ruby

#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