Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Appointment < ApplicationRecord
- scope :with_status, -> (status) { where(status: status) }
- scope :alertable, -> { where(is_alert: true) }
- belongs_to :offer
- belongs_to :stylist
- belongs_to :user
- has_many :appointment_follow_ups
- validates :user_id, presence: true
- validates :offer_id, presence: true
- validates_uniqueness_of :time, scope: [:offer_id, :date], conditions: -> { where.not(status: [APPOINTMENT_STATUS[2], APPOINTMENT_STATUS[3]]) }
- before_update :refund_if_cancelled_by_s_or_a, if: -> { status_changed? and cancelled_by_admin? }
- def notification_key
- if appointment.offer
- appointment.offer_id #incase offer is deleted but appointment status stays
- else
- 1
- end
- end
- private
- def refund_if_cancelled_by_s_or_a
- self.allow_refund = true
- end
- end
Add Comment
Please, Sign In to add comment