Class: Comee::Core::CustomerOrderItem

Inherits:
ApplicationRecord show all
Defined in:
app/models/comee/core/customer_order_item.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



36
37
38
# File 'app/models/comee/core/customer_order_item.rb', line 36

def self.ransackable_associations(_auth_object = nil)
  %w[customer_order product unit]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



32
33
34
# File 'app/models/comee/core/customer_order_item.rb', line 32

def self.ransackable_attributes(_auth_object = nil)
  %w[id customer_order_id product_id unit_id customer_item_no customer_item_description delivery_date]
end

Instance Method Details

#calculate_total_priceObject



17
18
19
# File 'app/models/comee/core/customer_order_item.rb', line 17

def calculate_total_price
  self.total_price = (price * quantity).round(2)
end

#fetch_customer_item_aliasObject



21
22
23
24
25
26
27
28
29
30
# File 'app/models/comee/core/customer_order_item.rb', line 21

def fetch_customer_item_alias
  self.customer_item_alias = "" unless customer_order && product_id
  client_id = customer_order.client.parent_id || customer_order.client_id
  lookup = ProductLookup.find_by(
    itemable_id: client_id,
    itemable_type: "Comee::Core::Client",
    product_id: product_id
  )
  self.customer_item_alias = lookup&.aliases
end