Class: Comee::Core::PurchaseOrderItem

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



62
63
64
65
66
67
# File 'app/models/comee/core/purchase_order_item.rb', line 62

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

.ransackable_attributes(_auth_object = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/comee/core/purchase_order_item.rb', line 47

def self.ransackable_attributes(_auth_object = nil)
  %w[
    id
    purchase_order_id
    unit_id
    quantity
    confirmed_quantity
    price
    confirmed_price
    delivery_date
    confirmed_delivery_date
    status
  ]
end

Instance Method Details

#calculate_confirmation_valuesObject



29
30
31
32
33
34
35
36
37
# File 'app/models/comee/core/purchase_order_item.rb', line 29

def calculate_confirmation_values
  self.confirmed_price = price unless confirmed_price

  self.confirmed_quantity = quantity unless confirmed_quantity

  self.confirmed_delivery_date = delivery_date unless confirmed_delivery_date

  self.confirmed_total_price = (confirmed_price * confirmed_quantity).round(2)
end

#calculate_total_priceObject



25
26
27
# File 'app/models/comee/core/purchase_order_item.rb', line 25

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

#update_purchase_orderObject



39
40
41
42
43
44
45
# File 'app/models/comee/core/purchase_order_item.rb', line 39

def update_purchase_order
  purchase_order.calculate_total_price
  purchase_order.calculate_vat
  purchase_order.calculate_confirmed_total_price
  purchase_order.calculate_confirmed_vat
  purchase_order.save!
end