Class: RmaReasonCode
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RmaReasonCode
- Defined in:
- app/models/rma_reason_code.rb
Overview
== Schema Information
Table name: rma_reason_codes
Database name: primary
id :integer not null, primary key
active :boolean default(TRUE), not null
advanced_reason_code :boolean default(FALSE), not null
aliases :string default([]), is an Array
category :string(255)
code :string(255)
customer_fault :boolean
default_location :string(255)
description :text
name :string(255)
replacement_order_type :string(2) default("TO")
created_at :datetime
updated_at :datetime
creator_id :integer
updater_id :integer
Indexes
index_rma_reason_codes_on_aliases (aliases) USING gin
index_rma_reason_codes_on_code (code) UNIQUE
index_rma_reason_codes_on_customer_fault (customer_fault)
Constant Summary collapse
- EMPTY_PL_SQL =
%{ NOT EXISTS( SELECT 1 FROM product_lines_rma_reason_codes plrrc WHERE plrrc.rma_reason_code_id = rma_reason_codes.id ) }.freeze
- EMPTY_PC_SQL =
%{ NOT EXISTS( SELECT 1 FROM product_categories_rma_reason_codes pcrrc WHERE pcrrc.rma_reason_code_id = rma_reason_codes.id )}.freeze
Instance Attribute Summary collapse
- #code ⇒ Object readonly
Has many collapse
- #restocked_rma_items ⇒ ActiveRecord::Relation<RmaItem>
- #returned_rma_items ⇒ ActiveRecord::Relation<RmaItem>
Has and belongs to many collapse
- #product_categories ⇒ ActiveRecord::Relation<ProductCategory>
- #product_lines ⇒ ActiveRecord::Relation<ProductLine>
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are active.
-
.for_any_product_categories ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for any product categories.
-
.for_any_product_lines ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for any product lines.
-
.for_product_category_ids ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product category ids.
-
.for_product_category_ids_exact ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product category ids exact.
-
.for_product_line_ids ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product line ids.
-
.for_product_line_ids_exact ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product line ids exact.
- .for_select(include_advanced: true) ⇒ Object
- .ransackable_scopes(_auth_object = nil) ⇒ Object
-
.search_code_or_desc ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are search code or desc.
- .select_options(include_advanced: true) ⇒ Object
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#code ⇒ Object (readonly)
35 |
# File 'app/models/rma_reason_code.rb', line 35 validates :code, uniqueness: true, presence: true |
Class Method Details
.active ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are active. Active Record Scope
57 |
# File 'app/models/rma_reason_code.rb', line 57 scope :active, -> { where(active: true) } |
.for_any_product_categories ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for any product categories. Active Record Scope
98 99 100 |
# File 'app/models/rma_reason_code.rb', line 98 scope :for_any_product_categories, -> { where(EMPTY_PC_SQL) } |
.for_any_product_lines ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for any product lines. Active Record Scope
95 96 97 |
# File 'app/models/rma_reason_code.rb', line 95 scope :for_any_product_lines, -> { where(EMPTY_PL_SQL) } |
.for_product_category_ids ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product category ids. Active Record Scope
79 80 81 82 |
# File 'app/models/rma_reason_code.rb', line 79 scope :for_product_category_ids, ->(*ids) { all_ids = ProductCategory.self_and_ancestors_ids(ids.flatten) for_product_category_ids_exact(all_ids) } |
.for_product_category_ids_exact ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product category ids exact. Active Record Scope
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/rma_reason_code.rb', line 83 scope :for_product_category_ids_exact, ->(*ids) { where(%{ EXISTS( SELECT 1 FROM product_categories_rma_reason_codes pcrrc WHERE pcrrc.rma_reason_code_id = rma_reason_codes.id AND pcrrc.product_category_id IN (:product_category_ids) ) OR #{EMPTY_PC_SQL} }, product_category_ids: ids.flatten) } |
.for_product_line_ids ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product line ids. Active Record Scope
61 62 63 64 |
# File 'app/models/rma_reason_code.rb', line 61 scope :for_product_line_ids, ->(*ids) { all_ids = ProductLine.self_and_ancestors_ids(ids.flatten) for_product_line_ids_exact(all_ids) } |
.for_product_line_ids_exact ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are for product line ids exact. Active Record Scope
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/rma_reason_code.rb', line 65 scope :for_product_line_ids_exact, ->(*ids) { where(%{ EXISTS( SELECT 1 FROM product_lines_rma_reason_codes plrrc WHERE plrrc.rma_reason_code_id = rma_reason_codes.id AND plrrc.product_line_id IN (:product_line_ids) ) OR #{EMPTY_PL_SQL} }, product_line_ids: ids.flatten) } |
.for_select(include_advanced: true) ⇒ Object
125 126 127 128 129 130 131 |
# File 'app/models/rma_reason_code.rb', line 125 def self.for_select(include_advanced: true) rrcs = RmaReasonCode.active rrcs = rrcs.where.not(advanced_reason_code: true) unless include_advanced rrcs.map do |e| [e.code_and_description, e.code, { 'data-default-location' => e.default_location }] end end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
109 110 111 |
# File 'app/models/rma_reason_code.rb', line 109 def self.ransackable_scopes(_auth_object = nil) %i[search_code_or_desc for_product_category_ids for_product_line_ids] end |
.search_code_or_desc ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are search code or desc. Active Record Scope
101 102 103 104 105 106 107 |
# File 'app/models/rma_reason_code.rb', line 101 scope :search_code_or_desc, ->(term) { where(%( code = :code OR description ILIKE :description OR name ILIKE :description ), code: term.upcase, description: "%#{term}%") } |
.select_options(include_advanced: true) ⇒ Object
113 114 115 116 117 |
# File 'app/models/rma_reason_code.rb', line 113 def self.(include_advanced: true) rrcs = RmaReasonCode.active rrcs = rrcs.where.not(advanced_reason_code: true) unless include_advanced rrcs.order(:code).map { |r| [r.to_s, r.code] } end |
Instance Method Details
#code_and_description ⇒ Object
119 120 121 122 123 |
# File 'app/models/rma_reason_code.rb', line 119 def code_and_description s = "[#{code}] #{description.presence || name}" s << " (#{aliases.join(', ')})" if aliases.present? s end |
#product_categories ⇒ ActiveRecord::Relation<ProductCategory>
33 |
# File 'app/models/rma_reason_code.rb', line 33 has_and_belongs_to_many :product_categories |
#product_lines ⇒ ActiveRecord::Relation<ProductLine>
32 |
# File 'app/models/rma_reason_code.rb', line 32 has_and_belongs_to_many :product_lines |
#restocked_rma_items ⇒ ActiveRecord::Relation<RmaItem>
30 |
# File 'app/models/rma_reason_code.rb', line 30 has_many :restocked_rma_items, class_name: "RmaItem", foreign_key: "restocking_reason", primary_key: "code" |
#returned_rma_items ⇒ ActiveRecord::Relation<RmaItem>
29 |
# File 'app/models/rma_reason_code.rb', line 29 has_many :returned_rma_items, class_name: "RmaItem", foreign_key: "returned_reason", primary_key: "code" |
#should_archive? ⇒ Boolean
137 138 139 |
# File 'app/models/rma_reason_code.rb', line 137 def should_archive? returned_rma_items.present? || restocked_rma_items.present? end |
#to_s ⇒ Object
133 134 135 |
# File 'app/models/rma_reason_code.rb', line 133 def to_s code_and_description end |