Module: Models::ShipMeasurable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Delivery, ShipQuotable, StandaloneDelivery
- Defined in:
- app/concerns/models/ship_measurable.rb
Instance Method Summary collapse
- #cartons_total ⇒ Object
- #crates_total ⇒ Object
- #pallets_total ⇒ Object
- #ship_freight_class_from_shipments ⇒ Object
- #ship_volume_from_shipments ⇒ Object
- #ship_volume_from_shipments_in_cubic_feet ⇒ Object
- #ship_weight_from_shipments ⇒ Object
-
#shipment_set ⇒ Object
Shipments in complete/awaiting_label stage take precedence over packed shipments which take precedence over suggested shipments.
-
#shipments_for_measure ⇒ Object
Returns the shipments to use for measurements.
Instance Method Details
#cartons_total ⇒ Object
56 57 58 |
# File 'app/concerns/models/ship_measurable.rb', line 56 def cartons_total shipment_set.cartons.size end |
#crates_total ⇒ Object
64 65 66 |
# File 'app/concerns/models/ship_measurable.rb', line 64 def crates_total shipment_set.crates.size end |
#pallets_total ⇒ Object
60 61 62 |
# File 'app/concerns/models/ship_measurable.rb', line 60 def pallets_total shipment_set.where(container_type: %i[pallet palleted_crate]).count end |
#ship_freight_class_from_shipments ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/concerns/models/ship_measurable.rb', line 41 def ship_freight_class_from_shipments return unless swfs = ship_weight_from_shipments return unless svs = ship_volume_from_shipments_in_cubic_feet pcf = swfs / svs freight_class = nil Shipping::UpsFreight::FREIGHT_CLASS_BY_PCF.each do |fc, pcf_limits| if pcf >= pcf_limits[:lower] && pcf < pcf_limits[:upper] freight_class = fc.to_i break end end freight_class end |
#ship_volume_from_shipments ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/concerns/models/ship_measurable.rb', line 29 def ship_volume_from_shipments vol = nil if shipments_for_measure.present? && shipments_for_measure.all?(&:volume) vol = shipments_for_measure.map(&:volume).sum end vol end |
#ship_volume_from_shipments_in_cubic_feet ⇒ Object
37 38 39 |
# File 'app/concerns/models/ship_measurable.rb', line 37 def ship_volume_from_shipments_in_cubic_feet (svs = ship_volume_from_shipments) ? svs / 1728.0 : nil end |
#ship_weight_from_shipments ⇒ Object
25 26 27 |
# File 'app/concerns/models/ship_measurable.rb', line 25 def ship_weight_from_shipments shipments_for_measure.sum(:weight) end |
#shipment_set ⇒ Object
Shipments in complete/awaiting_label stage take precedence over packed shipments which take precedence over suggested shipments
10 11 12 13 14 |
# File 'app/concerns/models/ship_measurable.rb', line 10 def shipment_set shipments.where(state: %w[awaiting_label label_complete manually_complete]).presence || shipments.packed.presence || shipments.suggested end |
#shipments_for_measure ⇒ Object
Returns the shipments to use for measurements. Cartons are used by default, unless none are defined then we'll use the pallet
TODO: once pallets are defined with boxes, use the pallet weight and volume
19 20 21 22 |
# File 'app/concerns/models/ship_measurable.rb', line 19 def shipments_for_measure # We only use top level shipments, ie shipments that are not contained in other shipments/pallets shipments_to_use = shipment_set.top_level end |