diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 9fa8669..0aab913 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -27,14 +27,18 @@ class CustomersController < ApplicationController include SortHelper helper :timelog - before_filter :add_customer, :only => :new - before_filter :view_customer, :except => :new - skip_before_filter :verify_authenticity_token, :check_if_login_required, :only => [:view] + before_action :add_customer, :only => :new + before_action :view_customer, :except => :new + skip_before_action :verify_authenticity_token, :check_if_login_required, :only => [:view] default_search_scope :names autocomplete :customer, :name, :full => true, :extra_data => [:id] + def allowed_params + params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number) + end + # getter method for a customer's vehicles # used for customer autocomplete field / issue form def filter_vehicles_by_customer @@ -70,7 +74,7 @@ class CustomersController < ApplicationController # create a new customer def create - @customer = Customer.new(params[:customer]) + @customer = Customer.new(allowed_params) if @customer.save flash[:notice] = "New Customer Created" redirect_to @customer @@ -104,7 +108,7 @@ class CustomersController < ApplicationController def update begin @customer = Customer.find_by_id(params[:id]) - if @customer.update_attributes(params[:customer]) + if @customer.update_attributes(allowed_params) flash[:notice] = "Customer updated" redirect_to @customer else diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index dbdf67a..5f72247 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -12,7 +12,7 @@ class EstimateController < ApplicationController include AuthHelper - before_filter :require_user + before_action :require_user # # Downloads and forwards the estimate pdf diff --git a/app/controllers/invoice_controller.rb b/app/controllers/invoice_controller.rb index 1308e44..203f1a4 100644 --- a/app/controllers/invoice_controller.rb +++ b/app/controllers/invoice_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -12,8 +12,8 @@ class InvoiceController < ApplicationController include AuthHelper - before_filter :require_user, :unless => proc {|c| session[:token].nil? } - skip_before_filter :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? } + before_action :require_user, :unless => proc {|c| session[:token].nil? } + skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? } # # Downloads and forwards the invoice pdf diff --git a/app/controllers/line_items_controler.rb b/app/controllers/line_items_controler.rb index 684d4c8..5300f32 100644 --- a/app/controllers/line_items_controler.rb +++ b/app/controllers/line_items_controler.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2018 rick barrette +#Copyright (c) 2022 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: # @@ -14,7 +14,7 @@ class LineItemsController < ApplicationController include AuthHelper - before_filter :require_user + before_action :require_user # display all line items for an issue def index diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 7150a09..3ee14cc 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -12,7 +12,7 @@ class PaymentsController < ApplicationController include AuthHelper - before_filter :check_permissions + before_action :check_permissions def new @payment = Payment.new diff --git a/app/controllers/qbo_controller.rb b/app/controllers/qbo_controller.rb index cdd22e4..4851a59 100644 --- a/app/controllers/qbo_controller.rb +++ b/app/controllers/qbo_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -15,8 +15,8 @@ class QboController < ApplicationController include AuthHelper - before_filter :require_user, :except => :qbo_webhook - skip_before_filter :verify_authenticity_token, :check_if_login_required, :only => [:qbo_webhook] + before_action :require_user, :except => :qbo_webhook + skip_before_action :verify_authenticity_token, :check_if_login_required, :only => [:qbo_webhook] # # Called when the QBO Top Menu us shown diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb index e7ffbfd..9029427 100644 --- a/app/controllers/vehicles_controller.rb +++ b/app/controllers/vehicles_controller.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -14,7 +14,11 @@ class VehiclesController < ApplicationController include AuthHelper - before_filter :require_user + before_action :require_user + + def allowed_params + params.require(:vehicle).permit(:year, :make, :model, :customer_id, :notes, :vin) + end # display a list of all vehicles def index @@ -43,7 +47,7 @@ class VehiclesController < ApplicationController # create a new vehicle def create - @vehicle = Vehicle.new(params[:vehicle]) + @vehicle = Vehicle.new(allowed_params) if @vehicle.save flash[:notice] = "New Vehicle Created" redirect_to @vehicle @@ -78,7 +82,7 @@ class VehiclesController < ApplicationController @customer = params[:customer] begin @vehicle = Vehicle.find_by_id(params[:id]) - if @vehicle.update_attributes(params[:vehicle]) + if @vehicle.update_attributes(allowed_params) flash[:notice] = "Vehicle updated" redirect_to @vehicle else @@ -117,4 +121,4 @@ class VehiclesController < ApplicationController found_non_zero end -end +end \ No newline at end of file diff --git a/app/models/customer.rb b/app/models/customer.rb index 79bb9d0..1466fb0 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -17,7 +17,7 @@ class Customer < ActiveRecord::Base has_many :qbo_estimates has_many :vehicles - attr_accessible :name, :notes, :email, :primary_phone, :mobile_phone, :phone_number + #attr_accessible :name, :notes, :email, :primary_phone, :mobile_phone, :phone_number validates_presence_of :id, :name self.primary_key = :id diff --git a/app/models/customer_token.rb b/app/models/customer_token.rb index a3ff89e..dce986f 100644 --- a/app/models/customer_token.rb +++ b/app/models/customer_token.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -11,7 +11,7 @@ class CustomerToken < ActiveRecord::Base unloadable has_many :issues - attr_accessible :token, :expires_at, :issue_id + #attr_accessible :token, :expires_at, :issue_id validates_presence_of :expires_at, :issue_id before_create :generate_token diff --git a/app/models/line_item.rb b/app/models/line_item.rb index 667144f..5eaed60 100644 --- a/app/models/line_item.rb +++ b/app/models/line_item.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2018 rick barrette +#Copyright (c) 2022 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: # @@ -14,7 +14,7 @@ class LineItem < ActiveRecord::Base belongs_to :issue - attr_accessible :amount, :description, :unit_price, :quantity, :item_id + #attr_accessible :amount, :description, :unit_price, :quantity, :item_id validates_presence_of :amount, :description, :unit_price, :quantity def add_to_invoice(invoice) diff --git a/app/models/qbo_employee.rb b/app/models/qbo_employee.rb index df331e0..651c511 100644 --- a/app/models/qbo_employee.rb +++ b/app/models/qbo_employee.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -11,7 +11,7 @@ class QboEmployee < ActiveRecord::Base unloadable has_many :users - attr_accessible :name + #attr_accessible :name validates_presence_of :id, :name def self.get_base diff --git a/app/models/qbo_estimate.rb b/app/models/qbo_estimate.rb index 2a777d6..d2d17b3 100644 --- a/app/models/qbo_estimate.rb +++ b/app/models/qbo_estimate.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -13,7 +13,7 @@ class QboEstimate < ActiveRecord::Base has_and_belongs_to_many :issues belongs_to :customer - attr_accessible :doc_number, :id + #attr_accessible :doc_number, :id validates_presence_of :doc_number, :id self.primary_key = :id diff --git a/app/models/qbo_invoice.rb b/app/models/qbo_invoice.rb index 6623edf..faa2f84 100644 --- a/app/models/qbo_invoice.rb +++ b/app/models/qbo_invoice.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -13,7 +13,7 @@ class QboInvoice < ActiveRecord::Base has_and_belongs_to_many :issues belongs_to :customer - attr_accessible :doc_number, :id + #attr_accessible :doc_number, :id validates_presence_of :doc_number, :id self.primary_key = :id diff --git a/app/models/qbo_item.rb b/app/models/qbo_item.rb index cc8502e..123ca0f 100644 --- a/app/models/qbo_item.rb +++ b/app/models/qbo_item.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -11,7 +11,7 @@ class QboItem < ActiveRecord::Base unloadable has_many :issues - attr_accessible :name + #attr_accessible :name validates_presence_of :id, :name self.primary_key = :id diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb index 8593cb0..aee8ede 100644 --- a/app/models/qbo_purchase.rb +++ b/app/models/qbo_purchase.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -12,7 +12,7 @@ class QboPurchase < ActiveRecord::Base unloadable belongs_to :issues belongs_to :qbo_customer - attr_accessible :description + #attr_accessible :description validates_presence_of :id, :line_id, :description, :qbo_customer_id def self.get_base diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb index 68a2126..c56412f 100644 --- a/app/models/vehicle.rb +++ b/app/models/vehicle.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -15,7 +15,7 @@ class Vehicle < ActiveRecord::Base belongs_to :customer has_many :issues, :foreign_key => 'vehicles_id' - attr_accessible :year, :make, :model, :customer_id, :notes, :vin + #attr_accessible :year, :make, :model, :customer_id, :notes, :vin validates_presence_of :customer validates :vin, uniqueness: true diff --git a/app/workers/email_worker.rb b/app/workers/email_worker.rb deleted file mode 100644 index a2d42d9..0000000 --- a/app/workers/email_worker.rb +++ /dev/null @@ -1,18 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2017 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. - -# This sidekiq worker class will handle emailing weekly time reports -class EmailWorker - include Sidekiq::Worker - - def perform() - # email something - end -end diff --git a/init.rb b/init.rb index f4f9b71..45016db 100644 --- a/init.rb +++ b/init.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2020 rick barrette +#Copyright (c) 2022 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: # @@ -28,10 +28,11 @@ Redmine::Plugin.register :redmine_qbo do require_dependency 'pdf_patch' require_dependency 'attachments_controller_patch' + # About name 'Redmine Quickbooks Online plugin' 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' - version '0.8.1' + version '1.0.0' url 'https://github.com/rickbarrette/redmine_qbo' author_url 'http://rickbarrette.org' settings :default => {'empty' => true}, :partial => 'qbo/settings' @@ -53,6 +54,7 @@ Redmine::Plugin.register :redmine_qbo do # set per_page globally WillPaginate.per_page = 20 + # Permissions for security permission :view_customers, :customers => :index, :public => false permission :add_customers, :customers => :new, :public => false permission :view_payments, :payments => :index, :public => false diff --git a/lib/pdf_patch.rb b/lib/pdf_patch.rb index 9d4ab51..a5796ee 100644 --- a/lib/pdf_patch.rb +++ b/lib/pdf_patch.rb @@ -1,3 +1,13 @@ +#The MIT License (MIT) +# +#Copyright (c) 2022 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 'redmine/export/pdf' require_dependency 'redmine/export/pdf/issues_pdf_helper' @@ -7,7 +17,9 @@ module IssuesPdfHelperPatch base.send(:include, InstanceMethods) base.class_eval do unloadable # Send unloadable so it will not be unloaded in development - alias_method_chain :issue_to_pdf, :patch + alias_method :issue_to_pdf, :issue_to_pdf_with_patch + alias_method :issue_to_pdf_with_patch, :issue_to_pdf + end end diff --git a/lib/query_patch.rb b/lib/query_patch.rb index 26da658..217c505 100644 --- a/lib/query_patch.rb +++ b/lib/query_patch.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -11,62 +11,24 @@ require_dependency 'issue_query' module QueryPatch - - 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 - - alias_method_chain :available_columns, :qbo - alias_method_chain :available_filters, :qbo + + # Add qbo options to the aviable columns + def available_columns + unless @available_columns + @available_columns = self.class.available_columns.dup + @available_columns << QueryColumn.new(:customer, :sortable => "#{Customer.table_name}.name", :groupable => true, :caption => :field_customer) + @available_columns << QueryColumn.new(:qbo_billed, :sortable => "#{TimeEntry.table_name}.qbo_billed", :groupable => true, :caption => :field_qbo_billed) end - end - - module ClassMethods - + super end - module InstanceMethods - - def available_columns_with_qbo - unless @available_columns - @available_columns = available_columns_without_qbo - @available_columns << QueryColumn.new(:customer, :sortable => "#{Customer.table_name}.name", :groupable => true, :caption => :field_customer) - @available_columns << QueryColumn.new(:qbo_billed, :sortable => "#{TimeEntry.table_name}.qbo_billed", :groupable => true, :caption => :field_qbo_billed) - end - @available_columns - end - - def available_filters_with_qbo - unless @available_filters - @available_filters = available_filters_without_qbo - - #qbo_filters = { - # :customer => { - # :id => l(:field_customer), - # :type => :integer, - # :order => @available_filters.size + 1}, - #} - - #qbo_filters = { - # "customer_id" => { - # :id => :customer_id, - # :type => :list_optional - #:order => @available_filters.size + 1, - #:values => Customer.find(:all).collect { |c| [c.name, c.id.to_s]} - # } - #} - - #@available_filters.merge!(qbo_filters) - end - @available_filters - end + # Add customers to filters + def initialize_available_filters + add_available_filter "customer", :type => :text + super end + end # Add module to Issue -IssueQuery.send(:include, QueryPatch) +IssueQuery.send(:prepend, QueryPatch) \ No newline at end of file diff --git a/lib/time_entry_query_patch.rb b/lib/time_entry_query_patch.rb index f70f99b..b89874d 100644 --- a/lib/time_entry_query_patch.rb +++ b/lib/time_entry_query_patch.rb @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 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: # @@ -12,60 +12,22 @@ require_dependency 'time_entry_query' module TimeEntryQueryPatch - 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 - - alias_method_chain :available_columns, :qbo_billed - alias_method_chain :available_filters, :qbo_billed + # Add QBO options to columns + def available_columns + unless @available_columns + @available_columns = self.class.available_columns.dup + @available_columns << QueryColumn.new(:qbo_billed, :sortable => "#{TimeEntry.table_name}.name", :groupable => true, :caption => :field_qbo_billed) end - end - - module ClassMethods - + super end - module InstanceMethods - - def available_columns_with_qbo_billed - unless @available_columns - @available_columns = available_columns_without_qbo - @available_columns << QueryColumn.new(:qbo_billed, :sortable => "#{TimeEntry.table_name}.name", :groupable => true, :caption => :field_qbo_billed) - end - @available_columns - end - - def available_filters_with_qbo_billed - unless @available_filters - @available_filters = available_filters_without_qbo - - #qbo_filters = { - # :customer => { - # :id => l(:field_qbo_billed), - # :type => :boolean, - # :order => @available_filters.size + 1}, - #} - - qbo_filters = { - "qbo_billed" => { - :id => :qbo_billed, - :type => :list_optional, - :order => @available_filters.size + 1, - #:values => Customer.find(:all).collect { |c| [c.name, c.id.to_s]} - } - } - - @available_filters.merge!(qbo_filters) - end - @available_filters - end + # Add QBO options to the filter + def initialize_available_filters + add_available_filter "qbo_billed", :type => :boolean + super end + end # Add module to TimeEntryQuery -TimeEntryQuery.send(:include, QueryPatch) +TimeEntryQuery.send(:prepend, QueryPatch) \ No newline at end of file