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

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