Moved to separate Ticket::Number class/adapter.
This commit is contained in:
parent
39cb5c5fa6
commit
e4381827ab
6 changed files with 46 additions and 44 deletions
|
@ -333,7 +333,7 @@ class Channel::EmailParser
|
||||||
UserInfo.current_user_id = user.id
|
UserInfo.current_user_id = user.id
|
||||||
|
|
||||||
# get ticket# from subject
|
# get ticket# from subject
|
||||||
ticket = Ticket.number_check( mail[:subject] )
|
ticket = Ticket::Number.check( mail[:subject] )
|
||||||
|
|
||||||
# set ticket state to open if not new
|
# set ticket state to open if not new
|
||||||
if ticket
|
if ticket
|
||||||
|
|
|
@ -4,7 +4,7 @@ require 'time_calculation'
|
||||||
require 'sla'
|
require 'sla'
|
||||||
|
|
||||||
class Ticket < ApplicationModel
|
class Ticket < ApplicationModel
|
||||||
before_create :number_generate, :check_defaults
|
before_create :check_generate, :check_defaults
|
||||||
before_update :check_defaults
|
before_update :check_defaults
|
||||||
before_destroy :destroy_dependencies
|
before_destroy :destroy_dependencies
|
||||||
after_create :notify_clients_after_create
|
after_create :notify_clients_after_create
|
||||||
|
@ -24,10 +24,6 @@ class Ticket < ApplicationModel
|
||||||
|
|
||||||
attr_accessor :callback_loop
|
attr_accessor :callback_loop
|
||||||
|
|
||||||
def self.number_check (string)
|
|
||||||
self.number_adapter.number_check_item(string)
|
|
||||||
end
|
|
||||||
|
|
||||||
def agent_of_group
|
def agent_of_group
|
||||||
Group.find( self.group_id ).users.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
|
Group.find( self.group_id ).users.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
|
||||||
end
|
end
|
||||||
|
@ -504,21 +500,6 @@ class Ticket < ApplicationModel
|
||||||
return bind
|
return bind
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.number_adapter
|
|
||||||
|
|
||||||
# load backend based on config
|
|
||||||
adapter_name = Setting.get('ticket_number')
|
|
||||||
adapter = nil
|
|
||||||
case adapter_name
|
|
||||||
when Symbol, String
|
|
||||||
require "ticket/number/#{adapter_name.to_s.downcase}"
|
|
||||||
adapter = Ticket::Number.const_get("#{adapter_name.to_s.capitalize}")
|
|
||||||
else
|
|
||||||
raise "Missing number_adapter '#{adapter_name}'"
|
|
||||||
end
|
|
||||||
return adapter
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.escalation_calculation_rebuild
|
def self.escalation_calculation_rebuild
|
||||||
ticket_state_list_open = Ticket::State.by_category( 'open' )
|
ticket_state_list_open = Ticket::State.by_category( 'open' )
|
||||||
|
|
||||||
|
@ -731,21 +712,11 @@ returns
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def number_generate
|
def check_generate
|
||||||
return if self.number
|
return if self.number
|
||||||
|
self.number = Ticket::Number.generate
|
||||||
# generate number
|
|
||||||
(1..25_000).each do |i|
|
|
||||||
number = Ticket.number_adapter.number_generate_item()
|
|
||||||
ticket = Ticket.where( :number => number ).first
|
|
||||||
if ticket != nil
|
|
||||||
number = Ticket.number_adapter.number_generate_item()
|
|
||||||
else
|
|
||||||
self.number = number
|
|
||||||
return number
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_defaults
|
def check_defaults
|
||||||
if !self.owner_id
|
if !self.owner_id
|
||||||
self.owner_id = 1
|
self.owner_id = 1
|
||||||
|
@ -874,7 +845,4 @@ returns
|
||||||
diff
|
diff
|
||||||
end
|
end
|
||||||
|
|
||||||
class Number
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module Ticket::Number::Date
|
module Ticket::Number::Date
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def number_generate_item
|
def generate
|
||||||
|
|
||||||
# get config
|
# get config
|
||||||
config = Setting.get('ticket_number_date')
|
config = Setting.get('ticket_number_date')
|
||||||
|
@ -64,7 +64,7 @@ module Ticket::Number::Date
|
||||||
end
|
end
|
||||||
return number
|
return number
|
||||||
end
|
end
|
||||||
def number_check_item (string)
|
def check(string)
|
||||||
|
|
||||||
# get config
|
# get config
|
||||||
system_id = Setting.get('system_id') || ''
|
system_id = Setting.get('system_id') || ''
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
module Ticket::Number::Increment
|
module Ticket::Number::Increment
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def number_generate_item
|
def generate
|
||||||
|
|
||||||
# get config
|
# get config
|
||||||
config = Setting.get('ticket_number_increment')
|
config = Setting.get('ticket_number_increment')
|
||||||
|
@ -68,7 +68,7 @@ module Ticket::Number::Increment
|
||||||
return number
|
return number
|
||||||
end
|
end
|
||||||
|
|
||||||
def number_check_item (string)
|
def check(string)
|
||||||
|
|
||||||
# get config
|
# get config
|
||||||
system_id = Setting.get('system_id') || ''
|
system_id = Setting.get('system_id') || ''
|
||||||
|
|
34
db/migrate/20130815000002_update_ticket_number.rb
Normal file
34
db/migrate/20130815000002_update_ticket_number.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
class UpdateTicketNumber < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
Setting.create_or_update(
|
||||||
|
:title => 'Ticket Number Format',
|
||||||
|
:name => 'ticket_number',
|
||||||
|
:area => 'Ticket::Number',
|
||||||
|
:description => 'Selects the ticket number generator module. "Increment" increments the ticket
|
||||||
|
number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139).
|
||||||
|
With "Date" the ticket numbers will be generated by the current date, the SystemID and the counter.
|
||||||
|
The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139).
|
||||||
|
With param "Checksum => true" the counter will be appended as checksum to the string. The format
|
||||||
|
looks like SystemID.Counter.CheckSum (e. g. 10101384, 10101392) or Year.Month.Day.SystemID.Counter.CheckSum (e.g. 2012070110101520, 2012070110101535).',
|
||||||
|
:options => {
|
||||||
|
:form => [
|
||||||
|
{
|
||||||
|
:display => '',
|
||||||
|
:null => true,
|
||||||
|
:name => 'ticket_number',
|
||||||
|
:tag => 'select',
|
||||||
|
:options => {
|
||||||
|
'Ticket::Number::Increment' => 'Increment (SystemID.Counter)',
|
||||||
|
'Ticket::Number::Date' => 'Date (Year.Month.Day.SystemID.Counter)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
:state => 'Ticket::Number::Increment',
|
||||||
|
:frontend => false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -712,13 +712,13 @@ Setting.create_if_not_exists(
|
||||||
:name => 'ticket_number',
|
:name => 'ticket_number',
|
||||||
:tag => 'select',
|
:tag => 'select',
|
||||||
:options => {
|
:options => {
|
||||||
'increment' => 'Increment (SystemID.Counter)',
|
'Ticket::Number::Increment' => 'Increment (SystemID.Counter)',
|
||||||
'date' => 'Date (Year.Month.Day.SystemID.Counter)',
|
'Ticket::Number::Date' => 'Date (Year.Month.Day.SystemID.Counter)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
:state => 'increment',
|
:state => 'Ticket::Number::Increment',
|
||||||
:frontend => false
|
:frontend => false
|
||||||
)
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
|
|
Loading…
Reference in a new issue