Files
old-holivud2/app/models/contract_template.rb

98 lines
2.3 KiB
Ruby
Raw Normal View History

2020-05-31 22:38:19 +02:00
# frozen_string_literal: true
class ContractTemplate < ApplicationRecord
include Exploitable
include Syncable
include PgSearch
2020-07-03 10:23:03 +02:00
NUMBER_OF_CUSTOM_FIELDS = 15
2020-05-31 22:38:19 +02:00
belongs_to :project
belongs_to :parent, class_name: 'ContractTemplate', optional: true
has_many :duplicates, class_name: 'ContractTemplate', foreign_key: 'parent_id'
has_many :talent_releases, dependent: :restrict_with_error
has_many :appearance_releases, dependent: :restrict_with_error
has_many :acquired_media_releases, dependent: :restrict_with_error
has_many :location_releases, dependent: :restrict_with_error
has_many :material_releases, dependent: :restrict_with_error
2020-06-11 16:56:29 +02:00
has_many :medical_releases, dependent: :restrict_with_error
2020-06-23 17:10:53 +02:00
has_many :misc_releases, dependent: :restrict_with_error
2020-05-31 22:38:19 +02:00
2020-09-16 05:39:08 +02:00
monetize :fee_old_cents
2020-05-31 22:38:19 +02:00
has_rich_text :body
has_rich_text :guardian_clause
2020-07-07 23:14:42 +02:00
has_rich_text :signature_legal_text
2020-07-27 10:17:56 +00:00
has_rich_text :amendment_clause
2020-08-20 06:50:51 +02:00
has_rich_text :exhibit_a_legal_text
has_rich_text :exhibit_b_legal_text
has_rich_text :questionnaire_legal_text
2020-05-31 22:38:19 +02:00
validates :name, presence: true
validates :release_type, presence: true
2020-09-16 05:39:08 +02:00
validates :fee_old_cents, numericality: {
2020-05-31 22:38:19 +02:00
greater_than_or_equal_to: 0,
less_than_or_equal_to: 99_999_999_99
}
pg_search_scope :search, {
against: [:name, :release_type],
associated_against: {project: [:name]},
using: {
tsearch: {any_word: true, prefix: true},
trigram: {},
dmetaphone: {any_word: true}
}
}
scope :non_archived, -> { where(archived_at: nil) }
scope :order_by_name, -> { order(:name) }
2020-07-14 14:10:30 +02:00
enum accessibility: [:public_template, :private_template]
2020-05-31 22:38:19 +02:00
def fee?
2020-09-16 05:39:08 +02:00
fee.present?
end
def fee_old?
!fee_old.zero?
2020-05-31 22:38:19 +02:00
end
def releases
public_send("#{release_type}_releases")
end
def duplicated?
parent.present?
end
2020-06-18 16:56:11 +02:00
def archived?
archived_at.present?
end
2020-05-31 22:38:19 +02:00
def archive
update(archived_at: Time.zone.now)
end
2020-07-03 10:23:03 +02:00
def has_questionnaire?
(1..NUMBER_OF_CUSTOM_FIELDS).any? { |n| public_send("question_#{n}_text").presence }
end
2020-07-14 14:10:30 +02:00
2020-08-20 06:50:51 +02:00
def has_exhibit_a?
exhibit_a_legal_text.present?
end
def has_exhibit_b?
exhibit_b_legal_text.present?
end
2020-07-16 17:27:57 +02:00
def editable?
releases.size.zero?
end
2020-07-14 14:10:30 +02:00
def attributes
result = super()
2020-07-16 17:27:57 +02:00
result[:signature_legal_text] = signature_legal_text.as_json
2020-07-14 14:10:30 +02:00
result
end
2020-05-31 22:38:19 +02:00
end