Class: Accountability::OrderGroup

Inherits:
ApplicationRecord show all
Defined in:
app/models/accountability/order_group.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

validates_attributes

Instance Method Details

#accrue_credits!Object



26
27
28
29
30
# File 'app/models/accountability/order_group.rb', line 26

def accrue_credits!
  return unless complete?

  order_items.each(&:accrue_credit!)
end

#add_item!(product, source_scope: nil) ⇒ Object

The ‘product` parameter accepts Product, String, and Integer objects



37
38
39
40
41
# File 'app/models/accountability/order_group.rb', line 37

def add_item!(product, source_scope: nil)
  product = Product.find(product) unless product.is_a? Product

  order_items.create! product: product, source_scope: source_scope.presence
end

#assign_account!(account) ⇒ Object



47
48
49
# File 'app/models/accountability/order_group.rb', line 47

def assign_account!()
  update! account: 
end

#checkout!Object



15
16
17
18
19
20
21
22
23
24
# File 'app/models/accountability/order_group.rb', line 15

def checkout!
  trigger_callback :before_checkout

  transaction do
    complete!
    accrue_credits!

    trigger_callback :after_checkout
  end
end

#raw_totalObject



32
33
34
# File 'app/models/accountability/order_group.rb', line 32

def raw_total
  order_items.sum(&:default_price)
end

#unassigned?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/accountability/order_group.rb', line 43

def unassigned?
  .nil?
end