Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1256/membership invoice on join zusatzsektion #1268

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/models/memberships/join_zusatzsektion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,30 @@ def affected_people
sac_family_membership? ? super : [person]
end

def save!
generate_invoice(roles.first) unless confirmation_needed?

super
end

private

def confirmation_needed?
group_for_neuanmeldung.is_a?(Group::SektionsNeuanmeldungenSektion)
end

def generate_invoice(role)
invoice = ExternalInvoice::SacMembership.create!(
person: role.person,
state: :draft,
year: Date.current.year,
issued_at: Date.current,
sent_at: Date.current,
link: role.layer_group
)
Invoices::Abacus::CreateMembershipInvoiceJob.new(invoice, Date.current, new_entry: false).enqueue!
end

def prepare_roles(person)
group_for_neuanmeldung.roles.build(
person: person,
Expand Down
12 changes: 12 additions & 0 deletions spec/models/memberships/join_zusatzsektion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,24 @@ def create_role(key, role, owner: person, **attrs)
ActiveRecord::Base.transaction do
expect(join_sektion).to be_valid
expect { join_sektion.save! }.to change { person.reload.roles.count }.by(1)
.and not_change { ExternalInvoice::SacMembership.count }
.and not_change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }
end
end

it "prefers to create role in NeuanmeldungenSektion group" do
expect { join_sektion.save! }.to change { person.reload.roles.count }.by(1)
.and not_change { ExternalInvoice::SacMembership.count }
.and not_change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }
expect(role.group).to eq groups(:matterhorn_neuanmeldungen_sektion)
expect(role.type).to eq "Group::SektionsNeuanmeldungenSektion::NeuanmeldungZusatzsektion"
end

it "falls back to create role in NeuanmeldungenSektionNv group" do
groups(:matterhorn_neuanmeldungen_sektion).destroy
expect { join_sektion.save! }.to change { person.reload.roles.count }.by(1)
.and change { ExternalInvoice::SacMembership.count }.by(1)
.and change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }.by(1)
expect(role.group).to eq groups(:matterhorn_neuanmeldungen_nv)
expect(role.type).to eq "Group::SektionsNeuanmeldungenNv::NeuanmeldungZusatzsektion"
end
Expand All @@ -179,12 +185,16 @@ def create_role(key, role, owner: person, **attrs)
neuanmeldungen = Fabricate(Group::SektionsNeuanmeldungenSektion.sti_name,
parent: sektion)
expect { join_sektion.save! }.to change { person.reload.roles.count }.by(1)
.and not_change { ExternalInvoice::SacMembership.count }
.and not_change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }
expect(role.group).to eq neuanmeldungen
expect(role.type).to eq "Group::SektionsNeuanmeldungenSektion::NeuanmeldungZusatzsektion"
end

it "falls back to create role in NeuanmeldungenSektionNv group" do
expect { join_sektion.save! }.to change { person.reload.roles.count }.by(1)
.and change { ExternalInvoice::SacMembership.count }.by(1)
.and change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }.by(1)
expect(role.group).to eq groups(:bluemlisalp_ortsgruppe_ausserberg_neuanmeldungen_nv)
expect(role.type).to eq "Group::SektionsNeuanmeldungenNv::NeuanmeldungZusatzsektion"
end
Expand Down Expand Up @@ -231,6 +241,8 @@ def create_sac_family(person, *others)
expect do
expect(join_sektion.save!).to eq true
end.to change { Role.count }.by(2)
.and not_change { ExternalInvoice::SacMembership.count }
.and not_change { Delayed::Job.where("handler like '%CreateMembershipInvoiceJob%'").count }
expect(role.beitragskategorie).to eq "family"
expect(role(other).beitragskategorie).to eq "family"
end
Expand Down
Loading