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 :enum 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

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#customer_filter_idObject (readonly)



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

validates :customer_filter_id, :email_template_id, :title, presence: true

#email_template_idObject (readonly)



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

validates :customer_filter_id, :email_template_id, :title, presence: true

#titleObject (readonly)



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

validates :customer_filter_id, :email_template_id, :title, presence: true

Class Method Details

.activeActiveRecord::Relation<AssortmentInstruction>

A relation of AssortmentInstructions that are active. Active Record Scope

Returns:

See Also:



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

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

.for_customerActiveRecord::Relation<AssortmentInstruction>

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

Returns:

See Also:



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

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

.instruction_types_for_selectObject



64
65
66
# File 'app/models/assortment_instruction.rb', line 64

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:



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

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

Instance Method Details

#customer_filterCustomerFilter



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

belongs_to :customer_filter, optional: true

#email_templateEmailTemplate



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

belongs_to :email_template, optional: true

#itemsActiveRecord::Relation<Item>

for publications

Returns:

  • (ActiveRecord::Relation<Item>)

See Also:



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

has_and_belongs_to_many :items, inverse_of: :assortment_instructions

#line_items_qualify?(line_items) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/assortment_instruction.rb', line 68

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

#product_filtersActiveRecord::Relation<ProductFilter>

Returns:

See Also:

Validations:



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

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

#to_partial_pathObject

Partial lives under app/views/crm/assortment_instructions/, not the
conventional app/views/assortment_instructions/. Override so
render @assortment_instructions resolves correctly from any
controller, not just Crm::AssortmentInstructionsController.



37
38
39
# File 'app/models/assortment_instruction.rb', line 37

def to_partial_path
  'crm/assortment_instructions/assortment_instruction'
end