Skip to content

Commit

Permalink
Add recipient household export
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek committed Sep 3, 2024
1 parent 6428283 commit b0a2296
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## unreleased

* Neuer Personen-Export "Empfänger Familien" für den physischen Versand des Sektionsbulletins

## Version 2.2

* Die ID der nächsten Sektion, Ortsgruppe oder des Nationalverbands zu jeder Rolle wird jetzt als Claim im OIDC Userinfo Endpoint ausgegeben, wenn der with_roles Scope verwendet wird. (hitobito_sac_cas#389)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sac_cas/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ def prepare_entries(entries)
end

def tabular_params(**)
super.merge(params.slice(:recipients).permit!)
super.merge(params.slice(:recipients, :recipient_households).permit!)
end
end
35 changes: 35 additions & 0 deletions app/domain/export/tabular/people/sac_recipient_household_row.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

module Export::Tabular::People
class SacRecipientHouseholdRow < SacRecipientRow
def entry
household.find { _1.email.present? } || household.first
end

def household
# Make sure it is an array, in case someone passes in a plain non-household list
Array.wrap(@entry)
end

def first_name
return entry.first_name unless household?

I18n.t("roles.beitragskategorie.family")
end

def last_name
return entry.last_name unless household?

Export::Tabular::People::HouseholdRow.new(household).name
end

def household?
household.size > 1
end
end
end
20 changes: 20 additions & 0 deletions app/domain/export/tabular/people/sac_recipient_households.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

module Export::Tabular::People
class SacRecipientHouseholds < Export::Tabular::People::SacRecipients
self.row_class = SacRecipientHouseholdRow

def list
@household_list ||= begin # rubocop:disable Naming/MemoizedInstanceVariableName @list is already used in the base-class, which shadows this extension
people = super

::People::HouseholdList.new(people.includes(:primary_group))
end
end
end
end
3 changes: 3 additions & 0 deletions app/helpers/sac_cas/dropdown/people_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def tabular_links(format)
item.sub_items << Dropdown::Item.new(translate(:recipients),
params.merge(format: format, recipients: true),
data: {checkable: true})
item.sub_items << Dropdown::Item.new(translate(:recipient_households),
params.merge(format: format, recipient_households: true),
data: {checkable: true})
end
end
end
5 changes: 5 additions & 0 deletions app/jobs/sac_cas/export/people_export_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ def entries

def data
return recipients_data if @options[:recipients]
return recipient_households_data if @options[:recipient_households]

super
end

def recipients_data
Export::Tabular::People::SacRecipients.export(@format, entries, group)
end

def recipient_households_data
Export::Tabular::People::SacRecipientHouseholds.export(@format, entries, group)
end
end
3 changes: 2 additions & 1 deletion config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ de:
terminate_sac_membership_wizard_link: SAC-Mitgliedschaft beenden

dropdown/people_export:
recipients: Empfänger
recipients: Empfänger Einzelpersonen
recipient_households: Empfänger Familien

dropdown/group_edit:
sac_membership_configs: Parameter für Mitgliedschaftsrechnungen
Expand Down
137 changes: 137 additions & 0 deletions spec/domain/export/tabular/people/sac_recipient_household_row_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas

require "spec_helper"

describe Export::Tabular::People::SacRecipientHouseholdRow do
let(:group) { groups(:bluemlisalp_mitglieder) }
let(:person) do
Fabricate.build(
:person,
id: 42,
first_name: "Hans",
last_name: "Muster",
street: "Musterstrasse",
housenumber: "42",
zip_code: "4242",
town: "Musterhausen",
country: "Schweiz",
email: "[email protected]"
)
end
let(:family_member) do
Fabricate.build(:person,
id: 43,
first_name: "Max",
last_name: "Muster",
email: "[email protected]",
street: "Maxweg",
housenumber: "12",
household_key: "42")
end

subject(:row) { described_class.new(people, group) }

def value(key) = row.fetch(key)

describe "person without household" do
let(:people) do
[person]
end

it("id") { expect(value(:id)).to eq 42 }
it("salutation") { expect(value(:salutation)).to be_nil }
it("first_name") { expect(value(:first_name)).to eq "Hans" }
it("last_name") { expect(value(:last_name)).to eq "Muster" }
it("adresszusatz") { expect(value(:adresszusatz)).to be_nil }
it("address") { expect(value(:address)).to eq "Musterstrasse 42" }
it("postfach") { expect(value(:postfach)).to be_nil }
it("zip_code") { expect(value(:zip_code)).to eq "4242" }
it("town") { expect(value(:town)).to eq "Musterhausen" }
it("email") { expect(value(:email)).to eq "[email protected]" }
it("layer_navision_id") do
expect(value(:layer_navision_id)).to eq groups(:bluemlisalp).navision_id
end
end

describe "person with household but other member not in export" do
let(:people) do
in_export = person.tap { _1.household_key = "42" }
family_member

[in_export]
end

it("id") { expect(value(:id)).to eq 42 }
it("salutation") { expect(value(:salutation)).to be_nil }
it("first_name") { expect(value(:first_name)).to eq "Hans" }
it("last_name") { expect(value(:last_name)).to eq "Muster" }
it("adresszusatz") { expect(value(:adresszusatz)).to be_nil }
it("address") { expect(value(:address)).to eq "Musterstrasse 42" }
it("postfach") { expect(value(:postfach)).to be_nil }
it("zip_code") { expect(value(:zip_code)).to eq "4242" }
it("town") { expect(value(:town)).to eq "Musterhausen" }
it("email") { expect(value(:email)).to eq "[email protected]" }
it("layer_navision_id") do
expect(value(:layer_navision_id)).to eq groups(:bluemlisalp).navision_id
end
end

describe "person with household and other member in export" do
let(:people) do
in_export1 = person.tap { _1.household_key = "42" }
in_export2 = Fabricate.build(:person, first_name: "Max", last_name: "Muster", household_key: "42")

[in_export1, in_export2]
end

it("id") { expect(value(:id)).to eq 42 }
it("salutation") { expect(value(:salutation)).to be_nil }
it("first_name") { expect(value(:first_name)).to eq "Familie" }
it("last_name") { expect(value(:last_name)).to eq "Hans und Max Muster" }
it("adresszusatz") { expect(value(:adresszusatz)).to be_nil }
it("address") { expect(value(:address)).to eq "Musterstrasse 42" }
it("postfach") { expect(value(:postfach)).to be_nil }
it("zip_code") { expect(value(:zip_code)).to eq "4242" }
it("town") { expect(value(:town)).to eq "Musterhausen" }
it("email") { expect(value(:email)).to eq "[email protected]" }
it("layer_navision_id") do
expect(value(:layer_navision_id)).to eq groups(:bluemlisalp).navision_id
end

context "with only one person having mail" do
let(:people) do
person.household_key = "42"
person.email = nil

[person, family_member]
end

it("uses id from person with email") { expect(value(:id)).to eq 43 }
it("uses email from person with email") { expect(value(:email)).to eq "[email protected]" }
it("uses address from person with email") { expect(value(:address)).to eq "Maxweg 12" }
it("first_name") { expect(value(:first_name)).to eq "Familie" }
it("last_name") { expect(value(:last_name)).to eq "Hans und Max Muster" }
end

context "with no person having mail" do
let(:people) do
person.household_key = "42"
person.email = nil

family_member.email = nil

[person, family_member]
end

it("uses id from first person") { expect(value(:id)).to eq 42 }
it("uses address from first person") { expect(value(:address)).to eq "Musterstrasse 42" }
it("first_name") { expect(value(:first_name)).to eq "Familie" }
it("last_name") { expect(value(:last_name)).to eq "Hans und Max Muster" }
end
end
end
36 changes: 36 additions & 0 deletions spec/domain/export/tabular/people/sac_recipient_households_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas

require "spec_helper"

describe Export::Tabular::People::SacRecipientHouseholds do
let(:group) { groups(:bluemlisalp) }
let(:list) { people(:mitglied, :familienmitglied, :abonnent) }

subject(:tabular) { described_class.new(list, group) }

its(:model_class) { is_expected.to eq Person }
its(:row_class) { is_expected.to eq Export::Tabular::People::SacRecipientHouseholdRow }

its(:attribute_labels) do
is_expected.to eq(
id: "Navision-Nr.",
salutation: "Anrede",
first_name: "Vorname",
last_name: "Name",
adresszusatz: "Adresszusatz",
address: "Strasse",
postfach: "Postfach",
zip_code: "PLZ",
town: "Ort",
country: "Land",
layer_navision_id: "Sektion",
anzahl: "Anzahl",
email: "E-Mail"
)
end
end
12 changes: 11 additions & 1 deletion spec/features/people/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
visit group_people_path(group_id: group.id)
click_link("Export")
find_link("CSV").hover
click_link("Empfänger")
click_link("Empfänger Einzelpersonen")

expect(page).to have_selector(".info-bar .alert-info",
text: "Die Downloads werden vorbereitet, bitte warten.")
end

it "starts recipient households export" do
visit group_people_path(group_id: group.id)
click_link("Export")
find_link("CSV").hover
click_link("Empfänger Familien")

expect(page).to have_selector(".info-bar .alert-info",
text: "Die Downloads werden vorbereitet, bitte warten.")
Expand Down
16 changes: 15 additions & 1 deletion spec/features/subscribers_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@

click_link("Export")
find_link("CSV").hover
click_link("Empfänger")
click_link("Empfänger Einzelpersonen")

expect(page).to have_selector(".info-bar .alert-info",
text: "Die Downloads werden vorbereitet, bitte warten.")
end

it "starts recipient households export" do
visit group_mailing_list_subscriptions_path(
group_id: mailing_list.group_id,
mailing_list_id: mailing_list.id
)

click_link("Export")
find_link("CSV").hover
click_link("Empfänger Familien")

expect(page).to have_selector(".info-bar .alert-info",
text: "Die Downloads werden vorbereitet, bitte warten.")
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/dropdown/people_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def submenu_entries(name)
is_expected.to have_content "Export"

expect(top_menu_entries).to match_array %w[CSV Excel vCard PDF]
expect(submenu_entries("CSV")).to match_array %w[Spaltenauswahl Adressliste Empfänger]
expect(submenu_entries("CSV")).to match_array ["Spaltenauswahl", "Adressliste", "Empfänger Einzelpersonen", "Empfänger Familien"]
end
end

0 comments on commit b0a2296

Please sign in to comment.