1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/models/offer_day.rb
Sylvain d942d46632 WIP: migration to object[]
TODO: fix running tests, fix front-end
2021-05-28 17:34:20 +02:00

19 lines
543 B
Ruby

# frozen_string_literal: true
# OfferDay provides a way for admins to extend the subscription of a member for free.
class OfferDay < ApplicationRecord
include NotifyWith::NotificationAttachedObject
has_many :invoice_items, as: :object, dependent: :destroy
belongs_to :subscription
# buying invoice
def original_invoice
invoice_items.select(:invoice_id)
.group(:invoice_id)
.map(&:invoice_id)
.map { |id| Invoice.find_by(id: id, type: nil) }
.first
end
end