fix: improve get_last_completed_cycle and fix test helpers
- Fix get_last_completed_cycle to find most recent completed cycle - Fix create_cycle helpers to delete auto-generated cycles first - Fix Ash.destroy return value handling - Fix form selectors to use specific IDs - Fix URL parameter names for filters - Fix Ash.read_one return value expectations in tests
This commit is contained in:
parent
ab7fa38010
commit
128c712dbc
12 changed files with 177 additions and 43 deletions
|
|
@ -126,11 +126,17 @@ defmodule MvWeb.Helpers.MembershipFeeHelpers do
|
|||
fee_type ->
|
||||
cycles = member.membership_fee_cycles || []
|
||||
|
||||
cycles
|
||||
|> Enum.filter(fn cycle ->
|
||||
CalendarCycles.last_completed_cycle?(cycle.cycle_start, fee_type.interval, today)
|
||||
end)
|
||||
|> List.first()
|
||||
# Get all completed cycles (cycle_end < today)
|
||||
completed_cycles =
|
||||
cycles
|
||||
|> Enum.filter(fn cycle ->
|
||||
cycle_end = CalendarCycles.calculate_cycle_end(cycle.cycle_start, fee_type.interval)
|
||||
Date.compare(today, cycle_end) == :gt
|
||||
end)
|
||||
|
||||
# Return the most recent completed cycle (highest cycle_start)
|
||||
completed_cycles
|
||||
|> Enum.max_by(& &1.cycle_start, Date, fn -> nil end)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -442,7 +442,9 @@ defmodule MvWeb.MemberLive.Show.MembershipFeesComponent do
|
|||
|
||||
case Decimal.parse(amount_str) do
|
||||
{amount, _} when is_struct(amount, Decimal) ->
|
||||
case Ash.update(cycle, :update, %{amount: amount}) do
|
||||
case cycle
|
||||
|> Ash.Changeset.for_update(:update, %{amount: amount})
|
||||
|> Ash.update() do
|
||||
{:ok, updated_cycle} ->
|
||||
updated_cycles = replace_cycle(socket.assigns.cycles, updated_cycle)
|
||||
|
||||
|
|
@ -489,6 +491,16 @@ defmodule MvWeb.MemberLive.Show.MembershipFeesComponent do
|
|||
|> assign(:deleting_cycle, nil)
|
||||
|> put_flash(:info, gettext("Cycle deleted"))}
|
||||
|
||||
{:ok, _destroyed} ->
|
||||
# Handle case where return_destroyed? is true
|
||||
updated_cycles = Enum.reject(socket.assigns.cycles, &(&1.id == cycle_id))
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:cycles, updated_cycles)
|
||||
|> assign(:deleting_cycle, nil)
|
||||
|> put_flash(:info, gettext("Cycle deleted"))}
|
||||
|
||||
{:error, error} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue