mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-02-13 09:13:58 -05:00
Compare commits
13 Commits
4ae9374401
...
2026.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c49ec6890 | |||
| ef7faee685 | |||
| 02b48d2de4 | |||
| e670d99766 | |||
| 241dd594d0 | |||
| b603cb634a | |||
| 1308a05011 | |||
| 334ed60bf7 | |||
| d63bf809f2 | |||
| 31406af681 | |||
| 479be461a6 | |||
| c1af031d22 | |||
| a741cd0217 |
@@ -112,15 +112,15 @@ class Invoice < ActiveRecord::Base
|
|||||||
logger.debug "Calling :process_invoice_custom_fields hook"
|
logger.debug "Calling :process_invoice_custom_fields hook"
|
||||||
context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice }
|
context = Redmine::Hook.call_hook :process_invoice_custom_fields, { issue: issue, invoice: invoice }
|
||||||
|
|
||||||
unless context.nil?
|
# Process updates from the hooks
|
||||||
logger.debug "We have a context!"
|
context.each do |c|
|
||||||
context= context.first
|
unless c.nil?
|
||||||
issue = context[:issue]
|
logger.debug "Invoice.compare_custom_fields: We have a responce from a hook"
|
||||||
invoice = context[:invoice]
|
push_updates c[:invoice] if c[:is_changed]
|
||||||
is_changed = context[:is_changed]
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom Values
|
# Process Issue Custom Values
|
||||||
begin
|
begin
|
||||||
value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
value = issue.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
||||||
|
|
||||||
@@ -137,13 +137,17 @@ class Invoice < ActiveRecord::Base
|
|||||||
# Nothing to do here, there is no match
|
# Nothing to do here, there is no match
|
||||||
end
|
end
|
||||||
|
|
||||||
# Push updates
|
push_updates invoice if is_changed
|
||||||
|
end
|
||||||
|
|
||||||
|
# pushes invoice updates
|
||||||
|
def self.push_updates(invoice)
|
||||||
begin
|
begin
|
||||||
logger.info "Trying to update invoice"
|
logger.info "Invoice.push_updates"
|
||||||
qbo = Qbo.first
|
qbo = Qbo.first
|
||||||
qbo.perform_authenticated_request do |access_token|
|
qbo.perform_authenticated_request do |access_token|
|
||||||
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
|
||||||
service.update(invoice) if is_changed
|
service.update invoice
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
# Do nothing, probaly custome field sync confict on the invoice.
|
# Do nothing, probaly custome field sync confict on the invoice.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://app.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2>
|
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://#{Setting.plugin_redmine_qbo['sandbox'] ? "sandbox" : "app"}.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2>
|
||||||
<div class="issue">
|
<div class="issue">
|
||||||
|
|
||||||
<div class="splitcontent">
|
<div class="splitcontent">
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<label for="issue_customer"><%= t(:customer) %></label>
|
<label for="issue_customer"><%= t(:customer) %></label>
|
||||||
<%= search_customer %>
|
<%= search_customer %>
|
||||||
<%= customer_id %>
|
<%= customer_id %>
|
||||||
<%= link_to t(:label_load_customer), '#', onclick: "#{js_link}; return false;" %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -1,15 +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 UpdateProjects < ActiveRecord::Migration[5.1]
|
|
||||||
def change
|
|
||||||
add_reference :projects, :customer, index: true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
3
init.rb
3
init.rb
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
name 'Redmine QBO DEVELOPMENT plugin'
|
name 'Redmine QBO DEVELOPMENT plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
|
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
|
||||||
version '2026.1.0'
|
version '2026.1.3'
|
||||||
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'
|
||||||
@@ -27,7 +27,6 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
Issue.safe_attributes 'invoice_id'
|
Issue.safe_attributes 'invoice_id'
|
||||||
User.safe_attributes 'employee_id'
|
User.safe_attributes 'employee_id'
|
||||||
TimeEntry.safe_attributes 'billed'
|
TimeEntry.safe_attributes 'billed'
|
||||||
Project.safe_attributes 'customer_id'
|
|
||||||
|
|
||||||
# set per_page globally
|
# set per_page globally
|
||||||
WillPaginate.per_page = 20
|
WillPaginate.per_page = 20
|
||||||
|
|||||||
@@ -12,24 +12,20 @@ module Hooks
|
|||||||
|
|
||||||
class IssuesFormHookListener < Redmine::Hook::ViewListener
|
class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||||
|
|
||||||
|
include IssuesHelper
|
||||||
|
|
||||||
# Edit Issue Form
|
# Edit Issue Form
|
||||||
# Here we build the required form components before passing them to a partial view formatting.
|
# Here we build the required form components before passing them to a partial view formatting.
|
||||||
def view_issues_form_details_bottom(context={})
|
def view_issues_form_details_bottom(context={})
|
||||||
f = context[:form]
|
f = context[:form]
|
||||||
issue = context[:issue]
|
issue = context[:issue]
|
||||||
|
|
||||||
# check project level customer ownership first
|
|
||||||
# This is done to preload customer information if the entire project is dedicated to a customer
|
|
||||||
if context[:project]
|
|
||||||
selected_customer = context[:project].customer ? context[:project].customer.id : nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check to see if the issue already belongs to a customer
|
# Check to see if the issue already belongs to a customer
|
||||||
selected_customer = issue.customer ? issue.customer.id : nil
|
selected_customer = issue.customer ? issue.customer.id : nil
|
||||||
selected_estimate = issue.estimate ? issue.estimate.id : nil
|
selected_estimate = issue.estimate ? issue.estimate.id : nil
|
||||||
|
|
||||||
# Gernerate edit.js link
|
# Gernerate edit.js link
|
||||||
js_link = issue.new_record? ? "updateIssueFrom('/projects/rmt/issues/new.js', this)" : "updateIssueFrom('/issues/#{issue.id}/edit.js', this)"
|
js_link = "updateIssueFrom('#{escape_javascript update_issue_form_path(issue.project, issue)}', this)"
|
||||||
|
|
||||||
# Load customer information
|
# Load customer information
|
||||||
customer = Customer.find_by_id(selected_customer) if selected_customer
|
customer = Customer.find_by_id(selected_customer) if selected_customer
|
||||||
@@ -65,8 +61,7 @@ module Hooks
|
|||||||
locals: {
|
locals: {
|
||||||
search_customer: search_customer,
|
search_customer: search_customer,
|
||||||
customer_id: customer_id,
|
customer_id: customer_id,
|
||||||
js_link: js_link,
|
select_estimate: select_estimate
|
||||||
select_estimate: select_estimate,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,31 +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.
|
|
||||||
|
|
||||||
module Hooks
|
|
||||||
|
|
||||||
class ProjectsFormHookListener < Redmine::Hook::ViewListener
|
|
||||||
|
|
||||||
# Edit Project Form
|
|
||||||
def view_projects_form(context={})
|
|
||||||
f = context[:form]
|
|
||||||
|
|
||||||
# Check to see if there is a quickbooks user attached to the issue
|
|
||||||
selected_customer = context[:project].customer ? context[:project].customer : nil
|
|
||||||
|
|
||||||
# Load customer information
|
|
||||||
customer = Customer.find_by_id(selected_customer) if selected_customer
|
|
||||||
search_customer = f.autocomplete_field :customer, autocomplete_customer_name_customers_path, :selected => selected_customer, :update_elements => {:id => '#project_customer_id', :value => '#project_customer'}
|
|
||||||
customer_id = f.hidden_field :customer_id, :id => "project_customer_id"
|
|
||||||
|
|
||||||
return "<p><label for=\"project_customer\">Customer</label>#{search_customer} #{customer_id}</p>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
@@ -59,8 +59,12 @@ module Patches
|
|||||||
#left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id')
|
#left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id')
|
||||||
|
|
||||||
logger.debug "Calling :pdf_left hook"
|
logger.debug "Calling :pdf_left hook"
|
||||||
context = Redmine::Hook.call_hook :pdf_left, { array: left, issue: issue }
|
left_hook_output = Redmine::Hook.call_hook :pdf_left, { issue: issue }
|
||||||
left << context.first unless context.nil?
|
unless left_hook_output.nil?
|
||||||
|
left_hook_output.each do |l|
|
||||||
|
left.concat l unless l.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
right = []
|
right = []
|
||||||
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
||||||
@@ -70,8 +74,12 @@ module Patches
|
|||||||
right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
|
right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
|
||||||
|
|
||||||
logger.debug "Calling :pdf_right hook"
|
logger.debug "Calling :pdf_right hook"
|
||||||
context = Redmine::Hook.call_hook :pdf_right, { array: right, issue: issue }
|
right_hook_output = Redmine::Hook.call_hook :pdf_right, { issue: issue }
|
||||||
right << context.first unless context.nil?
|
unless right_hook_output.nil?
|
||||||
|
right_hook_output.each do |r|
|
||||||
|
right.concat r unless r.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
rows = left.size > right.size ? left.size : right.size
|
rows = left.size > right.size ? left.size : right.size
|
||||||
while left.size < rows
|
while left.size < rows
|
||||||
|
|||||||
@@ -1,43 +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.
|
|
||||||
|
|
||||||
require_dependency 'project'
|
|
||||||
|
|
||||||
module Patches
|
|
||||||
|
|
||||||
# Patches Redmine's Projects dynamically.
|
|
||||||
# Adds a relationships
|
|
||||||
module ProjectPatch
|
|
||||||
|
|
||||||
def self.included(base) # :nodoc:
|
|
||||||
base.extend(ClassMethods)
|
|
||||||
|
|
||||||
base.send(:include, InstanceMethods)
|
|
||||||
|
|
||||||
# Same as typing in the class
|
|
||||||
base.class_eval do
|
|
||||||
belongs_to :customer, primary_key: :id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
# Add module to Project
|
|
||||||
Project.send(:include, ProjectPatch)
|
|
||||||
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user