Class: Spree::Stock::OrderCounter

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/stock/order_counter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderCounter

Returns a new instance of OrderCounter


6
7
8
9
10
# File 'app/models/spree/stock/order_counter.rb', line 6

def initialize(order)
  @order = order
  @ordered_counts = count_line_items
  @assigned_counts = count_inventory_units
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order


4
5
6
# File 'app/models/spree/stock/order_counter.rb', line 4

def order
  @order
end

Instance Method Details

#assigned(variant) ⇒ Object


28
29
30
# File 'app/models/spree/stock/order_counter.rb', line 28

def assigned(variant)
  @assigned_counts[variant]
end

#ordered(variant) ⇒ Object


24
25
26
# File 'app/models/spree/stock/order_counter.rb', line 24

def ordered(variant)
  @ordered_counts[variant]
end

#remaining(variant) ⇒ Object


32
33
34
# File 'app/models/spree/stock/order_counter.rb', line 32

def remaining(variant)
  @ordered_counts[variant] - @assigned_counts[variant]
end

#remaining?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'app/models/spree/stock/order_counter.rb', line 20

def remaining?
  not variants_with_remaining.empty?
end

#variantsObject


12
13
14
# File 'app/models/spree/stock/order_counter.rb', line 12

def variants
  @ordered_counts.keys
end

#variants_with_remainingObject


16
17
18
# File 'app/models/spree/stock/order_counter.rb', line 16

def variants_with_remaining
  variants.select { |variant| remaining(variant) > 0 }
end