Class: Shipment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Shipment
- Defined in:
- app/models/shipment.rb
Instance Attribute Summary collapse
-
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
Instance Method Summary collapse
-
#cost ⇒ Object
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.
- #editable_by?(user) ⇒ Boolean
- #line_items ⇒ Object
- #manifest ⇒ Object
- #shipped=(value) ⇒ Object
- #to_param ⇒ Object
-
#update!(order) ⇒ Object
Updates various aspects of the Shipment while bypassing any callbacks.
Instance Attribute Details
#special_instructions ⇒ Object
Returns the value of attribute special_instructions.
14 15 16 |
# File 'app/models/shipment.rb', line 14 def special_instructions @special_instructions end |
Instance Method Details
#cost ⇒ Object
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.
40 41 42 |
# File 'app/models/shipment.rb', line 40 def cost adjustment ? adjustment.amount : 0 end |
#editable_by?(user) ⇒ Boolean
59 60 61 |
# File 'app/models/shipment.rb', line 59 def editable_by?(user) !shipped? end |
#line_items ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/models/shipment.rb', line 70 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 |
#manifest ⇒ Object
63 64 65 66 67 |
# File 'app/models/shipment.rb', line 63 def manifest inventory_units.group_by(&:variant).map do |i| OpenStruct.new(:variant => i.first, :quantity => i.last.length) end end |
#shipped=(value) ⇒ Object
33 34 35 36 |
# File 'app/models/shipment.rb', line 33 def shipped=(value) return unless value == "1" && shipped_at.nil? self.shipped_at = Time.now end |
#to_param ⇒ Object
27 28 29 30 31 |
# File 'app/models/shipment.rb', line 27 def to_param self.number if self.number generate_shipment_number unless self.number self.number.parameterize.to_s.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.
81 82 83 84 85 86 |
# File 'app/models/shipment.rb', line 81 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 |