mirror of
https://github.com/rickbarrette/redmine_qbo_lineitems.git
synced 2026-04-02 15:11:58 -04:00
Compare commits
31 Commits
60a7f769ce
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| da49b996da | |||
| 50a02cc497 | |||
| b63e8f2a45 | |||
| 4b561ef4e3 | |||
| 1dadcf37b6 | |||
| ffaee10fef | |||
| 58994e3c7d | |||
| 6365fe6679 | |||
| 4d6c16373a | |||
| 20b7564c38 | |||
| 9820646857 | |||
| 647ce4c63a | |||
| 4367c77393 | |||
| 8c0ce8ce48 | |||
| 9fd1f4fb7d | |||
| cca822c570 | |||
| 795906b4f5 | |||
| d5e59c120c | |||
| e640e61648 | |||
| c968893f94 | |||
| 26f84bd221 | |||
| f59849e6e5 | |||
| 6bf5575f9c | |||
| 2703d6cc3e | |||
| 24e3e4ba82 | |||
| f81fe0ef87 | |||
| a2cc7a97fd | |||
| 7088550184 | |||
| 2302679c3a | |||
| ec1ef72267 | |||
| 564158722d |
@@ -10,8 +10,6 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
|
|||||||
|
|
||||||
* **Redmine:** 6.1+
|
* **Redmine:** 6.1+
|
||||||
|
|
||||||
* **Ruby:** 3.2+
|
|
||||||
|
|
||||||
* **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) (must be installed and configured)
|
* **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) (must be installed and configured)
|
||||||
|
|
||||||
|
|
||||||
@@ -19,9 +17,9 @@ This plugin allows **billable line items** to be attached to a Redmine issue. Wh
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
| Plugin Version | Redmine Version | Ruby Version |
|
| Plugin Version | Redmine Version | Parent Plugin Version |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 2026.3.6+ | 6.1.x | 3.2+ |
|
| 2026.3.8+ | 6.1.x | 2026.3.9+ |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -88,8 +86,9 @@ Before using this plugin:
|
|||||||
|
|
||||||
2. Ensure your **QuickBooks Online** company file is connected.
|
2. Ensure your **QuickBooks Online** company file is connected.
|
||||||
|
|
||||||
3. Verify that the products or services referenced in line items exist in QuickBooks.
|
3. Sync Accounts & Items via plugin settings
|
||||||
|
|
||||||
|
4. Set default income account for new items via plugin settings
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
BIN
Screenshots/accounts.png
Normal file
BIN
Screenshots/accounts.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 287 KiB |
BIN
Screenshots/edit item.png
Normal file
BIN
Screenshots/edit item.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
BIN
Screenshots/item.png
Normal file
BIN
Screenshots/item.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 162 KiB |
BIN
Screenshots/items.png
Normal file
BIN
Screenshots/items.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 368 KiB |
BIN
Screenshots/settings.png
Normal file
BIN
Screenshots/settings.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 166 KiB |
27
app/controllers/accounts_controller.rb
Normal file
27
app/controllers/accounts_controller.rb
Normal 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
|
||||||
@@ -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,6 +55,10 @@ 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
|
||||||
@@ -49,6 +67,7 @@ class ItemsController < ApplicationController
|
|||||||
|
|
||||||
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,18 @@ 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
|
||||||
|
|
||||||
|
def log(msg)
|
||||||
|
Rails.logger.info "[ItemsController] #{msg}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -46,7 +46,9 @@ class BillLineItemsJob < ActiveJob::Base
|
|||||||
|
|
||||||
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,8 +58,11 @@ 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
|
||||||
|
# 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")
|
detail.tax_code_ref = Quickbooks::Model::BaseReference.new("TAX")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
estimate.line_items << line
|
estimate.line_items << line
|
||||||
end
|
end
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
|
||||||
|
|
||||||
log "Starting #{full_sync ? 'full' : 'incremental'} sync for item ##{id || 'all'}..."
|
|
||||||
|
|
||||||
service = ItemSyncService.new(qbo: qbo)
|
|
||||||
|
|
||||||
if id.present?
|
|
||||||
service.sync_by_id(id)
|
|
||||||
else
|
|
||||||
service.sync(full_sync: full_sync)
|
|
||||||
end
|
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
|
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
|
||||||
@@ -10,37 +10,62 @@
|
|||||||
|
|
||||||
class Item < QboBaseModel
|
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
|
qbo_sync push: true
|
||||||
|
after_initialize :set_defaults, if: :new_record?
|
||||||
|
before_destroy :make_inactive
|
||||||
|
|
||||||
|
# Updates Both local & remote DB account ref
|
||||||
|
def account_id=(id)
|
||||||
|
details.income_account_ref = Account.find(id).ref
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
# Updates Both local & remote DB description
|
# Updates Both local & remote DB description
|
||||||
def description=(s)
|
def description=(s)
|
||||||
details
|
details.description = s
|
||||||
@details.description = s
|
|
||||||
super
|
super
|
||||||
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 make_inactive
|
||||||
|
details.active = false
|
||||||
|
push_to_qbo
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
# Updates Both local & remote DB type
|
||||||
|
def type=(s)
|
||||||
|
details.type = s.to_s
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
|
|||||||
23
app/services/account_sync_service.rb
Normal file
23
app/services/account_sync_service.rb
Normal 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
|
||||||
@@ -14,28 +14,7 @@ class ItemService < ServiceBase
|
|||||||
|
|
||||||
def build_qbo_remote
|
def build_qbo_remote
|
||||||
log "Building new QBO Item"
|
log "Building new QBO Item"
|
||||||
account = default_income_account
|
Quickbooks::Model::Item.new(type: Account.get_default&.ref)
|
||||||
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
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -23,6 +23,10 @@ class ItemSyncService < SyncServiceBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
map_attribute :active, :active?
|
map_attribute :active, :active?
|
||||||
map_attributes :description, :id, :name, :sku, :unit_price
|
map_attribute :taxable, :taxable?
|
||||||
|
map_attribute :account do |remote|
|
||||||
|
Account.find remote.income_account_ref.value.to_i
|
||||||
|
end
|
||||||
|
map_attributes :description, :id, :name, :sku, :type, :unit_price
|
||||||
|
|
||||||
end
|
end
|
||||||
37
app/views/accounts/index.html.erb
Normal file
37
app/views/accounts/index.html.erb
Normal 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 %>
|
||||||
@@ -1,43 +1,50 @@
|
|||||||
<%= form_with model: @item, local: true do |f| %>
|
<%= labelled_form_for @item do |f| %>
|
||||||
|
<%= error_messages_for 'item' %>
|
||||||
<% if @item.errors.any? %>
|
|
||||||
<div id="errorExplanation">
|
|
||||||
<h2><%= pluralize(@item.errors.count, "error") %></h2>
|
|
||||||
<ul>
|
|
||||||
<% @item.errors.full_messages.each do |msg| %>
|
|
||||||
<li><%= msg %></li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
|
<div class="box tabular">
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :name %><br>
|
<%= f.text_field :name, required: true, size: 60 %>
|
||||||
<%= f.text_field :name, required: true %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :sku %><br>
|
<%= f.text_field :sku, size: 30 %>
|
||||||
<%= f.text_field :sku %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :description %><br>
|
<%= f.text_area :description, rows: 4, class: 'wiki-edit' %>
|
||||||
<%= f.text_area :description, rows: 3 %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :unit_price %><br>
|
<%= f.text_field :unit_price,
|
||||||
<%= f.number_field :unit_price, step: 0.01 %>
|
class: "price-field",
|
||||||
|
inputmode: "decimal",
|
||||||
|
autocomplete: "off"%>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.check_box :taxable %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= 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 } %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.select :type,
|
||||||
|
Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] },
|
||||||
|
{ selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE } %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :active %>
|
|
||||||
<%= f.check_box :active %>
|
<%= f.check_box :active %>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
<%= submit_tag l(:button_save) %>
|
||||||
<%= f.submit %>
|
<%= link_to l(:button_cancel), items_path if controller.action_name == 'edit' %>
|
||||||
</p>
|
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
<h2>Edit Item</h2>
|
<h2><%=t(:label_edit_item)%></h2>
|
||||||
|
|
||||||
<%= render "form" %>
|
<%= render "form" %>
|
||||||
|
|
||||||
<%= link_to "Back", items_path %>
|
|
||||||
@@ -1,37 +1,56 @@
|
|||||||
<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>
|
||||||
|
|
||||||
|
<% if @items.any? %>
|
||||||
|
<div class="autoscroll">
|
||||||
|
<table class="list items">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th><%= l(:field_name) %></th>
|
||||||
<th>SKU</th>
|
<th><%= l(:field_sku) %></th>
|
||||||
<th>Description</th>
|
<th><%= l(:field_description) %></th>
|
||||||
<th>Price</th>
|
<th><%= l(:field_unit_price) %></th>
|
||||||
<th>Active</th>
|
<th class="center"><%= l(:field_taxable) %></th>
|
||||||
|
<th class="center"><%= l(:field_active) %></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @items.each do |item| %>
|
<% @items.each do |item| %>
|
||||||
<tr>
|
<tr class="<%= cycle("odd", "even") %>">
|
||||||
<td><%= link_to item.name, item_path(item) %></td>
|
<td class="name"><%= link_to item.name, item_path(item) %></td>
|
||||||
<td><%= item.sku %></td>
|
<td class="sku"><%= item.sku %></td>
|
||||||
<td><%= item.description %></td>
|
<td class="description"><%= truncate(item.description, length: 60) %></td>
|
||||||
<td><%= number_to_currency(item.unit_price) %></td>
|
<td class="unit_price"><%= number_to_currency(item.unit_price) %></td>
|
||||||
<td><%= item.active ? "Yes" : "No" %></td>
|
<td class="taxable center">
|
||||||
<td>
|
<% if item.taxable %>
|
||||||
<%= link_to "Edit", edit_item_path(item), class: "icon icon-edit" %>
|
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||||
<%= link_to "Delete", item_path(item),
|
<% else %>
|
||||||
|
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td class="active center">
|
||||||
|
<% if item.active %>
|
||||||
|
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||||
|
<% else %>
|
||||||
|
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||||
|
<% end %>
|
||||||
|
</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,
|
method: :delete,
|
||||||
data: { confirm: "Are you sure?" },
|
data: { confirm: l(:text_are_you_sure) },
|
||||||
class: "icon icon-del" %>
|
class: 'icon icon-del' %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||||
|
<% end %>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<h2>New Item</h2>
|
<h2><%=t(:label_item_new)%></h2>
|
||||||
|
|
||||||
<%= render "form" %>
|
<%= render "form" %>
|
||||||
|
|
||||||
<%= link_to "Back", items_path %>
|
<%= link_to t(:label_back), items_path %>
|
||||||
@@ -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><%=t(:field_sku)%>:</strong> <%= @item.sku.presence || "-" %></p>
|
||||||
|
<p><strong><%=t(:label_type)%>:</strong> <%= @item.type.presence || "-" %></p>
|
||||||
|
<p><strong><%=t(:field_unit_price)%>:</strong> <%= number_to_currency(@item.unit_price) %></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
<div class="splitcontentleft">
|
||||||
<strong>Unit Price:</strong>
|
<p><strong><%=t(:label_account)%>:</strong> <%= @item.account&.name || "-" %></p>
|
||||||
<%= number_to_currency(@item.unit_price) %>
|
<p>
|
||||||
</p>
|
<strong><%=t(:field_taxable)%>:</strong>
|
||||||
|
<% if @item.taxable %>
|
||||||
|
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||||
|
<% else %>
|
||||||
|
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong><%=t(:label_active)%>:</strong>
|
||||||
|
<% if @item.active %>
|
||||||
|
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||||
|
<% else %>
|
||||||
|
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
<hr />
|
||||||
<strong>Active:</strong>
|
|
||||||
<%= @item.active ? "Yes" : "No" %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p><strong><%=t(:label_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>
|
||||||
@@ -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>
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
let lastKeyWasTab = false;
|
||||||
|
|
||||||
|
document.addEventListener("keydown", function (e) {
|
||||||
|
lastKeyWasTab = (e.key === "Tab");
|
||||||
|
});
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
function initNestedForms() {
|
function initNestedForms() {
|
||||||
document.querySelectorAll("[data-nested-form]").forEach(function (wrapper) {
|
document.querySelectorAll("[data-nested-form]").forEach(function (wrapper) {
|
||||||
@@ -22,11 +28,28 @@
|
|||||||
Date.now().toString()
|
Date.now().toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
//container.insertAdjacentHTML("beforeend", content);
|
|
||||||
container.insertAdjacentHTML("beforeend", content);
|
container.insertAdjacentHTML("beforeend", content);
|
||||||
|
|
||||||
// initialize autocomplete on the new row
|
const newRow = container.lastElementChild;
|
||||||
initLineItemAutocomplete(container.lastElementChild);
|
|
||||||
|
// Ensure clean state
|
||||||
|
newRow.dataset.autoAdded = "false";
|
||||||
|
|
||||||
|
// Reset defaults
|
||||||
|
const qty = newRow.querySelector(".qty-field");
|
||||||
|
if (qty && !qty.value) qty.value = 1;
|
||||||
|
|
||||||
|
const price = newRow.querySelector(".price-field");
|
||||||
|
if (price) price.value = "";
|
||||||
|
|
||||||
|
// initialize autocomplete
|
||||||
|
initLineItemAutocomplete(newRow);
|
||||||
|
|
||||||
|
// Only focus if NOT tabbing
|
||||||
|
if (!lastKeyWasTab) {
|
||||||
|
const desc = newRow.querySelector(".line-item-description");
|
||||||
|
if (desc) desc.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// REMOVE
|
// REMOVE
|
||||||
@@ -56,9 +79,77 @@
|
|||||||
document.addEventListener("turbo:load", initNestedForms);
|
document.addEventListener("turbo:load", initNestedForms);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
$(document).on("input", ".line-item-description", function(){
|
|
||||||
|
|
||||||
|
// Keep your existing behavior
|
||||||
|
$(document).on("input", ".line-item-description", function () {
|
||||||
let row = $(this).closest(".line-item");
|
let row = $(this).closest(".line-item");
|
||||||
row.find(".item-id-field").val("");
|
row.find(".item-id-field").val("");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// AUTO-ADD NEW ROW LOGIC
|
||||||
|
// -------------------------------
|
||||||
|
|
||||||
|
// Reset autoAdded flag if cleared
|
||||||
|
document.addEventListener("input", function (e) {
|
||||||
|
if (!e.target.classList.contains("line-item-description")) return;
|
||||||
|
|
||||||
|
const row = e.target.closest(".line-item");
|
||||||
|
if (!row) return;
|
||||||
|
|
||||||
|
if (e.target.value.trim() === "") {
|
||||||
|
row.dataset.autoAdded = "false";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Add row when leaving last description (without breaking TAB flow)
|
||||||
|
document.addEventListener("blur", function (e) {
|
||||||
|
if (!e.target.classList.contains("line-item-description")) return;
|
||||||
|
|
||||||
|
const input = e.target;
|
||||||
|
const row = input.closest(".line-item");
|
||||||
|
if (!row) return;
|
||||||
|
|
||||||
|
const wrapper = input.closest("[data-nested-form]");
|
||||||
|
if (!wrapper) return;
|
||||||
|
|
||||||
|
const container = wrapper.querySelector("[data-nested-form-container]");
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
// Active (visible + not destroyed) rows only
|
||||||
|
const rows = Array.from(
|
||||||
|
container.querySelectorAll(wrapper.dataset.wrapperSelector)
|
||||||
|
).filter(r => {
|
||||||
|
const destroy = r.querySelector("input[name*='[_destroy]']");
|
||||||
|
const hidden = window.getComputedStyle(r).display === "none";
|
||||||
|
return !(destroy && destroy.value === "1") && !hidden;
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastRow = rows[rows.length - 1];
|
||||||
|
|
||||||
|
// Only last row
|
||||||
|
if (row !== lastRow) return;
|
||||||
|
|
||||||
|
// Must have content
|
||||||
|
if (input.value.trim() === "") return;
|
||||||
|
|
||||||
|
// Prevent duplicate firing
|
||||||
|
if (row.dataset.autoAdded === "true") return;
|
||||||
|
|
||||||
|
// If TAB, ensure user is leaving the row entirely
|
||||||
|
if (lastKeyWasTab) {
|
||||||
|
const next = document.activeElement;
|
||||||
|
|
||||||
|
if (row.contains(next)) {
|
||||||
|
return; // still inside row → allow normal tabbing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
row.dataset.autoAdded = "true";
|
||||||
|
|
||||||
|
const addButton = wrapper.querySelector("[data-nested-form-add]");
|
||||||
|
if (addButton) addButton.click();
|
||||||
|
|
||||||
|
}, true); // capture phase required for blur
|
||||||
@@ -11,13 +11,33 @@
|
|||||||
# 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_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_description: "Description"
|
||||||
|
label_edit_item: "Edit Item"
|
||||||
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_item_new: "New Item"
|
||||||
|
label_no: "No"
|
||||||
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_type: "Type"
|
||||||
label_total: "Total"
|
label_total: "Total"
|
||||||
|
label_yes: "Yes"
|
||||||
|
|
||||||
notice_added_from: "Added from issue #"
|
notice_added_from: "Added from issue #"
|
||||||
|
|
||||||
@@ -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
|
||||||
26
db/migrate/004_create_accounts.rb
Normal file
26
db/migrate/004_create_accounts.rb
Normal 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
|
||||||
18
init.rb
18
init.rb
@@ -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.8'
|
version '2026.3.12'
|
||||||
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.7'
|
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
|
||||||
@@ -31,10 +31,12 @@ Redmine::Plugin.register :redmine_qbo_lineitems do
|
|||||||
Issue.safe_attributes :line_items_attributes
|
Issue.safe_attributes :line_items_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dynamically load all Hooks & Patches recursively
|
# Administration menu extension
|
||||||
base_dir = File.join(File.dirname(__FILE__), 'lib')
|
Redmine::MenuManager.map :admin_menu do |menu|
|
||||||
|
menu.push :redmine_qbo_lineitems, { controller: 'items', action: 'index' },
|
||||||
# '**' looks inside subdirectories, '*.rb' matches Ruby files
|
icon: 'list',
|
||||||
Dir.glob(File.join(base_dir, '**', '*.rb')).sort.each do |file|
|
caption: :label_items,
|
||||||
require file
|
html: { class: 'icon icon-list' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RedmineQboLineItems.setup
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
#
|
#
|
||||||
#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.
|
||||||
|
|
||||||
module RedmineQboLineItems
|
module LineItems
|
||||||
module Hooks
|
module Hooks
|
||||||
|
|
||||||
class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
class IssuesSaveHookListener < Redmine::Hook::Listener
|
||||||
|
|
||||||
# Called After Issue Saved
|
# Called After Issue Saved
|
||||||
def controller_issues_edit_after_save(context={})
|
def controller_issues_edit_after_save(context={})
|
||||||
@@ -8,21 +8,21 @@
|
|||||||
#
|
#
|
||||||
#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.
|
||||||
|
|
||||||
module RedmineQboLineItems
|
module LineItems
|
||||||
module Hooks
|
module Hooks
|
||||||
|
|
||||||
class QboHookListener < Redmine::Hook::ViewListener
|
class QboHookListener < Redmine::Hook::Listener
|
||||||
|
|
||||||
# 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
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#
|
#
|
||||||
#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.
|
||||||
|
|
||||||
module RedmineQboLineItems
|
module LineItems
|
||||||
module Hooks
|
module Hooks
|
||||||
|
|
||||||
class ViewHookListener < Redmine::Hook::ViewListener
|
class ViewHookListener < Redmine::Hook::ViewListener
|
||||||
@@ -25,6 +25,7 @@ module RedmineQboLineItems
|
|||||||
end
|
end
|
||||||
|
|
||||||
def view_issues_edit_notes_bottom(context = {})
|
def view_issues_edit_notes_bottom(context = {})
|
||||||
|
return if context[:issue].closed?
|
||||||
context[:controller].send(:render_to_string, {
|
context[:controller].send(:render_to_string, {
|
||||||
partial: 'line_items/issue_form',
|
partial: 'line_items/issue_form',
|
||||||
locals: {
|
locals: {
|
||||||
@@ -8,35 +8,17 @@
|
|||||||
#
|
#
|
||||||
#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.
|
||||||
|
|
||||||
require_dependency 'issue'
|
module LineItems
|
||||||
|
|
||||||
module RedmineQboLineItems
|
|
||||||
module Patches
|
module Patches
|
||||||
module IssuePatch
|
module IssuePatch
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def self.included(base)
|
prepended do
|
||||||
base.extend(ClassMethods)
|
|
||||||
base.send(:include, InstanceMethods)
|
|
||||||
|
|
||||||
base.class_eval do
|
|
||||||
has_many :line_items, dependent: :destroy
|
has_many :line_items, dependent: :destroy
|
||||||
accepts_nested_attributes_for :line_items,
|
accepts_nested_attributes_for :line_items,
|
||||||
allow_destroy: true,
|
allow_destroy: true,
|
||||||
reject_if: proc { |attrs| attrs['description'].blank? }
|
reject_if: proc { |attrs| attrs['description'].blank? }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
Issue.send(:include, IssuePatch)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
21
lib/redmine_qbo_line_items.rb
Normal file
21
lib/redmine_qbo_line_items.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#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 RedmineQboLineItems
|
||||||
|
|
||||||
|
def self.setup
|
||||||
|
unless Issue.ancestors.include?(LineItems::Patches::IssuePatch)
|
||||||
|
Issue.prepend LineItems::Patches::IssuePatch
|
||||||
|
LineItems::Hooks::IssuesSaveHookListener
|
||||||
|
LineItems::Hooks::QboHookListener
|
||||||
|
LineItems::Hooks::ViewHookListener
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user