Files
openfoodnetwork/lib/tasks/sample_data/fee_factory.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

34 lines
766 B
Ruby

# frozen_string_literal: true
require "tasks/sample_data/logging"
module SampleData
class FeeFactory
include Logging
def create_samples(enterprises)
log "Creating fees:"
enterprises.each do |enterprise|
next if enterprise.enterprise_fees.present?
log "- #{enterprise.name} charges markup"
calculator = Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10)
create_fee(enterprise, calculator)
calculator.save!
end
end
private
def create_fee(enterprise, calculator)
fee = enterprise.enterprise_fees.new(
fee_type: "sales",
name: "markup",
inherits_tax_category: true,
)
fee.calculator = calculator
fee.save!
end
end
end