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 =
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 =
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
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#code ⇒ Object (readonly)
36 |
# File 'app/models/rma_reason_code.rb', line 36 validates :code, uniqueness: true, presence: true |
Class Method Details
.active ⇒ ActiveRecord::Relation<RmaReasonCode>
A relation of RmaReasonCodes that are active. Active Record Scope
60 |
# File 'app/models/rma_reason_code.rb', line 60 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
99 |
# File 'app/models/rma_reason_code.rb', line 99 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
98 |
# File 'app/models/rma_reason_code.rb', line 98 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
82 83 84 85 |
# File 'app/models/rma_reason_code.rb', line 82 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
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/rma_reason_code.rb', line 86 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
64 65 66 67 |
# File 'app/models/rma_reason_code.rb', line 64 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
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/rma_reason_code.rb', line 68 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
124 125 126 127 128 129 130 |
# File 'app/models/rma_reason_code.rb', line 124 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
108 109 110 |
# File 'app/models/rma_reason_code.rb', line 108 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
100 101 102 103 104 105 106 |
# File 'app/models/rma_reason_code.rb', line 100 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
112 113 114 115 116 |
# File 'app/models/rma_reason_code.rb', line 112 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
118 119 120 121 122 |
# File 'app/models/rma_reason_code.rb', line 118 def code_and_description s = "[#{code}] #{description.presence || name}" s += " (#{aliases.join(', ')})" if aliases.present? s end |
#product_categories ⇒ ActiveRecord::Relation<ProductCategory>
34 |
# File 'app/models/rma_reason_code.rb', line 34 has_and_belongs_to_many :product_categories |
#product_lines ⇒ ActiveRecord::Relation<ProductLine>
33 |
# File 'app/models/rma_reason_code.rb', line 33 has_and_belongs_to_many :product_lines |
#restocked_rma_items ⇒ ActiveRecord::Relation<RmaItem>
31 |
# File 'app/models/rma_reason_code.rb', line 31 has_many :restocked_rma_items, class_name: "RmaItem", foreign_key: "restocking_reason", primary_key: "code" |
#returned_rma_items ⇒ ActiveRecord::Relation<RmaItem>
30 |
# File 'app/models/rma_reason_code.rb', line 30 has_many :returned_rma_items, class_name: "RmaItem", foreign_key: "returned_reason", primary_key: "code" |
#should_archive? ⇒ Boolean
136 137 138 |
# File 'app/models/rma_reason_code.rb', line 136 def should_archive? returned_rma_items.present? || restocked_rma_items.present? end |
#to_s ⇒ Object
132 133 134 |
# File 'app/models/rma_reason_code.rb', line 132 def to_s code_and_description end |