Skip to content

Commit

Permalink
Use fixed salutation for company subjects in abacus
Browse files Browse the repository at this point in the history
  • Loading branch information
codez authored Dec 18, 2024
1 parent 5115e8d commit 3138cd4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
12 changes: 6 additions & 6 deletions app/domain/invoices/abacus/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ def assign_subject_key(data)
end

def subject_attrs
(entity.company? ? organisation_subject_attrs : person_subject_attrs).merge(
language: entity.language,
salutation_id: SALUTATION_IDS.fetch(GENDER_SALUTATIONS[entity.gender])
)
(entity.company? ? organisation_subject_attrs : person_subject_attrs)
.merge(language: entity.language)
end

def person_subject_attrs
# limit strings according to Abacus field lengths
{
type: "Person",
name: entity.last_name.to_s[0, 100],
first_name: entity.first_name.to_s[0, 50],
type: "Person"
salutation_id: SALUTATION_IDS.fetch(GENDER_SALUTATIONS[entity.gender])
}
end

def organisation_subject_attrs
# limit strings according to Abacus field lengths
{
type: "Organisation",
name: entity.company_name.to_s[0, 100],
type: "Organisation"
salutation_id: SALUTATION_IDS.fetch(:company)
}
end

Expand Down
3 changes: 1 addition & 2 deletions app/domain/people/data_quality_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# https://github.com/hitobito/hitobito_sac_cas

class People::DataQualityChecker
ATTRIBUTES_TO_CHECK = %w[first_name last_name company_name street zip_code postbox town email phone_numbers birthday].freeze
ATTRIBUTES_TO_CHECK = %w[first_name last_name street zip_code postbox town email phone_numbers birthday].freeze

attr_reader :person

Expand All @@ -15,7 +15,6 @@ def initialize(person)
end

def check_data_quality
check_blank(:company_name, person.company?, :warning)
check_blank(:first_name, !person.company?)
check_blank(:last_name, !person.company?)
check_blank(:street, membership_invoice? && check_street?)
Expand Down
42 changes: 21 additions & 21 deletions spec/domain/invoices/abacus/subject_interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@

it "fails if abacus assigns a different subject key" do
stub_get_non_existing_subject_request
body = "{\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Type\":\"Person\",\"Language\":\"de\",\"SalutationId\":2,\"Id\":#{person.id}}"
response = "{\"Id\":1234,\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Type\":\"Person\",\"Language\":\"de\",\"SalutationId\":2}"
body = "{\"Type\":\"Person\",\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"SalutationId\":2,\"Language\":\"de\",\"Id\":#{person.id}}"
response = "{\"Id\":1234,\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Type\":\"Person\",\"SalutationId\":2,\"Language\":\"de\"}"
stub_simple_request(:post, "Subjects", body, response)

expect { interface.transmit(subject) }.to raise_error("Abacus created subject with id=1234 but person has id=#{person.id}")
Expand Down Expand Up @@ -275,20 +275,20 @@ def stub_login_requests
end

def stub_create_subject_request
body = "{\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Type\":\"Person\",\"Language\":\"de\",\"SalutationId\":2,\"Id\":#{person.id}}"
body = "{\"Type\":\"Person\",\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"SalutationId\":2,\"Language\":\"de\",\"Id\":#{person.id}}"
response = "{\"Id\":#{person.id},\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Language\":\"de\",\"SalutationId\":2}"
stub_simple_request(:post, "Subjects", body, response)
end

def stub_create_organisation_subject_request
body = "{\"Name\":\"Puzzle ITC\",\"Type\":\"Organisation\",\"Language\":\"de\",\"SalutationId\":2,\"Id\":#{person.id}}"
response = "{\"Id\":#{person.id},\"Name\":\"Puzzle ITC\",\"Type\":\"Organisation\",\"Language\":\"de\",\"SalutationId\":2}"
body = "{\"Type\":\"Organisation\",\"Name\":\"Puzzle ITC\",\"SalutationId\":3,\"Language\":\"de\",\"Id\":#{person.id}}"
response = "{\"Id\":#{person.id},\"Type\":\"Organisation\",\"Name\":\"Puzzle ITC\",\"SalutationId\":3,\"Language\":\"de\"}"
stub_simple_request(:post, "Subjects", body, response)
end

def stub_update_subject_request
body = "{\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Type\":\"Person\",\"Language\":\"de\",\"SalutationId\":2}"
response = "{\"Id\":#{person.id},\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Language\":\"de\",\"SalutationId\":2}"
body = "{\"Type\":\"Person\",\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"SalutationId\":2,\"Language\":\"de\"}"
response = "{\"Id\":#{person.id},\"Type\":\"Person\",\"Name\":\"Hillary\",\"FirstName\":\"Edmund\",\"Language\":\"de\",\"SalutationId\":2}"
stub_simple_request(:patch, "Subjects(Id=#{person.id})", body, response)
end

Expand Down Expand Up @@ -460,7 +460,7 @@ def fetch_batch_existing_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Hillary","FirstName":"Edmund","Type":"Person","Language":"de","SalutationId":2,"Id":600001,\r
{"Type":"Person","Name":"Hillary","FirstName":"Edmund","Language":"de","SalutationId":2,"Id":600001,\r
"Addresses":[{"Id":"e65440b","SubjectId":600001,"ValidFrom":"2024-05-08","Street":"Belpstrasse","HouseNumber":"37","PostOfficeBoxText":"Postfach 23","PostOfficeBoxNumber":"23","StreetSupplement":"","AddressSupplement":"c/o Frau Müller","City":"Bern","PostCode":"3007","CountryId":"CH","State":"BE"}],\r
"Communications":[{"Id":"ef83129d","SubjectId":600001,"Type":"EMail","Value":"[email protected]","Category":"Private"}],
"Customers":[{"Id":600001,"SubjectId":600001,"Status":"Active"}]}\r
Expand All @@ -472,7 +472,7 @@ def fetch_batch_existing_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Tenzing","Type":"Person","Language":"de","SalutationId":2,"Id":600002,\r
{"Type":"Person","Name":"Norgay","FirstName":"Tenzing","Language":"de","SalutationId":2,"Id":600002,\r
"Addresses":[{"Id":"e65440b","SubjectId":600002,"ValidFrom":"2024-05-08","Street":"Hauptstrasse","HouseNumber":"1","PostOfficeBoxText":"","PostOfficeBoxNumber":"","StreetSupplement":"","AddressSupplement":"","City":"Thun","PostCode":"3600","CountryId":"CH","State":"BE"}],\r
"Communications":[{"Id":"ef83129d","SubjectId":600002,"Type":"EMail","Value":"[email protected]","Category":"Private"}],
"Customers":[{"Id":600002,"SubjectId":600002,"Status":"Active"}]}\r
Expand All @@ -484,7 +484,7 @@ def fetch_batch_existing_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":1,"Id":600004,\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","Language":"de","SalutationId":1,"Id":600004,\r
"Addresses":[{"Id":"e65440b","SubjectId":600004,"ValidFrom":"2024-05-08","Street":"","HouseNumber":"","PostOfficeBoxText":"","PostOfficeBoxNumber":"","StreetSupplement":"","AddressSupplement":"","City":"Thun","PostCode":"3600","CountryId":"CH","State":"BE"}],\r
"Communications":[{"Id":"ef83129d","SubjectId":600004,"Type":"EMail","Value":"[email protected]","Category":"Private"}]}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf--\r
Expand All @@ -509,7 +509,7 @@ def fetch_batch_various_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Tenzing","Type":"Person","Language":"de","SalutationId":2,"Id":600002,\r
{"Type":"Person","Name":"Norgay","FirstName":"Tenzing","Language":"de","SalutationId":2,"Id":600002,\r
"Addresses":[{"Id":"e65440b","SubjectId":600002,"ValidFrom":"2024-05-08","Street":"Hauptstrasse","HouseNumber":"1","PostOfficeBoxText":"Postfach 23","AddressSupplement":"c/o Frau Müller","City":"Thun","PostCode":"3600","CountryId":"CH","State":"BE"}],\r
"Communications":[{"Id":"ef83129d","SubjectId":600002,"Type":"EMail","Value":"[email protected]","Category":"Private"}],
"Customers":[{"Id":600002,"SubjectId":600002,"Status":"Active"}]}\r
Expand All @@ -535,7 +535,7 @@ def create_batch_subjects_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Hillary","FirstName":"Edmund","Type":"Person","Language":"de","SalutationId":2,"Id":600001}\r
{"Type":"Person","Name":"Hillary","FirstName":"Edmund","SalutationId":2,"Language":"de","Id":600001}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand All @@ -544,7 +544,7 @@ def create_batch_subjects_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Tenzing","Type":"Person","Language":"de","SalutationId":2,"Id":600002}\r
{"Type":"Person","Name":"Norgay","FirstName":"Tenzing","SalutationId":2,"Language":"de","Id":600002}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand All @@ -553,7 +553,7 @@ def create_batch_subjects_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":2,"Id":600004}\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","SalutationId":2,"Language":"de","Id":600004}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649--\r
HTTP
end
Expand All @@ -568,7 +568,7 @@ def create_batch_subjects_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Hillary","FirstName":"Edmund","Type":"Person","Language":"de","SalutationId":2,"Id":600001}\r
{"Type":"Person","Name":"Hillary","FirstName":"Edmund","SalutationId":2,"Language":"de","Id":600001}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand All @@ -577,7 +577,7 @@ def create_batch_subjects_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Tenzing","Type":"Person","Language":"de","SalutationId":2,"Id":600002}\r
{"Type":"Person","Name":"Norgay","FirstName":"Tenzing","SalutationId":2,"Language":"de","Id":600002}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand All @@ -586,7 +586,7 @@ def create_batch_subjects_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":2,"Id":600004}\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","SalutationId":2,"Language":"de","Id":600004}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf--\r
HTTP
end
Expand All @@ -601,7 +601,7 @@ def create_batch_subjects_partition_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Hillary","FirstName":"Edmund","Type":"Person","Language":"de","SalutationId":2,"Id":600001}\r
{"Type":"Person","Name":"Hillary","FirstName":"Edmund","SalutationId":2,"Language":"de","Id":600001}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand All @@ -610,7 +610,7 @@ def create_batch_subjects_partition_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":2,"Id":600004}\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","SalutationId":2,"Language":"de","Id":600004}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649--\r
HTTP
end
Expand All @@ -634,7 +634,7 @@ def create_batch_subjects_partition_response
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":2,"Id":600004}\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","SalutationId":2,"Language":"de","Id":600004}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf--\r
HTTP
end
Expand Down Expand Up @@ -907,7 +907,7 @@ def update_batch_body
Content-Type: application/json\r
Accept: application/json\r
\r
{"Name":"Norgay","FirstName":"Nima","Type":"Person","Language":"de","SalutationId":2}\r
{"Type":"Person","Name":"Norgay","FirstName":"Nima","SalutationId":2,"Language":"de"}\r
--batch-boundary-3f8b206b-4aec-4616-bd28-c1ccbe572649\r
Content-Type: application/http\r
Content-Transfer-Encoding: binary\r
Expand Down

0 comments on commit 3138cd4

Please sign in to comment.