Class: Shipment

Inherits:
Request show all
Defined in:
app/models/shipment.rb

Overview

Request from a user to receive a merchandising box for a designated event

State Machines

This class contains 1 state machine(s).

state

Instance Attribute Summary

Attributes inherited from Request

#contact_phone_number, #created_at, #description, #state, #state_updated_at, #type, #updated_at, #visa_letter

Belongs to collapse

Delegated Instance Attributes collapse

Instance Method Summary collapse

Methods inherited from Request

#event

Methods included from HasState

#active?, #assigned_roles, #can_be_destroyed?, #cancel, #editable?, #human_state_description, #human_state_guide, #in_final_state?, #in_initial_state?, #label, #notify_state, #title, #with_transitions?

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Method Details

#can_cancel?Boolean

Check is the shipment can still be canceled

Returns:

  • (Boolean)

    true if it have not been sent yet



83
84
85
# File 'app/models/shipment.rb', line 83

def can_cancel?
  %i[incomplete submitted approved].include? state.to_sym
end

#populate_contact_info(contact = user) ⇒ Object

Populate some fields with information read from the event and the user profile, creating the associated PostalAddress object if it's missing

Parameters:

  • contact (User) (defaults to: user)

    user to read the information from. By default, the one associated to the request.



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/shipment.rb', line 92

def populate_contact_info(contact = user)
  build_postal_address if postal_address.nil?
  postal_address.country_code ||= event.country_code unless event.nil?
  return unless contact

  profile = contact.profile
  # Phone number
  self.contact_phone_number ||= profile.phone_number
  self.contact_phone_number = profile.second_phone_number if contact_phone_number.blank?
  # Name
  postal_address.name ||= profile.full_name
  postal_address.name = contact.nickname if postal_address.name.blank?
end

#postal_addressPostalAddress

Postal address extracted to another model



8
# File 'app/models/shipment.rb', line 8

belongs_to :postal_address, dependent: :destroy, autosave: true

#shipment_typeObject

Alias for Event#shipment_type

Returns:

  • (Object)

    Event#shipment_type

See Also:



78
# File 'app/models/shipment.rb', line 78

delegate :shipment_type, to: :event