Added relationship to issues, renamed qbp_customer, started cleaning up

listeners
This commit is contained in:
2016-01-13 20:37:02 -05:00
parent 6f194e37bd
commit ec1c263347
6 changed files with 86 additions and 37 deletions

View File

@@ -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.
class QboCustomers < ActiveRecord::Base class QboCustomer < ActiveRecord::Base
unloadable unloadable
has_many :issues has_many :issues
attr_accessible :name attr_accessible :name
@@ -25,7 +25,7 @@ class QboCustomers < ActiveRecord::Base
def self.update_all def self.update_all
# Update the customer table # Update the customer table
get_base.service.all.each { |customer| get_base.service.all.each { |customer|
qbo_customer = QboCustomers.find_or_create_by(id: customer.id) qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
qbo_customer.id = customer.id qbo_customer.id = customer.id
qbo_customer.name = customer.display_name qbo_customer.name = customer.display_name
qbo_customer.save! qbo_customer.save!

View File

@@ -27,4 +27,12 @@ class QboEstimate < ActiveRecord::Base
qbo_estimate.save! qbo_estimate.save!
} }
end end
def self.update(id)
# Update the item table
estimate = get_base.service.fetch_by_id(id)
qbo_estimate = QboEstimate.find_or_create_by(id: id)
qbo_estimate.doc_number = estimate.doc_number
qbo_estimate.save!
end
end end

46
init.rb
View File

@@ -10,30 +10,34 @@
Redmine::Plugin.register :redmine_qbo do Redmine::Plugin.register :redmine_qbo do
require_dependency 'issues_form_hook_listener' # View Hook Listeners
require_dependency 'issues_save_hook_listener' require_dependency 'issues_form_hook_listener'
require_dependency 'issues_show_hook_listener' require_dependency 'issues_save_hook_listener'
require_dependency 'users_show_hook_listener' require_dependency 'issues_show_hook_listener'
require_dependency 'users_show_hook_listener'
name 'Redmine Quickbooks Online plugin' # Patches to the Redmine core. Will not work in development mode
author 'Rick Barrette' require_dependency 'issue_patch'
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
version '0.0.2'
url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'http://rickbarrette.org'
settings :default => {'empty' => true}, :partial => 'qbo/settings'
# Add safe attributes name 'Redmine Quickbooks Online plugin'
Issue.safe_attributes 'qbo_customer_id' author 'Rick Barrette'
Issue.safe_attributes 'qbo_item_id' description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
Issue.safe_attributes 'qbo_estimate_id' version '0.0.3'
User.safe_attributes 'qbo_employee_id' url 'https://github.com/rickbarrette/redmine_qbo'
TimeEntry.safe_attributes 'qbo_billed' author_url 'http://rickbarrette.org'
settings :default => {'empty' => true}, :partial => 'qbo/settings'
# We are playing in the sandbox # Add safe attributes
#Quickbooks.sandbox_mode = true Issue.safe_attributes 'qbo_customer_id'
Issue.safe_attributes 'qbo_item_id'
Issue.safe_attributes 'qbo_estimate_id'
User.safe_attributes 'qbo_employee_id'
TimeEntry.safe_attributes 'qbo_billed'
# Register QBO top menu item # We are playing in the sandbox
menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks' #Quickbooks.sandbox_mode = true
# Register QBO top menu item
menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks'
end end

41
lib/issue_patch.rb Normal file
View File

@@ -0,0 +1,41 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 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 'issue'
# Patches Redmine's Issues dynamically.
# Adds a relationships
module IssuePatch
def self.included(base) # :nodoc:
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
# Same as typing in the class
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
belongs_to :qbo_customer, primary_key: :id
belongs_to :qbo_item, primary_key: :id
belongs_to :qbo_estimate, primary_key: :id
end
end
module ClassMethods
end
module InstanceMethods
end
end
# Add module to Issue
Issue.send(:include, IssuePatch)

View File

@@ -15,7 +15,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
def view_issues_form_details_bottom(context={}) def view_issues_form_details_bottom(context={})
selected = "" selected = ""
QboCustomers.update_all QboCustomer.update_all
QboItem.update_all QboItem.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
@@ -25,7 +25,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
end end
# Generate the drop down list of quickbooks contacts # Generate the drop down list of quickbooks contacts
select_customer = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), :selected => selected_customer, include_blank: true select_customer = context[:form].select :qbo_customer_id, QboCustomer.all.pluck(:name, :id), :selected => selected_customer, include_blank: true
# Generate the drop down list of quickbooks contacts # Generate the drop down list of quickbooks contacts
select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id).reverse, :selected => selected_item, include_blank: true select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id).reverse, :selected => selected_item, include_blank: true

View File

@@ -21,21 +21,17 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
issue = context[:issue] issue = context[:issue]
# 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
unless context[:issue].qbo_customer_id.nil? #unless context[:issue].qbo_customer_id.nil?
@customer = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name @customer = issue.qbo_customer.name
end #end
# Check to see if there is a quickbooks item attached to the issue # Check to see if there is a quickbooks item attached to the issue
unless issue.qbo_customer_id.nil? then @item = issue.qbo_item.name
unless QboItem.find_by_id(context[:issue].qbo_item_id).nil?
@item = QboItem.find_by_id(context[:issue].qbo_item_id).name
end
end
# Estimate Number # Estimate Number
unless (issue.qbo_estimate_id.nil?) unless (issue.qbo_estimate.nil?)
QboEstimate.update_all QboEstimate.update(issue.qbo_estimate.id)
@estimate = QboEstimate.find_by_id(issue.qbo_estimate_id).doc_number @estimate = issue.qbo_estimate.doc_number
end end
return "<div class=\"attributes\"> return "<div class=\"attributes\">