Class: MembershipsImport

Inherits:
Import
  • Object
show all
Includes:
Imports::Rollback, Imports::Validations
Defined in:
app/models/imports/memberships_import.rb

Constant Summary

Constants inherited from Import

Import::DATE_INPUT_FORMAT, Import::DATE_INPUT_FORMAT_WITH_TIME

Instance Method Summary collapse

Methods included from Imports::Validations

#valid_amount?, #valid_date?

Methods included from Imports::Rollback

#rollback_orders, #rollback_people

Methods inherited from Import

#attach_person, build, #cache_data, #create_person, #fail!, #hash_address, #headers, #import, #message, #parsed_rows, #perform, #recallable?, #rollback, #rows

Methods included from Imports::Processing

#csv_data, included, #s3_service, #time_zone_parser

Methods included from Imports::Status

#approve!, #caching!, #failed!, #failed?, #imported!, #importing!, included, #invalidate!, #pending!, #recalled!, #recalling!

Instance Method Details

#create_membership_type(parsed_row) ⇒ Object



26
27
28
29
30
31
32
# File 'app/models/imports/memberships_import.rb', line 26

def create_membership_type(parsed_row)
  membership_type = self.organization.membership_types.build({
    :name => parsed_row.membership_name
  })
  membership_type.plan = parsed_row.membership_plan
  membership_type
end

#create_order(parsed_row, person, membership_type) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/models/imports/memberships_import.rb', line 34

def create_order(parsed_row, person, membership_type)
  #get order from hash
  # for 0 to parsed_row.number_of_memberships
       # create an item for this membership_type
  #add the item to the order
  #save the order
  #update get_action
  #hash order by order key (person, membership_type, payment_method)
end

#kindObject



5
6
7
# File 'app/models/imports/memberships_import.rb', line 5

def kind
  "memberships"
end

#process(parsed_row) ⇒ Object



18
19
20
21
22
23
24
# File 'app/models/imports/memberships_import.rb', line 18

def process(parsed_row)
  row_valid?(parsed_row)
  membership_type        = create_membership_type(parsed_row)
  person                 = create_person(parsed_row)
  order                  = create_order(parsed_row, person, membership_type)
  actions                = create_actions(parsed_row, person, memberships_type)
end

#row_valid?(parsed_row) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



9
10
11
12
13
14
15
16
# File 'app/models/imports/memberships_import.rb', line 9

def row_valid?(parsed_row)
  raise Import::RowError, "No Amount included in this row: #{parsed_row.row}" if parsed_row.unparsed_amount.blank?
  raise Import::RowError, "Please include a first name, last name, email, or company name in this row: #{parsed_row.row}" unless attach_person(parsed_row).naming_details_available?
  raise Import::RowError, "Please include a payment method in this row: #{parsed_row.row}" if parsed_row.payment_method.blank?
  valid_amount? parsed_row.unparsed_amount      unless parsed_row.unparsed_amount.blank?
  valid_date?   parsed_row.order_date           unless parsed_row.order_date.blank?
  true
end