Class: Comee::Core::BackOrder

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



20
21
22
# File 'app/models/comee/core/back_order.rb', line 20

def self.ransackable_associations(_auth_object = nil)
  []
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



16
17
18
# File 'app/models/comee/core/back_order.rb', line 16

def self.ransackable_attributes(_auth_object = nil)
  %w[id delivery_address delivery_date invoice_address order_date order_number status supplier_id]
end

Instance Method Details

#confirmObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/comee/core/back_order.rb', line 24

def confirm
  raise "Order already confirmed." if BackOrder.statuses[status] == BackOrder.statuses[:confirmed]

  raise "Order should be in submitted state first." if BackOrder.statuses[status] != BackOrder.statuses[:submitted]

  self.status = BackOrder.statuses[:confirmed]
  back_order_items.each do |item|
    if item.supplier_unit_price == item.requested_unit_price
      self.price_changed = true
      break
    end
  end
  save!
end

#submitObject



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

def submit
  unless BackOrder.statuses[status] == BackOrder.statuses[:draft]
    raise(StandardError,
          "Back order can't be submitted if it is not in draft state.")
  end

  self.status = BackOrder.statuses[:submitted]
  save
end