Class: ViewRma

Inherits:
ApplicationViewRecord show all
Includes:
Models::SearchableView, Models::SearchableViewWithRmaItems, PgSearch::Model
Defined in:
app/models/view_rma.rb

Overview

== Schema Information

Table name: view_rmas
Database name: primary

id :integer primary key
actual_rma_credit :decimal(, )
arrival_date :date
awaiting_return :boolean
company_name :string(255)
contact_name :string(255)
creator_full_name :string(255)
credited_date :date
customer_full_name :string(255)
customer_reference :string(255)
description :text
estimated_rma_credit :decimal(, )
original_invoice_reference_number :string(255)
original_order_reference_number :string(255)
original_po_number :string(255)
primary_sales_rep_full_name :string(255)
returned_date :date
returned_reasons :string(255) is an Array
rma_number :string(255)
state :string(255)
tracking_numbers :string is an Array
transmission_state :string(255)
created_at :datetime
updated_at :datetime
company_id :integer
creator_id :integer
customer_id :integer
original_invoice_id :integer
original_order_id :integer
primary_sales_rep_id :integer
return_delivery_id :integer

Belongs to collapse

Has many collapse

Class Method Summary collapse

Methods included from Models::SearchableViewWithRmaItems

contains_rma_item_ids

Methods included from Models::SearchableView

#crm_link, #crm_link_subtitle, #has_columns?, #main_resource, #readonly?

Methods inherited from ApplicationViewRecord

create, create!, #readonly?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.contains_tracking_numberActiveRecord::Relation<ViewRma>

A relation of ViewRmas that are contains tracking number. Active Record Scope

Returns:

  • (ActiveRecord::Relation<ViewRma>)

See Also:



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

scope :contains_tracking_number, ->(tracking_number) { joins(:return_shipments).where(ViewRma[:tracking_numbers].any(tracking_number).or(Shipment[:tracking_number].eq(tracking_number))) }

.ransackable_scopes(_auth_object = nil) ⇒ Object



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

def self.ransackable_scopes(_auth_object = nil)
  super + %i[customer_full_name_search customer_reference_search original_po_search
             contains_tracking_number returned_reasons]
end

.returned_reasonsActiveRecord::Relation<ViewRma>

A relation of ViewRmas that are returned reasons. Active Record Scope

Returns:

  • (ActiveRecord::Relation<ViewRma>)

See Also:



50
51
52
# File 'app/models/view_rma.rb', line 50

scope :returned_reasons, ->(reasons) {
  where('exists(select 1 from rma_items ri where ri.rma_id = view_rmas.id and ri.returned_reason IN (?))', Array(reasons))
}

Instance Method Details

#return_deliveryDelivery

Returns:

See Also:



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

belongs_to :return_delivery, class_name: 'Delivery', optional: true

#return_shipmentsActiveRecord::Relation<Shipment>

Returns:

See Also:



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

has_many :return_shipments, -> { label_complete }, source: :shipments, class_name: 'Shipment', through: :return_delivery

#rma_itemsActiveRecord::Relation<RmaItem>

Returns:

  • (ActiveRecord::Relation<RmaItem>)

See Also:



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

has_many :rma_items, foreign_key: :rma_id