mirror of
https://github.com/rickbarrette/redmine_qbo_lineitems.git
synced 2026-04-03 15:41:58 -04:00
Compare commits
3 Commits
50a02cc497
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b939d834e9 | |||
| 9b9a5c3505 | |||
| da49b996da |
@@ -100,8 +100,6 @@ class ItemsController < ApplicationController
|
|||||||
params.require(:item).permit(:name, :description, :sku, :unit_price, :active, :account_id, :type, :taxable)
|
params.require(:item).permit(:name, :description, :sku, :unit_price, :active, :account_id, :type, :taxable)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def log(msg)
|
def log(msg)
|
||||||
Rails.logger.info "[ItemsController] #{msg}"
|
Rails.logger.info "[ItemsController] #{msg}"
|
||||||
end
|
end
|
||||||
|
|||||||
2
init.rb
2
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.12'
|
version '2026.4.0'
|
||||||
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'
|
||||||
|
|||||||
@@ -10,14 +10,41 @@
|
|||||||
|
|
||||||
module LineItems
|
module LineItems
|
||||||
module Patches
|
module Patches
|
||||||
module IssuePatch
|
module IssuePatch extend ActiveSupport::Concern
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
prepended do
|
prepended 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, reject_if: proc { |attrs| attrs['description'].blank? }
|
||||||
allow_destroy: true,
|
|
||||||
reject_if: proc { |attrs| attrs['description'].blank? }
|
def line_items_attributes=(attrs)
|
||||||
|
attrs = attrs.stringify_keys
|
||||||
|
|
||||||
|
# IDs submitted in the form
|
||||||
|
submitted_ids = attrs.values.map { |a| a['id'] }.compact.map(&:to_s)
|
||||||
|
|
||||||
|
# Existing IDs in DB
|
||||||
|
existing_ids = line_items.pluck(:id).map(&:to_s)
|
||||||
|
|
||||||
|
# Find missing ones (these would be implicitly deleted by Rails)
|
||||||
|
missing_ids = existing_ids - submitted_ids
|
||||||
|
|
||||||
|
# Re-add missing records so Rails doesn't delete them
|
||||||
|
missing_ids.each do |id|
|
||||||
|
attrs["preserve_#{id}"] = { 'id' => id }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Only allow explicit deletes or valid updates/creates
|
||||||
|
filtered = attrs.select do |_, item_attrs|
|
||||||
|
item_attrs['_destroy'] == '1' ||
|
||||||
|
item_attrs['id'].present? ||
|
||||||
|
item_attrs['description'].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
super(filtered)
|
||||||
|
rescue => e
|
||||||
|
logger.error "Error processing line items attributes: #{e.message}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user