mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-04-02 16:21:58 -04:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b38f850df3 | |||
| 138e55933b | |||
| 5fbc169ade | |||
| d6737a6747 | |||
| 65db8f00a8 | |||
| 0197dc2a30 | |||
| cd1caa502d | |||
| 4b45d24a75 | |||
| 64a4526aa4 | |||
| 3514401808 | |||
| 3deafd8a6d | |||
| a54de28db5 | |||
| 6434eea906 | |||
| 9b656534ae |
@@ -30,8 +30,6 @@ class CustomersController < ApplicationController
|
|||||||
before_action :view_customer, except: [:new, :view]
|
before_action :view_customer, except: [:new, :view]
|
||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
|
||||||
|
|
||||||
default_search_scope :names
|
|
||||||
|
|
||||||
autocomplete :customer, :name, full: true, extra_data: [:id]
|
autocomplete :customer, :name, full: true, extra_data: [:id]
|
||||||
|
|
||||||
def allowed_params
|
def allowed_params
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
class Customer < ActiveRecord::Base
|
class Customer < ActiveRecord::Base
|
||||||
|
|
||||||
|
include Redmine::Acts::Searchable
|
||||||
|
include Redmine::Acts::Event
|
||||||
|
|
||||||
has_many :issues
|
has_many :issues
|
||||||
has_many :invoices
|
has_many :invoices
|
||||||
has_many :estimates
|
has_many :estimates
|
||||||
@@ -18,10 +21,15 @@ class Customer < ActiveRecord::Base
|
|||||||
|
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
|
||||||
# returns a human readable string
|
acts_as_searchable columns: %w[name phone_number mobile_phone_number ],
|
||||||
def to_s
|
scope: ->(_context) { left_joins(:project) },
|
||||||
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
|
date_column: :updated_at
|
||||||
end
|
|
||||||
|
acts_as_event :title => Proc.new {|o| "#{o}"},
|
||||||
|
:url => Proc.new {|o| { :controller => 'customers', :action => 'show', :id => o.id} },
|
||||||
|
:type => :to_s,
|
||||||
|
:description => Proc.new {|o| "#{I18n.t :label_primary_phone}: #{o.phone_number} #{I18n.t:label_mobile_phone}: #{o.mobile_phone_number}"},
|
||||||
|
:datetime => Proc.new {|o| o.updated_at || o.created_at}
|
||||||
|
|
||||||
# Convenience Method
|
# Convenience Method
|
||||||
# returns the customer's email
|
# returns the customer's email
|
||||||
@@ -63,6 +71,12 @@ class Customer < ActiveRecord::Base
|
|||||||
update_phone_number
|
update_phone_number
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Customers are not bound by a project
|
||||||
|
# but we need to implement this method for the Redmine::Acts::Searchable interface
|
||||||
|
def project
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
# Convenience Method
|
# Convenience Method
|
||||||
# returns the customer's mobile phone
|
# returns the customer's mobile phone
|
||||||
def mobile_phone
|
def mobile_phone
|
||||||
@@ -167,12 +181,29 @@ class Customer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Searchs the database for a customer by name or phone number with out special chars
|
|
||||||
def self.search(search)
|
def self.search(search)
|
||||||
|
search = sanitize_sql_like(search)
|
||||||
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
|
customers = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%")
|
||||||
return customers.order(:name)
|
return customers.order(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Override the defult redmine seach method to rank results by id
|
||||||
|
def self.search_result_ranks_and_ids(tokens, user, project = nil, options = {})
|
||||||
|
return {} if tokens.blank?
|
||||||
|
|
||||||
|
scope = self.all
|
||||||
|
|
||||||
|
tokens.each do |token|
|
||||||
|
q = "%#{sanitize_sql_like(token)}%"
|
||||||
|
scope = where("name LIKE ? OR phone_number LIKE ? OR mobile_phone_number LIKE ?", "%#{q}%", "%#{q}%", "%#{q}%")
|
||||||
|
end
|
||||||
|
|
||||||
|
ids = scope.distinct.limit(options[:limit] || 100).pluck(:id)
|
||||||
|
|
||||||
|
# Assign simple uniform ranking
|
||||||
|
ids.each_with_object({}) { |id, h| h[id] = id }
|
||||||
|
end
|
||||||
|
|
||||||
# proforms a bruteforce sync operation
|
# proforms a bruteforce sync operation
|
||||||
# This needs to be simplified
|
# This needs to be simplified
|
||||||
def self.sync_by_id(id)
|
def self.sync_by_id(id)
|
||||||
@@ -200,19 +231,29 @@ class Customer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns a human readable string
|
||||||
|
def to_s
|
||||||
|
return "#{self[:name]} - #{phone_number.split(//).last(4).join unless phone_number.nil?}"
|
||||||
|
end
|
||||||
|
|
||||||
# Push the updates
|
# Push the updates
|
||||||
def save_with_push
|
def save_with_push
|
||||||
begin
|
begin
|
||||||
qbo = Qbo.first
|
qbo = Qbo.first
|
||||||
@details = qbo.perform_authenticated_request do |access_token|
|
@details = qbo.perform_authenticated_request do |access_token|
|
||||||
service = Quickbooks::Service::Customer.new(company_id: qbo.realm_id, access_token: access_token)
|
service = Quickbooks::Service::Customer.new(
|
||||||
|
company_id: qbo.realm_id,
|
||||||
|
access_token: access_token
|
||||||
|
)
|
||||||
service.update(@details)
|
service.update(@details)
|
||||||
end
|
end
|
||||||
#raise "QBO Fault" if @details.fault?
|
|
||||||
self.id = @details.id
|
self.id = @details.id
|
||||||
rescue Exception => e
|
rescue => e
|
||||||
errors.add(e.message)
|
errors.add(:base, e.message)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
save_without_push
|
save_without_push
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= form_tag(customers_path, method: "get", id: "search-form") do %>
|
<%= form_tag(customers_path, method: "get", id: "customer-search-form") do %>
|
||||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_customers), autocomplete: "off" %>
|
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_customers), autocomplete: "off" %>
|
||||||
<%= submit_tag t(:label_search) %>
|
<%= submit_tag t(:label_search) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<%= form_tag(estimate_doc_path, method: "get") do %>
|
<%= form_tag(estimate_doc_path, method: "get", id: "estimate-search-form") do %>
|
||||||
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), autocomplete: "off" %>
|
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates), autocomplete: "off" %>
|
||||||
<%= submit_tag t(:label_search), formtarget: "_blank" %>
|
<%= submit_tag t(:label_search), formtarget: "_blank" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
15
db/migrate/038_add_customers_timestamp.rb
Normal file
15
db/migrate/038_add_customers_timestamp.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#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 AddCustomersTimestamp < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
add_timestamps(:customers, null: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
16
db/migrate/039_add_full_text_index_to_customers.rb
Normal file
16
db/migrate/039_add_full_text_index_to_customers.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#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 AddFullTextIndexToCustomers < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
# This creates a combined index for name and phone fields
|
||||||
|
add_index :customers, [:name, :phone_number, :mobile_phone_number], type: :fulltext, name: 'ft_search_idx'
|
||||||
|
end
|
||||||
|
end
|
||||||
6
init.rb
6
init.rb
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
name 'Redmine QBO plugin'
|
name 'Redmine QBO plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
|
||||||
version '2026.2.11'
|
version '2026.2.15'
|
||||||
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'
|
||||||
@@ -37,6 +37,10 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
# Register top menu items
|
# Register top menu items
|
||||||
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
|
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
|
||||||
|
|
||||||
|
Redmine::Search.map do |search|
|
||||||
|
search.register :customers
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dynamically load all Hooks & Patches recursively
|
# Dynamically load all Hooks & Patches recursively
|
||||||
|
|||||||
Reference in New Issue
Block a user