trabajo-afectivo/app/models/sla.rb

32 lines
837 B
Ruby
Raw Normal View History

# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2013-02-01 08:53:14 +00:00
class Sla < ApplicationModel
include ChecksClientNotification
include ChecksConditionValidation
include HasEscalationCalculationImpact
include Sla::Assets
store :condition
store :data
validates :name, presence: true
belongs_to :calendar, optional: true
def condition_matches?(ticket)
query_condition, bind_condition, tables = Ticket.selector2sql(condition)
Ticket.where(query_condition, *bind_condition).joins(tables).exists?(ticket.id)
end
def self.for_ticket(ticket)
fallback = nil
all.order(:name, :created_at).find_each do |record|
if record.condition.present?
return record if record.condition_matches?(ticket)
else
fallback = record
end
end
fallback
end
end