19 Commits

Author SHA1 Message Date
c968893f94 fixed taxable check 2026-03-17 19:29:05 -04:00
26f84bd221 2026.3.9 2026-03-17 19:21:47 -04:00
f59849e6e5 Merge remote-tracking branch 'origin/master' 2026-03-17 19:20:08 -04:00
6bf5575f9c Updated views for items and accounts 2026-03-17 19:18:03 -04:00
2703d6cc3e Default to taxable, otherwise folllow tax flag 2026-03-17 18:27:56 -04:00
24e3e4ba82 Added taxable flag 2026-03-17 12:25:58 -04:00
f81fe0ef87 Added accounts to allow for assinging income account to items, and selecting default income account. Also added item type selection 2026-03-16 22:59:54 -04:00
a2cc7a97fd Added comment 2026-03-15 18:57:48 -04:00
7088550184 Removed ItemSyncJob as it was replaced withj QboSyncJob 2026-03-15 17:44:14 -04:00
2302679c3a updated ItemSyncService init call 2026-03-15 07:50:07 -04:00
ec1ef72267 Use a private note to make it clear where the estimate came from. 2026-03-14 22:13:45 -04:00
564158722d Updated t work with redmine_qbo 2026.3.9 2026-03-14 21:56:09 -04:00
60a7f769ce Added Screenshots 2026-03-14 08:03:04 -04:00
1367937614 Merge remote-tracking branch 'origin/master' 2026-03-13 08:39:23 -04:00
62adcb11cd fixed typo 2026-03-13 08:38:41 -04:00
896813983c Updated to use DSL and qbo_sync flag 2026-03-13 08:36:49 -04:00
89e3048c29 Update README.md 2026-03-12 12:17:22 -04:00
a7899fb6b3 2026.3.7 2026-03-12 11:23:25 -04:00
ef7570fb3b Refactored to use QboBaseModel & ServiceBase from redmine_qbo 2026-03-12 11:23:07 -04:00
21 changed files with 398 additions and 294 deletions

View File

@@ -21,7 +21,7 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
| Plugin Version | Redmine Version | Ruby Version | | Plugin Version | Redmine Version | Ruby Version |
| --- | --- | --- | | --- | --- | --- |
| 2026.3.5+ | 6.1.x | 3.2+ | | 2026.3.6+ | 6.1.x | 3.2+ |
--- ---

BIN
Screenshots/Form.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

BIN
Screenshots/Issue View.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 KiB

View File

@@ -0,0 +1,27 @@
#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
def index
@accounts = Account.where(classification: 'Revenue').order(:name)
end
def set_default
account = Account.find(params[:default_account_id])
account.update(default: true)
redirect_to accounts_path, notice: "Default account updated."
end
def sync
Account.sync
redirect_to :home, flash: { notice: I18n.t(:label_syncing) }
end
end

View File

@@ -12,6 +12,7 @@ class ItemsController < ApplicationController
before_action :require_login before_action :require_login
before_action :find_item, only: [:show, :edit, :update, :destroy] before_action :find_item, only: [:show, :edit, :update, :destroy]
# Used for autocomplete form
def autocomplete def autocomplete
term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s) term = ActiveRecord::Base.sanitize_sql_like(params[:q].to_s)
@@ -33,6 +34,19 @@ class ItemsController < ApplicationController
else else
render :new render :new
end 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 end
def destroy def destroy
@@ -41,14 +55,19 @@ class ItemsController < ApplicationController
end end
def edit def edit
rescue => e
log "Failed to edit item"
flash[:error] = e.message
render_404
end end
def index def index
@items = Item.order(:name) @items = Item.order(:name)
end end
def new def new
@item = Item.new @item = Item.new
@item.taxable.nil? ? true : @item.taxable
end end
def show def show
@@ -71,9 +90,20 @@ class ItemsController < ApplicationController
def find_item def find_item
@item = Item.find(params[:id]) @item = Item.find(params[:id])
rescue => e
log "Failed to find item"
flash[:error] = e.message
render_404
end end
def item_params def item_params
params.require(:item).permit(:name, :description, :sku, :unit_price, :active) params.require(:item).permit(:name, :description, :sku, :unit_price, :active, :account_id, :type, :taxable)
end end
private
def log(msg)
Rails.logger.info "[ItemsController] #{msg}"
end
end end

View File

@@ -45,8 +45,10 @@ class BillLineItemsJob < ActiveJob::Base
log "Creating Estimate records in QBO for #{issue.customer.name} from issue ##{issue.id}" 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 = Quickbooks::Model::Estimate.new(customer_id: issue.customer.id)
estimate_service = Quickbooks::Service::Estimate.new( company_id: qbo.realm_id, access_token: access_token) estimate_service = Quickbooks::Service::Estimate.new( company_id: qbo.realm_id, access_token: access_token)
estimate.line_items << Quickbooks::Model::InvoiceLineItem.new(description: "#{I18n.t(:notice_added_from)}#{issue.id} #{issue.subject}", detail_type: 'DescriptionOnly' ) 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| unbilled_entries.each do |item|
log "Creating Line Item for #{item.description}" log "Creating Line Item for #{item.description}"
@@ -56,7 +58,10 @@ class BillLineItemsJob < ActiveJob::Base
line.sales_item! do |detail| line.sales_item! do |detail|
detail.unit_price = item.unit_price detail.unit_price = item.unit_price
detail.quantity = item.quantity detail.quantity = item.quantity
detail.tax_code_ref = Quickbooks::Model::BaseReference.new("TAX") # 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 end
estimate.line_items << line estimate.line_items << line
@@ -66,8 +71,6 @@ class BillLineItemsJob < ActiveJob::Base
log "Created estimate ##{e.doc_number}" log "Created estimate ##{e.doc_number}"
end end
private
def log(msg) def log(msg)
Rails.logger.info "[BillLineItemsJob] #{msg}" Rails.logger.info "[BillLineItemsJob] #{msg}"
end end

View File

@@ -8,29 +8,34 @@
# #
#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. #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 ItemSyncJob < ApplicationJob class Account < QboBaseModel
queue_as :default has_many :items
retry_on StandardError, wait: 5.minutes, attempts: 5 validates_presence_of :id, :name
self.primary_key = :id
qbo_sync push: false
before_save :clear_other_defaults, if: :default?
# Performs a sync of items from QuickBooks Online. # Returns the account marked as default
def perform(full_sync: false, id: nil) def self.get_default
qbo = QboConnectionService.current! find_by(default: true)
raise "No QBO configuration found" unless qbo end
log "Starting #{full_sync ? 'full' : 'incremental'} sync for item ##{id || 'all'}..." # Returns QBO Refrence object for the account
def ref
r = Quickbooks::Model::BaseReference.new
r.value = id
r.name = name
return r
end
service = ItemSyncService.new(qbo: qbo) def to_s
name
if id.present?
service.sync_by_id(id)
else
service.sync(full_sync: full_sync)
end
end end
private private
def log(msg) def clear_other_defaults
Rails.logger.info "[ItemSyncJob] #{msg}" Account.where.not(id: id).update_all(default: false)
end end
end end

View File

@@ -8,108 +8,59 @@
# #
#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. #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 < ApplicationRecord class Item < QboBaseModel
belongs_to :issue belongs_to :issue
belongs_to :account
validates_presence_of :id, :description validates_presence_of :id, :description
validates :unit_price, numericality: { greater_than_or_equal_to: 0 } validates :unit_price, numericality: { greater_than_or_equal_to: 0 }
self.primary_key = :id self.primary_key = :id
self.inheritance_column = :_type_disabled
qbo_sync push: true
after_initialize :set_defaults, if: :new_record?
# Returns the details of the item. If the details have already been fetched, it returns the cached version. Otherwise, it fetches the details from QuickBooks Online and caches them for future use. This method is used to access the item's information in a way that minimizes unnecessary API calls to QBO, improving performance and reducing latency. # Updates Both local & remote DB account ref
def details def account_id=(id)
@details ||= begin details.income_account_ref = Account.find(id).ref
xml = Rails.cache.fetch(details_cache_key, expires_in: 10.minutes) do
fetch_details.to_xml_ns
end
Quickbooks::Model::Item.from_xml(xml)
end
end
# Generates a unique cache key for storing this customer's QBO details.
def details_cache_key
"item:#{id}:qbo_details:#{updated_at.to_i}"
end
# Updates Both local & remote DB description
def description=(s)
details
@details.description = s
super super
end end
# Returns the last sync time formatted for display. If no sync has occurred, returns a default message. # Updates Both local & remote DB description
def self.last_sync def description=(s)
return I18n.t(:label_qbo_never_synced) unless maximum(:updated_at) details.description = s
format_time(maximum(:updated_at)) super
end
# Magic Method
# Maps Get/Set methods to QBO item object
def method_missing(method_name, *args, &block)
if Quickbooks::Model::Item.method_defined?(method_name)
details
@details.public_send(method_name, *args, &block)
else
super
end
end end
# Updates Both local & remote DB name # Updates Both local & remote DB name
def name=(s) def name=(s)
details details.name = s
@details.name = s
super super
end end
def ref
Quickbooks::Model::BaseReference.new
end
def set_defaults
self.taxable = true if taxable.nil?
end
# Updates Both local & remote DB sku # Updates Both local & remote DB sku
def sku=(s) def sku=(s)
details details.sku = s
@details.sku = s
super super
end end
# Sync all items, typically triggered by a scheduled task or manual sync request # Updates Both local & remote DB type
def self.sync def type=(s)
ItemSyncJob.perform_later(full_sync: true) details.type = s.to_s
super
end end
# Sync a single items by ID, typically triggered by a webhook notification or manual sync request
def self.sync_by_id(id)
ItemSyncJob.perform_later(id: id)
end
# Push the updates
def save_with_push
log "Starting push for item ##{self.id}..."
qbo = QboConnectionService.current!
ItemService.new(qbo: qbo, item: self).push()
Rails.cache.delete(details_cache_key)
save_without_push
end
alias_method :save_without_push, :save
alias_method :save, :save_with_push
# Updates Both local & remote DB price # Updates Both local & remote DB price
def unit_price=(s) def unit_price=(s)
details details.unit_price = s
@details.unit_price = s
super super
end end
private
def log(msg)
Rails.logger.info "[Item] #{msg}"
end
# Fetches the item's details from QuickBooks Online.
def fetch_details
log "Fetching details for item ##{id} from QBO..."
qbo = QboConnectionService.current!
ItemService.new(qbo: qbo, item: self).pull()
end
end end

View File

@@ -0,0 +1,23 @@
#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

View File

@@ -8,86 +8,13 @@
# #
#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. #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 class ItemService < ServiceBase
# Initializes the service with a QBO client and an optional item record. The QBO client is used to communicate with QuickBooks Online, while the item record contains the data that needs to be pushed to QBO. If no item is provided, the service will not perform any operations.
def initialize(qbo:, item: nil)
raise "No QBO configuration found" unless qbo
raise "Item record is required for push operation" unless item
@qbo = qbo
@item = item
end
def build_qbo_item
log "Building new QBO Item"
account = default_income_account
log "Account: #{account.id} - #{account.name}"
income = Quickbooks::Model::BaseReference.new
income.value = account.id
income.name = account.name
Quickbooks::Model::Item.new(
type: Quickbooks::Model::Item::NON_INVENTORY_TYPE,
income_account_ref: income
)
end
def default_income_account
log "Looking up sales income account"
qbo = QboConnectionService.current!
qbo.perform_authenticated_request do |token|
service = Quickbooks::Service::Account.new(
company_id: qbo.realm_id,
access_token: token
)
service.query("SELECT * FROM Account WHERE AccountType='Income' AND Name LIKE '%Sales%'").first
end
end
# Pulls the Item data from QuickBooks Online.
def pull
return Quickbooks::Model::Item.new unless @item.present?
return build_qbo_item unless @item.id
log "Fetching details for item ##{@item.id} from QBO..."
qbo = QboConnectionService.current!
qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Item.new(
company_id: qbo.realm_id,
access_token: access_token
)
service.fetch_by_id(@item.id)
end
rescue => e
log "Fetch failed for #{@item.id}: #{e.message}"
build_qbo_item
end
# Pushes the Item data to QuickBooks Online. This method handles the communication with QBO, including authentication and error handling. It uses the QBO client to send the item data and logs the process for monitoring and debugging purposes. If the push is successful, it returns the item record; otherwise, it logs the error and returns false.
def push
log "Pushing item ##{@item.id} to QBO..."
item = @qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Item.new(
company_id: @qbo.realm_id,
access_token: access_token
)
if @item.id.present?
service.update(@item.details)
else
service.create(@item.details)
end
end
@item.id = item.id unless @item.persisted?
log "Push for item ##{@item.id} completed."
return @item
end
private private
# Log messages with the entity type for better traceability def build_qbo_remote
def log(msg) log "Building new QBO Item"
Rails.logger.info "[ItemService] #{msg}" Quickbooks::Model::Item.new(type: Account.get_default&.ref)
end end
end end

View File

@@ -22,19 +22,8 @@ class ItemSyncService < SyncServiceBase
20 20
end end
# Map relevant attributes from the QBO Employee to the local Employee model map_attribute :active, :active?
def process_attributes(local, remote) map_attribute :taxable, :taxable?
log "Processing Item ##{remote.id}" map_attributes :description, :id, :name, :sku, :type, :unit_price
local.id = remote.id
local.description = remote.description
local.unit_price = remote.unit_price
local.active = remote.active?
local.name = remote.name
local.sku = remote.sku
end
def log(msg)
Rails.logger.info "[ItemSyncService] #{msg}"
end
end end

View File

@@ -0,0 +1,37 @@
<h2><%= l(:label_accounts) %></h2>
<%= form_tag set_default_accounts_path, method: :patch do %>
<div class="autoscroll">
<table class="list accounts">
<thead>
<tr>
<th style="width:50px;"><%= l(:label_default) %></th>
<th><%= l(:field_name) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_classification) %></th>
<th class="center"><%= l(:field_active) %></th>
</tr>
</thead>
<tbody>
<% @accounts.each do |account| %>
<tr class="<%= cycle("odd", "even") %>">
<td class="center">
<%= radio_button_tag "default_account_id", account.id, account.default %>
</td>
<td class="name"><strong><%= account.name %></strong></td>
<td class="description"><%= truncate(account.description, length: 80) %></td>
<td class="classification"><%= account.classification %></td>
<td class="active center">
<%= checked_image account.active %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<p class="buttons">
<%= submit_tag l(:button_save), class: 'button-small' %>
</p>
<% end %>

View File

@@ -1,43 +1,47 @@
<%= form_with model: @item, local: true do |f| %> <%= labelled_form_for @item do |f| %>
<%= error_messages_for 'item' %>
<% if @item.errors.any? %> <div class="box tabular">
<div id="errorExplanation"> <p>
<h2><%= pluralize(@item.errors.count, "error") %></h2> <%= f.text_field :name, required: true, size: 60 %>
<ul> </p>
<% @item.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p> <p>
<%= f.label :name %><br> <%= f.text_field :sku, size: 30 %>
<%= f.text_field :name, required: true %> </p>
</p>
<p> <p>
<%= f.label :sku %><br> <%= f.text_area :description, rows: 4, class: 'wiki-edit' %>
<%= f.text_field :sku %> </p>
</p>
<p> <p>
<%= f.label :description %><br> <%= f.number_field :unit_price, step: 0.01, size: 10 %>
<%= f.text_area :description, rows: 3 %> </p>
</p>
<p> <p>
<%= f.label :unit_price %><br> <%= f.check_box :taxable %>
<%= f.number_field :unit_price, step: 0.01 %> </p>
</p>
<p> <p>
<%= f.label :active %> <%= f.label :account_id, l(:label_account) %>
<%= f.check_box :active %> <%= f.collection_select :account_id,
</p> Account.where(classification: 'Revenue').order(:name),
:id,
:name,
{ selected: @item.account_id || Account.get_default&.id, include_blank: true } %>
</p>
<p> <p>
<%= f.submit %> <%= f.select :type,
</p> Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] },
{ selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE } %>
</p>
<p>
<%= f.check_box :active %>
</p>
</div>
<%= submit_tag l(:button_save) %>
<%= link_to l(:button_cancel), items_path if controller.action_name == 'edit' %>
<% end %> <% end %>

View File

@@ -1,37 +1,48 @@
<h2>Items</h2>
<div class="contextual"> <div class="contextual">
<%= link_to "New Item", new_item_path, class: "icon icon-add" %> <%= link_to l(:label_item_new), new_item_path, class: 'icon icon-add' %>
</div> </div>
<table class="list items"> <h2><%= l(:label_items) %></h2>
<thead>
<tr>
<th>Name</th>
<th>SKU</th>
<th>Description</th>
<th>Price</th>
<th>Active</th>
<th></th>
</tr>
</thead>
<tbody> <% if @items.any? %>
<% @items.each do |item| %> <div class="autoscroll">
<tr> <table class="list items">
<td><%= link_to item.name, item_path(item) %></td> <thead>
<td><%= item.sku %></td> <tr>
<td><%= item.description %></td> <th><%= l(:field_name) %></th>
<td><%= number_to_currency(item.unit_price) %></td> <th><%= l(:field_sku) %></th>
<td><%= item.active ? "Yes" : "No" %></td> <th><%= l(:field_description) %></th>
<td> <th><%= l(:field_unit_price) %></th>
<%= link_to "Edit", edit_item_path(item), class: "icon icon-edit" %> <th class="center"><%= l(:field_taxable) %></th>
<%= link_to "Delete", item_path(item), <th class="center"><%= l(:field_active) %></th>
method: :delete, <th></th>
data: { confirm: "Are you sure?" }, </tr>
class: "icon icon-del" %> </thead>
</td> <tbody>
</tr> <% @items.each do |item| %>
<% end %> <tr class="<%= cycle("odd", "even") %>">
</tbody> <td class="name"><%= link_to item.name, item_path(item) %></td>
</table> <td class="sku"><%= item.sku %></td>
<td class="description"><%= truncate(item.description, length: 60) %></td>
<td class="unit_price"><%= number_to_currency(item.unit_price) %></td>
<td class="taxable center">
<%= item.taxable ? content_tag(:span, '', class: 'icon icon-ok') : "" %>
</td>
<td class="active center">
<%= checked_image item.active %>
</td>
<td class="buttons">
<%= 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' %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@@ -1,26 +1,44 @@
<h2><%= @item.name %></h2> <div class="contextual">
<%= link_to l(:button_edit), edit_item_path(@item), class: 'icon icon-edit' %>
<%= link_to l(:button_back), items_path, class: 'icon icon-list' %>
</div>
<p> <h2><%= t(:item) %># <%= @item.id %> <%= @item.name %></h2>
<strong>SKU:</strong>
<%= @item.sku %>
</p>
<p> <div class="issue details"> <div class="attributes">
<strong>Description:</strong> <div class="splitcontent">
<%= @item.description %> <div class="splitcontentleft">
</p> <p><strong>SKU:</strong> <%= @item.sku.presence || "-" %></p>
<p><strong>Type:</strong> <%= @item.type.presence || "-" %></p>
<p><strong>Unit Price:</strong> <%= number_to_currency(@item.unit_price) %></p>
</div>
<p> <div class="splitcontentleft">
<strong>Unit Price:</strong> <p><strong>Account:</strong> <%= @item.account&.name || "-" %></p>
<%= number_to_currency(@item.unit_price) %> <p>
</p> <strong>Taxable:</strong>
<% if @item.taxable %>
<span class="icon icon-ok" style="color: green;">Yes</span>
<% else %>
<span class="icon icon-not-ok" style="color: #999;">No</span>
<% end %>
</p>
<p>
<strong>Active:</strong>
<% if @item.active %>
<span class="icon icon-ok" style="color: green;">Yes</span>
<% else %>
<span class="icon icon-not-ok" style="color: #999;">No</span>
<% end %>
</p>
</div>
</div>
<p> <hr />
<strong>Active:</strong>
<%= @item.active ? "Yes" : "No" %>
</p>
<p> <p><strong>Description:</strong></p>
<%= link_to "Edit", edit_item_path(@item), class: "icon icon-edit" %> <div class="wiki" style="padding-left: 20px;">
<%= link_to "Back", items_path %> <%= @item.description.presence || "<em>No description provided</em>".html_safe %>
</p> </div>
</div>
</div>

View File

@@ -1,6 +1,39 @@
<div> <div class="box tabular">
<b><%=t(:label_item_count)%></b> <%= Item.count %> @ <%= Item.last_sync %> <p>
<br/> <label><strong><%= t(:label_item_count) %></strong></label>
<%=t(:label_last_sync)%> </b> <%= Qbo.last_sync if Qbo.exists? %> <%= Item.count %>
<em style="color: #777; font-size: 0.9em; margin-left: 8px;">
(@ <%= Item.last_sync %>)
</em>
</p>
<p>
<label><strong><%= t(:label_account_count) %></strong></label>
<%= Account.count %>
<em style="color: #777; font-size: 0.9em; margin-left: 8px;">
(@ <%= Account.last_sync %>)
</em>
</p>
<p>
<label><strong><%= t(:label_last_sync) %> (QBO)</strong></label>
<%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %>
</p>
<p>
<label><strong><%= t(:label_default_account) %></strong></label>
<%= Account.get_default %>
</p>
</div> </div>
<%= link_to t(:label_sync_now), sync_items_path %>
<fieldset class="box">
<legend>Management & Synchronization</legend>
<div style="margin-bottom: 15px;">
<%= 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' %>
</div>
<div>
<%= link_to t(:label_items), items_path, class: 'icon icon-list' %>
<span style="margin: 0 10px; color: #ccc;">|</span>
<%= link_to t(:label_accounts), accounts_path, class: 'icon icon-list' %>
</div>
</fieldset>

View File

@@ -11,13 +11,26 @@
# English strings go here for Rails i18n # English strings go here for Rails i18n
# Usage I18n.t(:label) # Usage I18n.t(:label)
en: en:
field_classification: "Classification"
field_sku: "SKU"
field_taxable: "Taxable"
field_unit_price: "Unit Price"
label_account: "Account"
label_accounts: "Accounts"
label_account_count: "Number of Accounts:"
label_default_account: "Default Item Income Account"
label_description: "Description" label_description: "Description"
label_item: "Item" label_item: "Item"
label_item_count: "Item Count:" label_item_count: "Item Count:"
label_items: "Items"
label_line_items: "Line Items" label_line_items: "Line Items"
label_price: "Unit Price" label_price: "Unit Price"
label_qty: "Quantity" label_qty: "Quantity"
label_remove: "Remove" label_remove: "Remove"
label_sync_now_accounts: "Sync Accounts"
label_sync_now_items: "Sync Items"
label_total: "Total" label_total: "Total"
notice_added_from: "Added from issue #" notice_added_from: "Added from issue #"

View File

@@ -14,3 +14,10 @@ resources :items do
get :sync get :sync
end end
end end
resources :accounts do
collection do
patch :set_default
get :sync
end
end

View File

@@ -0,0 +1,26 @@
#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

View File

@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
name 'Redmine QBO Line Items plugin' name 'Redmine QBO Line Items plugin'
author 'Rick Barrette' author 'Rick Barrette'
description 'A plugin for Redmine to extend the capabilitys of the Redmine QuickBooks Online plugin to attach billable line items to an isuue' description 'A plugin for Redmine to extend the capabilitys of the Redmine QuickBooks Online plugin to attach billable line items to an isuue'
version '2026.3.6' version '2026.3.9'
url 'https://github.com/rickbarrette/redmine_qbo_lineitems' url 'https://github.com/rickbarrette/redmine_qbo_lineitems'
author_url 'https://barrettefabrication.com' author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '6.1.0' requires_redmine version_or_higher: '6.1.0'
@@ -22,7 +22,7 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
# Ensure redmine_qbo is installed # Ensure redmine_qbo is installed
begin begin
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.5' requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.9'
rescue Redmine::PluginNotFound rescue Redmine::PluginNotFound
raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)' raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)'
end end

View File

@@ -16,13 +16,13 @@ module RedmineQboLineItems
# Called by WebhookProcessJob # Called by WebhookProcessJob
def qbo_additional_entities(context={}) def qbo_additional_entities(context={})
log "Added QBO Item to allowed webook entities" log "Added QBO Item to allowed webook entities"
return "Item" return ["Item", "Account"]
end end
# Called by the QboSyncDispatcher # Called by the QboSyncDispatcher
def qbo_full_sync (context={}) def qbo_full_sync (context={})
log "Adding ItemSyncJob to QBO sync dispatcher" log "Adding Item to QBO sync dispatcher"
return ItemSyncJob return [Item, Account]
end end
private private