Class: Spree::Shipment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/shipment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#special_instructionsObject

Returns the value of attribute special_instructions.



15
16
17
# File 'app/models/spree/shipment.rb', line 15

def special_instructions
  @special_instructions
end

Instance Method Details

#costObject Also known as: amount

The adjustment amount associated with this shipment (if any.) Returns only the first adjustment to match the shipment but there should never really be more than one.



41
42
43
# File 'app/models/spree/shipment.rb', line 41

def cost
  adjustment ? adjustment.amount : 0
end

#editable_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/spree/shipment.rb', line 61

def editable_by?(user)
  !shipped?
end

#line_itemsObject



71
72
73
74
75
76
77
# File 'app/models/spree/shipment.rb', line 71

def line_items
  if order.complete? and Spree::Config[:track_inventory_levels]
    order.line_items.select { |li| inventory_units.map(&:variant_id).include?(li.variant_id) }
  else
    order.line_items
  end
end

#manifestObject



65
66
67
68
69
# File 'app/models/spree/shipment.rb', line 65

def manifest
  inventory_units.group_by(&:variant).map do |i|
    OpenStruct.new(:variant => i.first, :quantity => i.last.length)
  end
end

#shipped=(value) ⇒ Object



34
35
36
37
# File 'app/models/spree/shipment.rb', line 34

def shipped=(value)
  return unless value == '1' && shipped_at.nil?
  self.shipped_at = Time.now
end

#to_paramObject



28
29
30
31
32
# File 'app/models/spree/shipment.rb', line 28

def to_param
  self.number if self.number
  generate_shipment_number unless self.number
  self.number.to_s.to_url.upcase
end

#update!(order) ⇒ Object

Updates various aspects of the Shipment while bypassing any callbacks. Note that this method takes an explicit reference to the Order object. This is necessary because the association actually has a stale (and unsaved) copy of the Order and so it will not yield the correct results.



82
83
84
85
86
87
# File 'app/models/spree/shipment.rb', line 82

def update!(order)
  old_state = self.state
  new_state = determine_state(order)
  update_attribute_without_callbacks 'state', determine_state(order)
  after_ship if new_state == 'shipped' and old_state != 'shipped'
end