Class: Comee::Core::Price

Inherits:
ApplicationRecord show all
Defined in:
app/models/comee/core/price.rb

Direct Known Subclasses

ClientPrice, MasterPrice

Instance Method Summary collapse

Instance Method Details

#approveObject



45
46
47
48
49
50
51
52
53
# File 'app/models/comee/core/price.rb', line 45

def approve
  if Price.price_statuses[price_status] == Price.price_statuses[:approved]
    raise(StandardError, "Price status is already in approved state.")
  end

  self.price_status = Price.price_statuses[:approved]
  save!
  self
end

#approved?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/comee/core/price.rb', line 30

def approved?
  Price.price_statuses[price_status] == Price.price_statuses[:approved]
end

#compute_statusObject



34
35
36
37
38
39
40
41
42
43
# File 'app/models/comee/core/price.rb', line 34

def compute_status
  period = Period.new(valid_from, valid_to)
  if period.past?
    self.status = Price.statuses[:past]
  elsif period.current?
    self.status = Price.statuses[:current]
  elsif period.future?
    self.status = Price.statuses[:future]
  end
end

#current?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/comee/core/price.rb', line 59

def current?
  Price.statuses[status] == Price.statuses[:current]
end

#draft?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/comee/core/price.rb', line 26

def draft?
  Price.price_statuses[price_status] == Price.price_statuses[:draft]
end

#future?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/comee/core/price.rb', line 63

def future?
  Price.statuses[status] == Price.statuses[:future]
end

#past?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/comee/core/price.rb', line 55

def past?
  Price.statuses[status] == Price.statuses[:past]
end

#validate_price_validity_datesObject



19
20
21
22
23
24
# File 'app/models/comee/core/price.rb', line 19

def validate_price_validity_dates
  return unless valid_from && valid_to

  period = Period.new(valid_from, valid_to)
  errors.add(:base, "Price validity date range is not correct.") unless period.valid?
end