-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6428283
commit b0a2296
Showing
12 changed files
with
270 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/domain/export/tabular/people/sac_recipient_household_row.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
app/domain/export/tabular/people/sac_recipient_households.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
spec/domain/export/tabular/people/sac_recipient_household_row_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
spec/domain/export/tabular/people/sac_recipient_households_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters