Class: VariableCost

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/variable_cost.rb

Overview

== Schema Information

Table name: variable_costs
Database name: primary

id :integer not null, primary key
freight_allowance :float
group_type :string not null
marketing_allowance_frequency :float
marketing_services :float
mdf :float
name :string not null
net_terms :float
others :float
penalties_back_charges :float
promotions :float
rebate_ptg :float
return_allowance :float
tradeshow :float
travel_expenses :float
created_at :datetime not null
updated_at :datetime not null
creator_id :integer
updater_id :integer

Indexes

index_variable_costs_on_group_type (group_type)
index_variable_costs_on_name (name)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#group_typevoid (readonly)

This method returns an undefined value.



35
# File 'app/models/variable_cost.rb', line 35

validates :group_type, :name, presence: true

#namevoid (readonly)

This method returns an undefined value.

Validations:



35
# File 'app/models/variable_cost.rb', line 35

validates :group_type, :name, presence: true

Class Method Details

.populate_from_datavoid

This method returns an undefined value.

Imports variable costs from data/variable_cost.csv.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/variable_cost.rb', line 39

def self.populate_from_data
  file_path = Rails.root.join("data/variable_cost.csv")
  counter = 0
  CSV.foreach(file_path, headers: true) do |row|
    group_type = row['group_type'].presence
    name = row['name'].presence
    rebate_ptg = row['rebate_ptg'].presence
    marketing_allowance_frequency = row['marketing_allowance_frequency'].presence
    freight_allowance = row['freight_allowance'].presence
    return_allowance = row['return_allowance'].presence
    net_terms = row['net_terms'].presence
    marketing_services = row['marketing_services'].presence
    mdf = row['mdf'].presence
    promotions = row['promotions'].presence
    penalties_back_charges = row['penalties_back_charges'].presence
    tradeshow = row['tradeshow'].presence
    travel_expenses = row['travel_expenses'].presence

    new_vc = VariableCost.create(group_type: group_type.presence,
                                  name: name.presence,
                                  rebate_ptg: rebate_ptg.presence,
                                  marketing_allowance_frequency: marketing_allowance_frequency.presence,
                                  freight_allowance: freight_allowance.presence,
                                  return_allowance: return_allowance.presence,
                                  net_terms: net_terms.presence,
                                  marketing_services: marketing_services.presence,
                                  mdf: mdf.presence,
                                  promotions: promotions.presence,
                                  penalties_back_charges: penalties_back_charges.presence,
                                  tradeshow: tradeshow.presence,
                                  travel_expenses: travel_expenses.presence)

    puts new_vc.errors.full_messages if new_vc.errors.any?
    counter += 1 if new_vc.persisted?
  end
  puts "Imported #{counter} variable costs."
end