Skip to content

Commit a2f7af6

Browse files
authored
Improve the Seeding of sofia accounts (#1201)
* generate better seeding files * intial commit message * fix suggestions * fix lint * fix lint
1 parent 4a331ed commit a2f7af6

File tree

2 files changed

+100
-18
lines changed

2 files changed

+100
-18
lines changed

db/seeds.rb

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,49 @@
1111
end
1212

1313
p 'Seeding users...'
14-
users = []
15-
4.times do
16-
users << FactoryBot.create(:user)
14+
# Nederlandse testnamen
15+
dutch_names = [
16+
'Jan de Vries',
17+
'Piet Bakker',
18+
'Lisa Jansen',
19+
'Emma van der Berg',
20+
'Daan Visser',
21+
'Sophie Smit',
22+
'Thomas Mulder',
23+
'Anna de Boer'
24+
]
25+
26+
users = dutch_names.map do |name|
27+
FactoryBot.create(:user, name:)
1728
end
1829
users << FactoryBot.create(:user, name: 'Benjamin Knopje', birthday: 16.years.ago)
1930

2031
p 'Seeding activities...'
21-
activities = []
22-
4.times do
23-
activities << FactoryBot.create(:activity, price_list: price_lists.sample, created_by: users.sample)
32+
# Recente activiteiten
33+
activity_names = %w[Donderdagborrel Vrijdagborrel ALV Kerstdiner Filmavond Bierproeverij]
34+
activities = activity_names.map do |title|
35+
FactoryBot.create(:activity, title:, price_list: price_lists.sample, created_by: users.sample)
36+
end
37+
38+
# Historische activiteiten (locked)
39+
p 'Seeding historical activities...'
40+
historical_activities = [
41+
{ title: 'Nieuwjaarsborrel', days_ago: 15 },
42+
{ title: 'Studiemiddag', days_ago: 30 },
43+
{ title: 'Kroegentocht', days_ago: 45 },
44+
{ title: 'Dies Natalis', days_ago: 90 }
45+
]
46+
47+
historical_activities.each do |hist_act|
48+
start_time = hist_act[:days_ago].days.ago.beginning_of_hour
49+
end_time = (hist_act[:days_ago] - 1).days.ago.beginning_of_hour
50+
activity = FactoryBot.create(:activity,
51+
title: hist_act[:title],
52+
start_time:,
53+
end_time:,
54+
price_list: price_lists.sample,
55+
created_by: users.sample)
56+
activities << activity
2457
end
2558

2659
p 'Seeding orders...'
@@ -32,9 +65,27 @@
3265
end
3366

3467
p 'Seeding credit mutations...'
68+
# Realistische credit mutations met variatie
69+
mutation_descriptions = [
70+
{ description: 'Opwaardering', amount_range: 10..50 },
71+
{ description: 'Contant gestort', amount_range: 5..30 },
72+
{ description: 'iDEAL betaling', amount_range: 10..100 },
73+
{ description: 'Correctie admin', amount_range: -20..20 },
74+
{ description: 'Restitutie borrel', amount_range: 5..15 },
75+
{ description: 'Handmatige correctie', amount_range: -10..10 }
76+
]
77+
3578
users.each do |user|
36-
FactoryBot.create_list(:credit_mutation, 3, user:, created_by: users.sample,
37-
activity: (activities + [nil]).sample)
79+
3.times do
80+
mutation = mutation_descriptions.sample
81+
amount = rand(mutation[:amount_range])
82+
FactoryBot.create(:credit_mutation,
83+
user:,
84+
created_by: users.sample,
85+
description: mutation[:description],
86+
amount:,
87+
activity: (activities + [nil]).sample)
88+
end
3889
end
3990

4091
p 'Seeding invoices'
@@ -47,4 +98,22 @@
4798
Role.create(role_type: :treasurer)
4899
Role.create(role_type: :renting_manager)
49100
Role.create(role_type: :main_bartender)
101+
102+
p 'Seeding Sofia accounts...'
103+
# Use environment variable for password or fallback to default for development
104+
105+
treasurer_user = FactoryBot.create(:user, :sofia_account, name: 'Penningmeester Test')
106+
SofiaAccount.create!(username: 'penningmeester', password: 'password1234', user: treasurer_user)
107+
treasurer_role = Role.create(role_type: :treasurer)
108+
treasurer_user.roles << treasurer_role
109+
110+
main_bartender_user = FactoryBot.create(:user, :sofia_account, name: 'Hoofdtapper Test')
111+
SofiaAccount.create!(username: 'hoofdtapper', password: 'password1234', user: main_bartender_user)
112+
main_bartender_role = Role.create(role_type: :main_bartender)
113+
main_bartender_user.roles << main_bartender_role
114+
115+
renting_manager_user = FactoryBot.create(:user, :sofia_account, name: 'Verhuur Test')
116+
SofiaAccount.create!(username: 'verhuur', password: 'password1234', user: renting_manager_user)
117+
renting_manager_role = Role.create(role_type: :renting_manager)
118+
renting_manager_user.roles << renting_manager_role
50119
# rubocop:enable Rails/Output

db/seeds/products.rb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
2+
# Category colors for products
3+
category_colors = {
4+
beer: '#FFD700', # Goud/geel - bierkleur
5+
low_alcohol_beer: '#90EE90', # Lichtgroen - light/gezonder
6+
craft_beer: '#CD7F32', # Brons - premium/craft
7+
non_alcoholic: '#87CEEB', # Lichtblauw - fris/water
8+
distilled: '#DC143C', # Donkerrood - sterke drank
9+
whiskey: '#8B4513', # Bruin - whiskykleur
10+
wine: '#722F37', # Bordeaux - wijnkleur
11+
food: '#FFA500', # Oranje - eten
12+
tobacco: '#808080', # Grijs - rook
13+
donation: '#9370DB' # Paars - speciaal/donatie
14+
}.freeze
215
# rubocop:disable Style/WordArray
316
products_beer = ['Bier (glas)', 'Bier (pul)', 'Bier (pitcher)', '12+1']
417
products_low_alcohol_beer = ['Alcoholarm bier', 'Radler 0.0']
@@ -13,43 +26,43 @@ def seed_products # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metri
1326
# rubocop:enable Style/WordArray
1427

1528
products = products_beer.map do |name|
16-
Product.create(name:, category: :beer)
29+
Product.create(name:, category: :beer, color: category_colors[:beer])
1730
end
1831

1932
products_low_alcohol_beer.each do |name|
20-
products << Product.create(name:, category: :low_alcohol_beer)
33+
products << Product.create(name:, category: :low_alcohol_beer, color: category_colors[:low_alcohol_beer])
2134
end
2235

2336
products_craft_beer.each do |name|
24-
products << Product.create(name:, category: :craft_beer)
37+
products << Product.create(name:, category: :craft_beer, color: category_colors[:craft_beer])
2538
end
2639

2740
products_non_alcoholic.each do |name|
28-
products << Product.create(name:, category: :non_alcoholic)
41+
products << Product.create(name:, category: :non_alcoholic, color: category_colors[:non_alcoholic])
2942
end
3043

3144
products_distilled.each do |name|
32-
products << Product.create(name:, category: :distilled)
45+
products << Product.create(name:, category: :distilled, color: category_colors[:distilled])
3346
end
3447

3548
products_whiskey.each do |name|
36-
products << Product.create(name:, category: :whiskey)
49+
products << Product.create(name:, category: :whiskey, color: category_colors[:whiskey])
3750
end
3851

3952
products_wine.each do |name|
40-
products << Product.create(name:, category: :wine)
53+
products << Product.create(name:, category: :wine, color: category_colors[:wine])
4154
end
4255

4356
products_food.each do |name|
44-
products << Product.create(name:, category: :food)
57+
products << Product.create(name:, category: :food, color: category_colors[:food])
4558
end
4659

4760
products_tobacco.each do |name|
48-
products << Product.create(name:, category: :tobacco)
61+
products << Product.create(name:, category: :tobacco, color: category_colors[:tobacco])
4962
end
5063

5164
products_donation.each do |name|
52-
products << Product.create(name:, category: :donation)
65+
products << Product.create(name:, category: :donation, color: category_colors[:donation])
5366
end
5467

5568
products

0 commit comments

Comments
 (0)