Class: SpreeCmCommissioner::PriceLists::Create

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/price_lists/create.rb

Instance Method Summary collapse

Instance Method Details

#call(params:, agency:, vendor:, user:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/spree_cm_commissioner/price_lists/create.rb', line 6

def call(params:, agency:, vendor:, user:)
  channel_type = resolve_channel_type(user)
  managed_by = resolve_managed_by(user, channel_type)
  list_type = resolve_list_type(user, managed_by)

  record = SpreeCmCommissioner::PriceList.new(
    vendor: vendor,
    agency: agency,
    channel_type: channel_type,
    name: params[:name],
    code: params[:code],
    list_type: params[:list_type] || list_type,
    managed_by: params[:managed_by] || managed_by,
    margin_basis: params[:margin_basis],
    status: params[:status],
    default_margin_type: params[:default_margin_type],
    default_margin_value: params[:default_margin_value],
    default_settlement_basis: params[:default_settlement_basis]
  )

  if record.save
    success(price_list: record)
  else
    failure(record, record.errors.full_messages.join(', '))
  end
end