Cycle Management & Member Integration closes #279 #294

Open
moritz wants to merge 49 commits from feature/279_cycle_management into main
Showing only changes of commit 1e5f84fd88 - Show all commits

View file

@ -191,33 +191,23 @@ defmodule Mv.Membership.Member do
# Trigger cycle regeneration when membership_fee_type_id changes
# This deletes future unpaid cycles and regenerates them with the new type/amount
# Note: Cycle regeneration runs asynchronously to not block the action,
# but in test environment it runs synchronously for DB sandbox compatibility
# Note: Cycle regeneration runs synchronously in the same transaction to ensure atomicity
# CycleGenerator uses advisory locks and transactions internally to prevent race conditions
change after_action(fn changeset, member, _context ->
fee_type_changed =
Ash.Changeset.changing_attribute?(changeset, :membership_fee_type_id)
if fee_type_changed && member.membership_fee_type_id && member.join_date do
regenerate_fn = fn ->
case regenerate_cycles_on_type_change(member) do
:ok ->
:ok
case regenerate_cycles_on_type_change(member) do
:ok ->
:ok
{:error, reason} ->
require Logger
{:error, reason} ->
require Logger
Logger.warning(
"Failed to regenerate cycles for member #{member.id}: #{inspect(reason)}"
)
end
end
if Application.get_env(:mv, :sql_sandbox, false) do
# Run synchronously in test environment for DB sandbox compatibility
regenerate_fn.()
else
# Run asynchronously in other environments
Task.start(regenerate_fn)
Logger.warning(
"Failed to regenerate cycles for member #{member.id}: #{inspect(reason)}"
)
end
end