I have started working on a plugin for redmine that will allow me to assign a Quickbooks Online (QBO) contact to an issue.
I have created a table for the contacts that only stores a name for each qbo contact.
I have also added a migration to add a reference for qbo_contact to Issues
class UpdateIssues < ActiveRecord::Migration
def change
add_reference :issues, :qbo_customer, index: true
end
end
The issue I am having is that when the issue is being edited, the user can select a QBO contact. When the user saves the issue, Issues.qbo_contact_id is not updated.
I feel it might have something to do with the form selection box
Please Advise
class QboHookListener < Redmine::Hook::ViewListener
# Edit Issue Form
# Show a dropdown for quickbooks contacts
def view_issues_form_details_bottom(context={})
selected = ""
# Check to see if there is a quickbooks user attached to the issue
if not context[:issue].qbo_customer_id.nil? then
selected = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name
end
# Generate the drop down list of quickbooks contacts
select = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), include_blank: true, selected: selected
return "<p>#{select}</p>"
#TODO save selection to Issues.qbp_customer_id
end
end
If you need more, I have shared my work on github