seeds: distribute fee types at create, add exit dates for 5 members
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f430762555
commit
bb1a80ad08
1 changed files with 21 additions and 19 deletions
|
|
@ -34,7 +34,7 @@ countries_list =
|
||||||
|> List.replace_at(7, "Österreich")
|
|> List.replace_at(7, "Österreich")
|
||||||
|> List.replace_at(14, "Schweiz")
|
|> List.replace_at(14, "Schweiz")
|
||||||
|
|
||||||
# 20 members: varied names, cities, join dates; fee types by index (last 2 without fee type)
|
# 20 members: varied names, cities, join dates; fee types distributed over all members (round-robin)
|
||||||
member_configs = [
|
member_configs = [
|
||||||
%{
|
%{
|
||||||
first_name: "Anna",
|
first_name: "Anna",
|
||||||
|
|
@ -218,7 +218,7 @@ member_configs = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Fee type index per member: 0..4 round-robin for first 18, nil for last 2
|
# Fee type index per member: 0..4 round-robin for all 20 (each type used 4 times)
|
||||||
# Cycle status: all_paid, all_unpaid, mixed (varied)
|
# Cycle status: all_paid, all_unpaid, mixed (varied)
|
||||||
cycle_statuses = [
|
cycle_statuses = [
|
||||||
:all_paid,
|
:all_paid,
|
||||||
|
|
@ -240,18 +240,20 @@ cycle_statuses = [
|
||||||
:all_unpaid,
|
:all_unpaid,
|
||||||
:all_paid,
|
:all_paid,
|
||||||
:mixed,
|
:mixed,
|
||||||
nil
|
:all_paid
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Indices of members that get an exit date (5 distributed: 3, 7, 11, 15, 19)
|
||||||
|
exit_date_member_indices = [3, 7, 11, 15, 19]
|
||||||
|
|
||||||
Enum.with_index(member_configs)
|
Enum.with_index(member_configs)
|
||||||
|> Enum.each(fn {config, index} ->
|
|> Enum.each(fn {config, index} ->
|
||||||
email = "mitglied#{index + 1}@example.de"
|
email = "mitglied#{index + 1}@example.de"
|
||||||
fee_type_index = if index >= 18, do: nil, else: rem(index, length(all_fee_types))
|
fee_type_index = rem(index, length(all_fee_types))
|
||||||
fee_type_id = if fee_type_index, do: Enum.at(all_fee_types, fee_type_index).id, else: nil
|
fee_type_id = Enum.at(all_fee_types, fee_type_index).id
|
||||||
cycle_status = Enum.at(cycle_statuses, index)
|
cycle_status = Enum.at(cycle_statuses, index)
|
||||||
|
|
||||||
# Do not include membership_fee_type_id in upsert so re-runs do not overwrite
|
# Set fee type at create so cycles are generated with correct interval (no interval-change conflict)
|
||||||
# existing assignments; set via update below only when member has none
|
|
||||||
base_attrs = %{
|
base_attrs = %{
|
||||||
first_name: config.first_name,
|
first_name: config.first_name,
|
||||||
last_name: config.last_name,
|
last_name: config.last_name,
|
||||||
|
|
@ -264,6 +266,11 @@ Enum.with_index(member_configs)
|
||||||
country: Enum.at(countries_list, index)
|
country: Enum.at(countries_list, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base_attrs =
|
||||||
|
if fee_type_id,
|
||||||
|
do: Map.put(base_attrs, :membership_fee_type_id, fee_type_id),
|
||||||
|
else: base_attrs
|
||||||
|
|
||||||
member =
|
member =
|
||||||
Membership.create_member!(base_attrs,
|
Membership.create_member!(base_attrs,
|
||||||
upsert?: true,
|
upsert?: true,
|
||||||
|
|
@ -271,17 +278,7 @@ Enum.with_index(member_configs)
|
||||||
actor: admin_user_with_role
|
actor: admin_user_with_role
|
||||||
)
|
)
|
||||||
|
|
||||||
final_member =
|
final_member = member
|
||||||
if is_nil(member.membership_fee_type_id) and fee_type_id do
|
|
||||||
{:ok, updated} =
|
|
||||||
Membership.update_member(member, %{membership_fee_type_id: fee_type_id},
|
|
||||||
actor: admin_user_with_role
|
|
||||||
)
|
|
||||||
|
|
||||||
updated
|
|
||||||
else
|
|
||||||
member
|
|
||||||
end
|
|
||||||
|
|
||||||
if not is_nil(final_member.membership_fee_type_id) and not is_nil(cycle_status) do
|
if not is_nil(final_member.membership_fee_type_id) and not is_nil(cycle_status) do
|
||||||
member_with_cycles =
|
member_with_cycles =
|
||||||
|
|
@ -330,6 +327,11 @@ Enum.with_index(member_configs)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if index in exit_date_member_indices do
|
||||||
|
exit_date = Date.add(config.join_date, 365)
|
||||||
|
Membership.update_member(final_member, %{exit_date: exit_date}, actor: admin_user_with_role)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
# Groups (idempotent)
|
# Groups (idempotent)
|
||||||
|
|
@ -482,7 +484,7 @@ for {email, values} <- custom_value_assignments do
|
||||||
end
|
end
|
||||||
|
|
||||||
IO.puts("✅ Dev seeds completed.")
|
IO.puts("✅ Dev seeds completed.")
|
||||||
IO.puts(" - Members: 20 with country (mostly Deutschland, 1 Österreich, 1 Schweiz)")
|
IO.puts(" - Members: 20 with country (mostly Deutschland, 1 Österreich, 1 Schweiz), fee types distributed, 5 with exit date")
|
||||||
IO.puts(" - Test users: 4 linked to mitglied1–4 with roles Mitglied, Vorstand, Kassenwart, Buchhaltung")
|
IO.puts(" - Test users: 4 linked to mitglied1–4 with roles Mitglied, Vorstand, Kassenwart, Buchhaltung")
|
||||||
IO.puts(" - Groups: Vorstand, Jugend, Newsletter (with assignments)")
|
IO.puts(" - Groups: Vorstand, Jugend, Newsletter (with assignments)")
|
||||||
IO.puts(" - Custom field values: ~80% filled (16 members, 4–6 fields each)")
|
IO.puts(" - Custom field values: ~80% filled (16 members, 4–6 fields each)")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue