Module: Models::Packable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Delivery
- Defined in:
- app/concerns/models/packable.rb
Overview
ActiveSupport::Concern mixin: packable.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #calculate_actual_insured_value ⇒ Object
- #carrier ⇒ Object
- #carrier_fedex? ⇒ Boolean
- #delivery_description(include_line_items = false) ⇒ Object
- #domestic? ⇒ Boolean
- #has_supported_carrier? ⇒ Boolean
- #is_goods_shipping? ⇒ Boolean
- #is_onsite_service_only? ⇒ Boolean
- #is_remote_service_only? ⇒ Boolean
- #is_service_only? ⇒ Boolean
- #is_warehouse_ca_pickup? ⇒ Boolean
- #is_warehouse_pickup? ⇒ Boolean
- #is_warehouse_us_pickup? ⇒ Boolean
- #is_zero_charge_dropship? ⇒ Boolean
- #must_be_insured? ⇒ Boolean
- #must_be_signature_confirmation? ⇒ Boolean
-
#search_deliveries_for_equivalent_packaging ⇒ Object
This populates our shipments.
- #ship_weight ⇒ Object (also: #line_item_ship_weight)
- #ships_from_text ⇒ Object
- #subtotal ⇒ Object
- #subtotal_cogs ⇒ Object
- #subtotal_for_commercial_invoice ⇒ Object
- #subtotal_for_insured_value ⇒ Object
- #subtotal_for_ltl_threshold ⇒ Object
- #subtotal_msrp ⇒ Object
Instance Method Details
#calculate_actual_insured_value ⇒ Object
126 127 128 129 |
# File 'app/concerns/models/packable.rb', line 126 def calculate_actual_insured_value # Use the same logic as calculate_declared_value to ensure declared value matches calculated insured value line_items.goods.without_children.sum { |li| li.quantity * li.unit_value_for_commercial_invoice } end |
#carrier ⇒ Object
106 107 108 |
# File 'app/concerns/models/packable.rb', line 106 def carrier shipping_option&.carrier || shipments.first&.sanitized_carrier end |
#carrier_fedex? ⇒ Boolean
98 99 100 |
# File 'app/concerns/models/packable.rb', line 98 def carrier_fedex? shipping_option&.carrier == 'FedEx' && has_supported_carrier? end |
#delivery_description(include_line_items = false) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/concerns/models/packable.rb', line 64 def delivery_description(include_line_items = false) return 'service fulfilled remotely' if is_remote_service_only? return 'service fulfilled onsite' if is_onsite_service_only? return 'service fulfilled electronically' if is_service_only? line_items_desc = include_line_items ? "#{line_items.grouped_by_category.map { |_c, lis| lis.map(&:name).join(',') }.join(',')}, #{ship_weight} lbs of goods, " : '' if is_warehouse_pickup? "#{line_items_desc}to pick up from our warehouse in #{origin_address.city}, #{origin_address.state_code}, #{origin_address.country_printable_name}" else "#{line_items_desc}shipped from #{origin_address.city}, #{origin_address.state_code}, #{origin_address.country_printable_name}" end end |
#domestic? ⇒ Boolean
93 94 95 96 |
# File 'app/concerns/models/packable.rb', line 93 def domestic? country_iso3 = destination_address&.country_iso3 || resource.try(:installation_country_iso3) origin_address.country_iso3 == country_iso3 end |
#has_supported_carrier? ⇒ Boolean
102 103 104 |
# File 'app/concerns/models/packable.rb', line 102 def has_supported_carrier? supported_shipping_carrier? end |
#is_goods_shipping? ⇒ Boolean
59 60 61 |
# File 'app/concerns/models/packable.rb', line 59 def is_goods_shipping? !(is_warehouse_pickup? || is_service_only?) end |
#is_onsite_service_only? ⇒ Boolean
55 56 57 |
# File 'app/concerns/models/packable.rb', line 55 def is_onsite_service_only? is_service_only? && line_items.reject(&:marked_for_destruction?).any? { |li| li.sku.include?('ONSITE') } end |
#is_remote_service_only? ⇒ Boolean
51 52 53 |
# File 'app/concerns/models/packable.rb', line 51 def is_remote_service_only? is_service_only? && line_items.reject(&:marked_for_destruction?).any? { |li| li.sku.include?('REMOTE') } end |
#is_service_only? ⇒ Boolean
45 46 47 48 |
# File 'app/concerns/models/packable.rb', line 45 def is_service_only? items = line_items.reject(&:marked_for_destruction?) items.any?(&:is_service?) && items.none?(&:is_goods?) end |
#is_warehouse_ca_pickup? ⇒ Boolean
43 |
# File 'app/concerns/models/packable.rb', line 43 def is_warehouse_ca_pickup? = warehouse_pickup_for_country?('CA') |
#is_warehouse_pickup? ⇒ Boolean
28 29 30 31 32 33 |
# File 'app/concerns/models/packable.rb', line 28 def is_warehouse_pickup? return false unless (dest_addr = destination_address) # STs and returns are not warehouse pickups because we want to adjust shipping method if necessary dest_addr.is_warehouse && !store_transfer? && !is_rma_return? end |
#is_warehouse_us_pickup? ⇒ Boolean
42 |
# File 'app/concerns/models/packable.rb', line 42 def is_warehouse_us_pickup? = warehouse_pickup_for_country?('US') |
#is_zero_charge_dropship? ⇒ Boolean
35 36 37 38 39 |
# File 'app/concerns/models/packable.rb', line 35 def is_zero_charge_dropship? has_dropship_items? && !(order || quote)&.single_origin && line_items.goods.includes(item: :supplier_item).all? { |li| li.item.supplier_item.dropships_cost_for_customer_is_zero? } end |
#must_be_insured? ⇒ Boolean
135 136 137 |
# File 'app/concerns/models/packable.rb', line 135 def must_be_insured? line_items.without_children.must_be_shipped_insured.active_non_shipping_lines.any? end |
#must_be_signature_confirmation? ⇒ Boolean
139 140 141 |
# File 'app/concerns/models/packable.rb', line 139 def must_be_signature_confirmation? order&.payments&.&.any? { |pp| pp.category == Payment::PAYPAL && pp.amount > Payment::PAYPAL_MIN_SIGNATURE_REQUIRED } end |
#search_deliveries_for_equivalent_packaging ⇒ Object
This populates our shipments
19 20 21 |
# File 'app/concerns/models/packable.rb', line 19 def search_deliveries_for_equivalent_packaging Shipping::CreateSuggestedShipment.new.process(self) end |
#ship_weight ⇒ Object Also known as: line_item_ship_weight
23 24 25 |
# File 'app/concerns/models/packable.rb', line 23 def ship_weight @ship_weight ||= [0.1, line_items.includes(:item).non_shipping.parents_only.sum(&:total_shipping_weight).round(1)].max end |
#ships_from_text ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/concerns/models/packable.rb', line 79 def ships_from_text if is_remote_service_only? 'service fulfilled remotely' elsif is_onsite_service_only? 'service fulfilled onsite' elsif is_service_only? 'Services fulfilled electronically' elsif is_warehouse_pickup? "Pickup from our warehouse in #{origin_address.city}, #{origin_address.state_code}, #{origin_address.country_printable_name}" else "Ships from #{origin_address.city}, #{origin_address.state_code}. #{origin_address.country_printable_name}" end end |
#subtotal ⇒ Object
110 111 112 |
# File 'app/concerns/models/packable.rb', line 110 def subtotal line_items.active_non_shipping_lines.sum(&:discounted_total) end |
#subtotal_cogs ⇒ Object
122 123 124 |
# File 'app/concerns/models/packable.rb', line 122 def subtotal_cogs line_items.without_children.active_non_shipping_lines.sum(&:current_line_cogs) end |
#subtotal_for_commercial_invoice ⇒ Object
114 115 116 |
# File 'app/concerns/models/packable.rb', line 114 def subtotal_for_commercial_invoice line_items.parents_only.goods.sum { |li| li.quantity * li.unit_value_for_commercial_invoice } end |
#subtotal_for_insured_value ⇒ Object
131 132 133 |
# File 'app/concerns/models/packable.rb', line 131 def subtotal_for_insured_value line_items.without_children.must_be_shipped_insured.active_non_shipping_lines.sum(&:current_line_cogs) end |
#subtotal_for_ltl_threshold ⇒ Object
143 144 145 146 |
# File 'app/concerns/models/packable.rb', line 143 def subtotal_for_ltl_threshold # subtotal returns 0 on a before_save, this will return an actual msrp subtotal line_items.non_shipping.sum { |li| li.price * li.quantity }.round(1) end |
#subtotal_msrp ⇒ Object
118 119 120 |
# File 'app/concerns/models/packable.rb', line 118 def subtotal_msrp line_items.active_non_shipping_lines.sum(&:price_total) end |