mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-04-02 08:21:57 -04:00
Compare commits
4 Commits
2026.3.16
...
61b02831e3
| Author | SHA1 | Date | |
|---|---|---|---|
| 61b02831e3 | |||
| 7c79f2388a | |||
| 36267893bd | |||
| e681203a45 |
12
README.md
12
README.md
@@ -89,17 +89,6 @@ Supported automation:
|
|||||||
|
|
||||||
Invoices containing an Issue reference (e.g. `#123`) automatically attach to the corresponding Issue.
|
Invoices containing an Issue reference (e.g. `#123`) automatically attach to the corresponding Issue.
|
||||||
|
|
||||||
### Custom Field Synchronization
|
|
||||||
|
|
||||||
Invoice custom fields can be mapped to Issue custom fields.
|
|
||||||
|
|
||||||
Example use case:
|
|
||||||
|
|
||||||
* Mileage In/Out recorded in Redmine
|
|
||||||
|
|
||||||
* Automatically synchronized to the QuickBooks invoice.
|
|
||||||
|
|
||||||
|
|
||||||
### Customer Synchronization
|
### Customer Synchronization
|
||||||
|
|
||||||
Customer records are automatically updated in the local database when changes occur in QuickBooks.
|
Customer records are automatically updated in the local database when changes occur in QuickBooks.
|
||||||
@@ -121,7 +110,6 @@ Available hooks:
|
|||||||
|--|--|--|
|
|--|--|--|
|
||||||
View Hook|:pdf_left, { issue: issue } | Used to add text to left side of PDF
|
View Hook|:pdf_left, { issue: issue } | Used to add text to left side of PDF
|
||||||
View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF
|
View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF
|
||||||
Hook|process_invoice_custom_fields, { issue: issue, invoice: invoice } | Used to process invoice custom fields
|
|
||||||
View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view
|
View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view
|
||||||
Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob
|
Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob
|
||||||
Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher
|
Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ class InvoiceAttachmentService
|
|||||||
issue.save! if issue.changed?
|
issue.save! if issue.changed?
|
||||||
log "Attached invoice ##{@invoice.id} to issue ##{issue.id}"
|
log "Attached invoice ##{@invoice.id} to issue ##{issue.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
InvoiceCustomFieldSyncService.new(issue, @invoice, @remote).sync
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
#The MIT License (MIT)
|
|
||||||
#
|
|
||||||
#Copyright (c) 2016 - 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 InvoiceCustomFieldSyncService
|
|
||||||
|
|
||||||
def initialize(issue, invoice, remote)
|
|
||||||
@issue = issue
|
|
||||||
@invoice = invoice
|
|
||||||
@remote = remote
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sync custom fields on the issue based on the invoice data, then push changes to QBO if any fields were updated
|
|
||||||
def sync
|
|
||||||
return if @invoice.qbo_sync_locked?
|
|
||||||
|
|
||||||
log "Syncing custom fields for issue ##{@issue.id} based on invoice ##{@invoice.doc_number}"
|
|
||||||
|
|
||||||
changed = false
|
|
||||||
|
|
||||||
# Process Invoice Custom Fields via Hooks
|
|
||||||
Redmine::Hook.call_hook(
|
|
||||||
:process_invoice_custom_fields,
|
|
||||||
issue: @issue,
|
|
||||||
invoice: @remote
|
|
||||||
).each do |context|
|
|
||||||
next unless context
|
|
||||||
changed ||= context[:is_changed]
|
|
||||||
log "Custom fields updated by hook, marking invoice for push to QBO" if context[:is_changed]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Process Issue Custom Values from any issue custom fields that match the invoice custom fields
|
|
||||||
begin
|
|
||||||
value = @issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
|
||||||
|
|
||||||
# Check to see if the value is blank...
|
|
||||||
if not value.value.to_s.blank?
|
|
||||||
# Check to see if the value is diffrent
|
|
||||||
if not cf.string_value.to_s.eql? value.value.to_s
|
|
||||||
# update the custom field on the invoice
|
|
||||||
cf.string_value = value.value.to_s
|
|
||||||
is_changed = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
# Nothing to do here, there is no match
|
|
||||||
end
|
|
||||||
|
|
||||||
push_if_changed if changed
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# If any custom fields were changed during the sync process, this method will trigger a push of the invoice data to QuickBooks Online to ensure that the remote data stays in sync with the local changes. It uses the InvoicePushService to handle the actual communication with QBO.
|
|
||||||
def push_if_changed
|
|
||||||
InvoicePushService.new(@invoice).push
|
|
||||||
end
|
|
||||||
|
|
||||||
def log(msg)
|
|
||||||
Rails.logger.info "[InvoiceCustomFieldSyncService] #{msg}"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#The MIT License (MIT)
|
|
||||||
#
|
|
||||||
#Copyright (c) 2016 - 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 InvoicePushService
|
|
||||||
|
|
||||||
def initialize(invoice)
|
|
||||||
@invoice = invoice
|
|
||||||
end
|
|
||||||
|
|
||||||
# Push invoice changes to QBO if the invoice is linked to any issues with custom field changes that need to be synced
|
|
||||||
def push
|
|
||||||
return if @invoice.qbo_sync_locked?
|
|
||||||
log "Pushing invoice ##{@invoice.id} to QBO due to linked issue custom field changes"
|
|
||||||
@invoice.update_column(:qbo_sync_locked, true)
|
|
||||||
remote = QboConnectionService.with_qbo_service(entity: Invoice) do |service|
|
|
||||||
remote = service.fetch_by_id(@invoice.id)
|
|
||||||
# modify remote object here if needed
|
|
||||||
service.update(remote)
|
|
||||||
end
|
|
||||||
rescue => e
|
|
||||||
Rails.logger.error "[InvoicePushService] #{e.message}"
|
|
||||||
ensure
|
|
||||||
@invoice.update_column(:qbo_sync_locked, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def log(msg)
|
|
||||||
Rails.logger.info "[InvoicePushService] #{msg}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
2
init.rb
2
init.rb
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
name 'Redmine QBO plugin'
|
name 'Redmine QBO plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
||||||
version '2026.3.16'
|
version '2026.3.17'
|
||||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||||
author_url 'https://barrettefabrication.com'
|
author_url 'https://barrettefabrication.com'
|
||||||
settings default: {empty: true}, partial: 'qbo/settings'
|
settings default: {empty: true}, partial: 'qbo/settings'
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ module RedmineQbo
|
|||||||
|
|
||||||
# View User
|
# View User
|
||||||
def view_users_form(context={})
|
def view_users_form(context={})
|
||||||
|
|
||||||
# Update the users
|
|
||||||
#Employee.update_all
|
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
# Check to see if there is a quickbooks user attached to the issue
|
||||||
@selected = context[:user]&.employee&.id
|
@selected = context[:user]&.employee&.id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user