Class: Shipment
- Inherits:
-
Request
- Object
- ActiveRecord::Base
- ApplicationRecord
- Request
- Shipment
- 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
-
#postal_address ⇒ PostalAddress
Postal address extracted to another model.
Delegated Instance Attributes collapse
-
#shipment_type ⇒ Object
Alias for Event#shipment_type.
Instance Method Summary collapse
-
#can_cancel? ⇒ Boolean
Check is the shipment can still be canceled.
-
#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.
Methods inherited from Request
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
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
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_address ⇒ PostalAddress
Postal address extracted to another model
8 |
# File 'app/models/shipment.rb', line 8 belongs_to :postal_address, dependent: :destroy, autosave: true |
#shipment_type ⇒ Object
Alias for Event#shipment_type
78 |
# File 'app/models/shipment.rb', line 78 delegate :shipment_type, to: :event |