Compare commits

...

15 Commits

13 changed files with 33 additions and 131 deletions

View File

@@ -23,7 +23,6 @@ class Employee < ActiveRecord::Base
return unless employees return unless employees
transaction do transaction do
# Update the item table
employees.each { |e| employees.each { |e|
logger.info "Processing employee #{e.id}" logger.info "Processing employee #{e.id}"
employee = find_or_create_by(id: e.id) employee = find_or_create_by(id: e.id)

View File

@@ -56,7 +56,6 @@ class Estimate < ActiveRecord::Base
# update an estimate # update an estimate
def self.update(id) def self.update(id)
# Update the item table
qbo = Qbo.first qbo = Qbo.first
estimate = qbo.perform_authenticated_request do |access_token| estimate = qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token)

View File

@@ -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.

View File

@@ -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">

View File

@@ -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>

View File

@@ -12,7 +12,6 @@
# Usage I18n.t(:label) # Usage I18n.t(:label)
en: en:
field_customer: "Customer" field_customer: "Customer"
field_item: "Item"
field_employee: "Employee" field_employee: "Employee"
field_invoice: "Invoice" field_invoice: "Invoice"
field_estimate: "Estimate" field_estimate: "Estimate"
@@ -54,7 +53,6 @@ en:
label_customer_count: "Customer Count" label_customer_count: "Customer Count"
label_invoice_count: "Invoice Count" label_invoice_count: "Invoice Count"
label_estimate_count: "Estimate Count" label_estimate_count: "Estimate Count"
label_item_count: "Item Count"
label_employee_count: "Employee Count" label_employee_count: "Employee Count"
label_client_id: "Intuit QBO OAuth2 Client ID" label_client_id: "Intuit QBO OAuth2 Client ID"
label_client_secret: "Intuit QBO OAuth2 Client Secret" label_client_secret: "Intuit QBO OAuth2 Client Secret"

View File

@@ -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

View File

@@ -11,10 +11,10 @@
Redmine::Plugin.register :redmine_qbo do Redmine::Plugin.register :redmine_qbo do
# About # About
name 'Redmine QBO DEVELOPMENT plugin' name 'Redmine QBO 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'
@@ -22,12 +22,10 @@ Redmine::Plugin.register :redmine_qbo do
# Add safe attributes for core models # Add safe attributes for core models
Issue.safe_attributes 'customer_id' Issue.safe_attributes 'customer_id'
Issue.safe_attributes 'item_id'
Issue.safe_attributes 'estimate_id' Issue.safe_attributes 'estimate_id'
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

View File

@@ -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,
} }
} }
) )

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,9 +0,0 @@
require File.expand_path('../../test_helper', __FILE__)
class QboItemTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end