blob: 742c181413088f200e11d1d811f23fb0621b4df0 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 | require 'range_ext'
require_relative '../calendar/period'
module Chouette
  class PurchaseWindow < Chouette::TridentActiveRecord
    # include ChecksumSupport
    include ObjectidSupport
    include PeriodSupport
    extend Enumerize
    enumerize :color, in: %w(#9B9B9B #FFA070 #C67300 #7F551B #41CCE3 #09B09C #3655D7 #6321A0 #E796C6 #DD2DAA)
    has_paper_trail
    belongs_to :referential
    has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney'
    validates_presence_of :name, :referential
    scope :contains_date, ->(date) { where('date ? <@ any (date_ranges)', date) }
    scope :text_search, ->(q) { where("unaccent(name) ILIKE unaccent(:q) OR objectid ILIKE :q", q: "%#{q}%")}
    def self.ransackable_scopes(auth_object = nil)
      [:contains_date]
    end
    def self.colors_i18n
      Hash[*color.values.map{|c| [I18n.t("enumerize.purchase_window.color.#{c[1..-1]}"), c]}.flatten]
    end
    def local_id
      "IBOO-#{self.referential.id}-#{self.id}"
    end
    # def checksum_attributes
    # end
  end
end
 |