Commit 20627052 authored by David F.'s avatar David F.

Merge branch '90-renouvellement-d-une-adhesion' into 'master'

Resolve "[club partenaire] renouveler une adhésion d'une saison l'autre"

See merge request !93
parents b5df8eef 850d609a
......@@ -164,8 +164,8 @@ GEM
ffi (1.9.18)
fitvidsjs_rails (1.1.3)
railties (>= 3.1)
font-awesome-rails (4.7.0.2)
railties (>= 3.2, < 5.2)
font-awesome-rails (4.7.0.4)
railties (>= 3.2, < 6.0)
fullcalendar-rails (3.4.0.0)
jquery-rails (>= 4.0.5, < 5.0.0)
jquery-ui-rails (>= 5.0.2)
......
......@@ -44,15 +44,29 @@ form#search_contacts_form {
}
}
li.subscription {
span {
padding: 0 0.5em;
&.billed { @include button-color($oligaa-green); }
&.not-billed { @include button-color; }
&.platform-number { font: caption;}
&.activities {
display: none;
aside#subscriptions {
div {
padding: 0 1em;
a.expendable {
display: block;
}
ul {
padding: 0.5em 0;
li.subscription {
span {
padding: 0 0.5em;
&.billed { @include button-color($oligaa-green); }
&.not-billed { @include button-color; }
&.platform-number { font: caption;}
&.activities {
display: none;
}
}
i.fa-info-circle:hover + span.activities { display: block;}
}
}
}
i.fa-info-circle:hover + span.activities { display: block;}
}
......@@ -96,9 +96,12 @@ class MembersController < ApplicationController
@disabled_performances = @member.performances.disabled
if @member.collaborating_club?
@internal_subscriptions = @member.subscriptions
@seasoned_internal_subscriptions = Season.all_for(@internal_subscriptions, :created_at)
@external_subscriptions = Subscription.for_performances(@member.performance_ids) - @internal_subscriptions
@seasoned_external_subscriptions = Season.all_for(@external_subscriptions, :created_at)
elsif @member.collaborating_medicosocial_org?
@internal_subscriptions = Subscription.of_medicosocial_org(@member).by_adherent_name
@seasoned_internal_subscriptions = Season.all_for(@internal_subscriptions, :created_at)
end
else
authorize
......
......@@ -24,7 +24,7 @@ class SubscriptionsController < ApplicationController
include AuthorizationsHelper
before_action :set_member
before_action :set_subscription, only: [:edit, :update, :destroy, :card, :toggle_billing]
before_action :set_subscription, only: [:edit, :update, :destroy, :card, :toggle_billing, :renew]
before_action :authorize_member, except: [:destroy, :toggle_billing, :card]
before_action :authorize, only: [:destroy, :toggle_billing]
before_action :set_medico_social_orgs, except: [:destroy, :card, :toggle_billing]
......@@ -37,7 +37,7 @@ class SubscriptionsController < ApplicationController
def create
@subscription = @member.subscriptions.build(subscription_params).tap do |subscription|
subscription.build_adherent(adherent_params)
subscription.adherent = Adherent.available_for_current_season(adherent_params)
end
if @subscription.save
......@@ -90,6 +90,12 @@ class SubscriptionsController < ApplicationController
render layout: nil
end
def renew
old_subscription = @subscription
@subscription = old_subscription.dup
@subscription.performance_ids = old_subscription.performance_ids
end
def destroy
if @subscription
@subscription.destroy
......
......@@ -137,4 +137,11 @@ module LinksHelper
custom_link 'fa-toggle-on', 'Activer', path, version, options
end
def custom_redo_link(path, version = :normal, options = {})
options[:class] ||= []
options[:class] << 'primary'
custom_link 'fa-repeat', 'Renouveler', path, version, options
end
end
......@@ -30,6 +30,17 @@ class Adherent < ApplicationRecord
before_validation :cleanup_medicosocial_org
def self.available_for_current_season(params)
current_season = Season.new(Date.today)
adherent = Adherent.find(params[:id]) if params[:id].present?
if adherent && !adherent.subscriptions.map(&:season).map(&:shorten).uniq.include?(current_season.shorten)
adherent
else
params.delete(:id)
Adherent.new(params)
end
end
def name
"#{first_name} #{last_name}"
end
......
......@@ -32,11 +32,11 @@ class Season
Settings.instance.reload.season_birthdate || self.default_birthdate
end
def self.all_for(items)
def self.all_for(items, date_field=:begin_at)
result = {}
items.each do |item|
year = item.begin_at.year
if item.begin_at >= Season.birthdate.change(year: year)
year = item.send(date_field).year
if item.send(date_field)>= Season.birthdate.change(year: year)
(result["Saison #{year.to_s}-#{(year+1).to_s}"] ||= []) << item
else
(result["Saison #{(year-1).to_s}-#{year.to_s}"] ||= []) << item
......
......@@ -37,27 +37,40 @@
Nos adhérents
<span><%= Statistics::Pass::Unit.new(@member).label %></span>
</h2>
<ul id="internal">
<% @internal_subscriptions.each do |subscription| %>
<li class="subscription">
<%= custom_print_card_link card_member_subscription_path(@member, subscription, format: :pdf), :short, class: %w(tight) %>
<%- if admin? %>
<%= custom_edit_link edit_member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%= custom_delete_link member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%- end %>
<%= internal_subscription_label(subscription) %>
</li>
<div id="internal">
<%- @seasoned_internal_subscriptions.each do |season, subscriptions| %>
<% season_label = season.downcase.gsub(/\s/, '_') + "_int" %>
<%= toggle_link "#{ season } (#{ subscriptions.length })", "##{season_label}" %>
<ul id="<%= season_label %>" style="display:none;">
<% subscriptions.each do |subscription| %>
<li class="subscription">
<%= custom_print_card_link card_member_subscription_path(@member, subscription, format: :pdf), :short, class: %w(tight) %>
<%= custom_redo_link renew_member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%- if admin? %>
<%= custom_edit_link edit_member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%= custom_delete_link member_subscription_path(@member, subscription), :short, class: %w(tight) %>
<%- end %>
<%= internal_subscription_label(subscription) %>
</li>
<%- end %>
</ul>
<%- end if @internal_subscriptions %>
</ul>
</div>
<%- unless @member.collaborating_medicosocial_org? %>
<h2>Adhérents extérieurs</h2>
<ul id="external">
<% @external_subscriptions.each do |subscription| %>
<li class="subscription">
<%= external_subscription_label(subscription, @member) %>
</li>
<%- end if @external_subscriptions %>
</ul>
<h2>Adhérents extérieurs</h2>
<div id="external">
<%- @seasoned_external_subscriptions.each do |season, subscriptions| %>
<% season_label = season.downcase.gsub(/\s/, '_') + "_ext" %>
<%= toggle_link "#{ season } (#{ subscriptions.length })", "##{season_label}" %>
<ul id="<%= season_label %>" style="display:none;">
<% subscriptions.each do |subscription| %>
<li class="subscription">
<%= external_subscription_label(subscription, @member) %>
</li>
<%- end %>
</ul>
<%- end if @external_subscriptions %>
</div>
<%- end %>
</aside>
<%- end %>
......@@ -28,7 +28,7 @@
<%= f.fields_for :adherent do |a| %>
<%= a.input :last_name %>
<%= a.input :first_name %>
<%= a.input :born_on, as: :string %>
<%= a.input :born_on, as: :date_picker %>
<%= a.input :permit_number %>
<%= a.association :medico_social_org, collection: @medico_social_orgs, include_blank: "Autre", required: true %>
<%= a.input :other_medicosocial_org, required: true %>
......
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2018 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
<% title 'Renouvellement adhésion' %>
<div class="card-block">
<h1><%= yield :title %></h1>
<p class="AdminCard-globalActions">
<%= custom_list_link member_path(@member) %>
</p>
<%= render 'form' %>
</div>
......@@ -60,6 +60,7 @@ Rails.application.routes.draw do
get :option, on: :collection
get :card, on: :member
patch :toggle_billing, on: :member
get :renew, on: :member
end
end
resources :member_groups, :except => [:index] do
......
This diff is collapsed.
......@@ -79,4 +79,79 @@ RSpec.describe Adherent, type: :model do
expect(adherent.medico_social_org_name).to eq "IME two"
end
end
describe "scopes" do
context ".available_for_current_season" do
let(:params) {
{
first_name: "Jean",
last_name: "Dupont",
born_on: "14/07/1989",
permit_number: "123456",
medico_social_org_id: nil,
other_medicosocial_org: nil
}
}
context "adherent does not exist" do
it "returns a just built one" do
# Given
# When
result = Adherent.available_for_current_season(params)
# Then
expect(result).to be_a Adherent
expect(result).not_to be_persisted
end
end
context "adherent alreaday exists" do
let!(:existing_adherent) { create :adherent, id: 42, permit_number: "123456" }
context "within another season" do
before do
Timecop.freeze(Date.new(2016,9,10))
create :subscription, adherent: existing_adherent
end
after { Timecop.return }
it "returns the adherent" do
# Given
Timecop.travel(Date.new(2017,9,10))
params[:id] = 42
# When
result = Adherent.available_for_current_season(params)
# Then
expect(result).to eq existing_adherent
expect(result).to be_persisted
end
end
context "Within the same season" do
before do
Timecop.freeze(Date.new(2018,9,10))
create :subscription, adherent: existing_adherent
end
after { Timecop.return }
it "returns a just built one (for validations purpose)" do
# Given
params[:id] = 42
# When
result = Adherent.available_for_current_season(params)
# Then
expect(result).not_to eq existing_adherent
expect(result).not_to be_persisted
expect(result.id).to be_nil
end
end
end
end
end
end
......@@ -54,21 +54,41 @@ RSpec.describe Season, type: :model do
end
end
it ".all_for returns items arranged by season" do
# Given
allow(Settings).to receive_message_chain(:instance, :reload, :season_birthdate).and_return(Date.new(1970,9,1))
Item = Struct.new(:begin_at)
item1 = Item.new(Date.new(2018,8,31))
item2 = Item.new(Date.new(2018,9,1))
item3 = Item.new(Date.new(2018,9,2))
expected = [
["Saison 2018-2019", [item2, item3]],
["Saison 2017-2018", [item1]]
]
# When
result = Season.all_for([ item1, item2, item3 ])
# Then
expect(result).to eq expected
context ".all_for returns items arranged by season" do
before { allow(Settings).to receive_message_chain(:instance, :reload, :season_birthdate).and_return(Date.new(1970,9,1)) }
it "based on :begin_at if no field provided" do
# Given
Item = Struct.new(:begin_at)
item1 = Item.new(Date.new(2018,8,31))
item2 = Item.new(Date.new(2018,9,1))
item3 = Item.new(Date.new(2018,9,2))
expected = [
["Saison 2018-2019", [item2, item3]],
["Saison 2017-2018", [item1]]
]
# When
result = Season.all_for([ item1, item2, item3 ])
# Then
expect(result).to eq expected
end
it "based on the provided field" do
# Given
Item = Struct.new(:created_at)
item1 = Item.new(Date.new(2018,8,31))
item2 = Item.new(Date.new(2018,9,1))
item3 = Item.new(Date.new(2018,9,2))
expected = [
["Saison 2018-2019", [item2, item3]],
["Saison 2017-2018", [item1]]
]
# When
result = Season.all_for([ item1, item2, item3 ], :created_at)
# Then
expect(result).to eq expected
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment