Class: AssortmentInstruction

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/assortment_instruction.rb

Overview

== Schema Information

Table name: assortment_instructions
Database name: primary

id :integer not null, primary key
active :boolean default(TRUE)
final_rule :boolean default(TRUE)
instruction_type :string not null
position :integer
title :string
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
customer_filter_id :integer
email_template_id :integer
updater_id :integer

Indexes

index_assortment_instructions_on_customer_filter_id (customer_filter_id)
index_assortment_instructions_on_instruction_type (instruction_type)

Foreign Keys

fk_rails_... (customer_filter_id => customer_filters.id)
fk_rails_... (email_template_id => email_templates.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Has and belongs to many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.activeActiveRecord::Relation<AssortmentInstruction>

A relation of AssortmentInstructions that are active. Active Record Scope

Returns:

See Also:



48
# File 'app/models/assortment_instruction.rb', line 48

scope :active, -> { where(active: true) }

.for_customerActiveRecord::Relation<AssortmentInstruction>

A relation of AssortmentInstructions that are for customer. Active Record Scope

Returns:

See Also:



49
# File 'app/models/assortment_instruction.rb', line 49

scope :for_customer, ->(customer) { where(customer_filter_id: CustomerFilter::QueryBuilder.filter_ids_for_customer(customer)).order(:position) }

.instruction_types_for_selectObject



54
55
56
# File 'app/models/assortment_instruction.rb', line 54

def self.instruction_types_for_select
  instruction_types.invert.keys.map{|k| [k.to_s.humanize.titleize, k] }
end

.sortedActiveRecord::Relation<AssortmentInstruction>

A relation of AssortmentInstructions that are sorted. Active Record Scope

Returns:

See Also:



50
# File 'app/models/assortment_instruction.rb', line 50

scope :sorted, -> { order(:position)}

Instance Method Details

#customer_filterCustomerFilter



32
# File 'app/models/assortment_instruction.rb', line 32

belongs_to :customer_filter, optional: true

#email_templateEmailTemplate



33
# File 'app/models/assortment_instruction.rb', line 33

belongs_to :email_template, optional: true

#itemsActiveRecord::Relation<Item>

for publications

Returns:

  • (ActiveRecord::Relation<Item>)

See Also:



35
# File 'app/models/assortment_instruction.rb', line 35

has_and_belongs_to_many :items, inverse_of: :assortment_instructions

#line_items_qualify?(line_items) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/assortment_instruction.rb', line 58

def line_items_qualify?(line_items)
  ProductFilter::LineQualifier.new(line_items, product_filters).qualifying_line_items?
end

#product_filtersActiveRecord::Relation<ProductFilter>

Returns:

See Also:



34
# File 'app/models/assortment_instruction.rb', line 34

has_many :product_filters, dependent: :destroy, inverse_of: :assortment_instruction