diff --git a/app/domain/people/sac_membership.rb b/app/domain/people/sac_membership.rb index b70f2d735..25be4472f 100644 --- a/app/domain/people/sac_membership.rb +++ b/app/domain/people/sac_membership.rb @@ -48,7 +48,7 @@ def zusatzsektion_roles active_roles_of_type(mitglied_zusatzsektion_types) end - def select_currently_paying(roles) + def select_paying(roles) roles.compact.select { |role| paying_person?(role.beitragskategorie) } end diff --git a/app/models/people/membership/invoice_form.rb b/app/models/people/membership/invoice_form.rb index 0a270e571..cc7c542bf 100644 --- a/app/models/people/membership/invoice_form.rb +++ b/app/models/people/membership/invoice_form.rb @@ -26,9 +26,9 @@ class People::Membership::InvoiceForm validates :discount, inclusion: {in: DISCOUNTS}, allow_blank: true validate :assert_active_membership, if: :assert_active_membership? - delegate :stammsektion_role, :zusatzsektion_roles, - :neuanmeldung_nv_zusatzsektion_roles, :select_currently_paying, to: - :sac_membership + delegate :stammsektion_role, :neuanmeldung_stammsektion_role, + :zusatzsektion_roles, :neuanmeldung_nv_zusatzsektion_roles, + :select_paying, to: :sac_membership def initialize(person, attrs = {}) super(attrs) @@ -36,18 +36,18 @@ def initialize(person, attrs = {}) end def stammsektion - select_currently_paying([stammsektion_role]).first&.layer_group + select_paying([stammsektion_role, neuanmeldung_stammsektion_role]).first&.layer_group end def zusatzsektionen - select_currently_paying(neuanmeldung_nv_zusatzsektion_roles + zusatzsektion_roles).map(&:layer_group) + select_paying(neuanmeldung_nv_zusatzsektion_roles + zusatzsektion_roles).map(&:layer_group) end def min_date = today.beginning_of_year def max_date = today.next_year.end_of_year - def max_send_date = (!already_member_next_year?) ? today.end_of_year : today.next_year.end_of_year + def max_send_date = already_member_next_year? ? today.next_year.end_of_year : today.end_of_year private @@ -64,7 +64,7 @@ def assert_active_membership? end def already_member_next_year? - person.sac_membership.stammsektion_role.end_on&.year&.>= today.next_year.year + person.sac_membership.active? && (person.sac_membership.stammsektion_role.end_on&.year&.>= today.next_year.year) end def today = Time.zone.today diff --git a/app/views/people/membership_invoices/new.html.haml b/app/views/people/membership_invoices/new.html.haml index 94050b991..1df96d8b2 100644 --- a/app/views/people/membership_invoices/new.html.haml +++ b/app/views/people/membership_invoices/new.html.haml @@ -29,7 +29,7 @@ = f.date_field(:send_date, minDate: @invoice_form.min_date, maxDate: @invoice_form.max_send_date) = f.labeled(:section_id) do - = f.inline_radio_button :section_id, @person.sac_membership.stammsektion_role.group.layer_group.id, t(".mv_yearly_invoice"), true, checked: true + = f.inline_radio_button :section_id, @invoice_form.stammsektion.id, t(".mv_yearly_invoice"), true, checked: true .nested-radio-group = f.labeled(:new_entry, class: "ms-3") do diff --git a/spec/controllers/people/membership_invoices_controller_spec.rb b/spec/controllers/people/membership_invoices_controller_spec.rb index 7ee455103..bf44965ef 100644 --- a/spec/controllers/people/membership_invoices_controller_spec.rb +++ b/spec/controllers/people/membership_invoices_controller_spec.rb @@ -64,5 +64,31 @@ expect(flash[:alert]).to eq "Die Person hat Datenqualitätsprobleme, daher wurde keine Rechnung erstellt." end end + + context "only neuanmeldung for stammsektion" do + let(:person) do + person = Fabricate(:person, birthday: 42.years.ago) + Fabricate(Group::SektionsNeuanmeldungenNv::Neuanmeldung.sti_name.to_sym, + person: person, + beitragskategorie: :adult, + group: groups(:bluemlisalp_neuanmeldungen_nv)) + person + end + + it "creates external invoice and enqueues job" do + expect do + post :create, params: params.deep_merge(people_membership_invoice_form: {discount: 50, new_entry: true}) + end.to change { ExternalInvoice.count }.by(1) + .and change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count } + + expect(response).to redirect_to(external_invoices_group_person_path(groups(:bluemlisalp_mitglieder).id, person.id)) + expect(flash[:notice]).to eq("Die gewünschte Rechnung wird erzeugt und an Abacus übermittelt") + + job = Delayed::Job.last.payload_object + expect(job.new_entry).to eq true + expect(job.discount).to eq 50 + expect(job.reference_date).to eq today + end + end end end diff --git a/spec/models/people/membership/invoice_form_spec.rb b/spec/models/people/membership/invoice_form_spec.rb index 727b3eea5..f557884a5 100644 --- a/spec/models/people/membership/invoice_form_spec.rb +++ b/spec/models/people/membership/invoice_form_spec.rb @@ -49,6 +49,13 @@ expect(form).not_to be_valid expect(form.errors.full_messages).to eq ["Mitgliedschaft ist nicht gültig"] end + + it "is valid if person has neuanmeldung for stammsektion in chose section" do + person.roles.destroy_all + Fabricate(Group::SektionsNeuanmeldungenNv::Neuanmeldung.sti_name, person: person, group: groups(:bluemlisalp_neuanmeldungen_nv), start_on: 1.year.ago) + form.section_id = groups(:bluemlisalp_neuanmeldungen_nv).layer_group.id.to_s + expect(form).to be_valid + end end describe "send_date" do @@ -143,6 +150,12 @@ expect(form.max_send_date).to eq Date.new(2024, 12, 31) end + it "uses end of this year for max_send_date for people with neuanmeldung roles" do + person.roles.destroy_all + Fabricate(Group::SektionsNeuanmeldungenNv::Neuanmeldung.sti_name, person: person, group: groups(:bluemlisalp_neuanmeldungen_nv), start_on: 1.year.ago) + expect(form.max_send_date).to eq Date.new(2024, 12, 31) + end + context "with membership for next year" do before { roles(:mitglied).update!(end_on: 3.years.from_now) }