From 3138cd46d81908e358b6718e2ddc13ee4ea0c047 Mon Sep 17 00:00:00 2001 From: z Date: Wed, 18 Dec 2024 16:15:33 +0100 Subject: [PATCH] Use fixed salutation for company subjects in abacus --- app/domain/invoices/abacus/subject.rb | 12 +++--- app/domain/people/data_quality_checker.rb | 3 +- .../invoices/abacus/subject_interface_spec.rb | 42 +++++++++---------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/app/domain/invoices/abacus/subject.rb b/app/domain/invoices/abacus/subject.rb index ca2ea647a..a399f84ed 100644 --- a/app/domain/invoices/abacus/subject.rb +++ b/app/domain/invoices/abacus/subject.rb @@ -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 diff --git a/app/domain/people/data_quality_checker.rb b/app/domain/people/data_quality_checker.rb index e53a52f3a..66e744b7a 100644 --- a/app/domain/people/data_quality_checker.rb +++ b/app/domain/people/data_quality_checker.rb @@ -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 @@ -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?) diff --git a/spec/domain/invoices/abacus/subject_interface_spec.rb b/spec/domain/invoices/abacus/subject_interface_spec.rb index aa14ed042..945c7eb6b 100644 --- a/spec/domain/invoices/abacus/subject_interface_spec.rb +++ b/spec/domain/invoices/abacus/subject_interface_spec.rb @@ -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}") @@ -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 @@ -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":"e.hillary@hitobito.example.com","Category":"Private"}], "Customers":[{"Id":600001,"SubjectId":600001,"Status":"Active"}]}\r @@ -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":"tenzing@hitobito.example.com","Category":"Private"}], "Customers":[{"Id":600002,"SubjectId":600002,"Status":"Active"}]}\r @@ -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":"n.norgay@hitobito.example.com","Category":"Private"}]}\r --batch-boundary-3f8b206b-4aec-4616-bd28-asdasdfasdf--\r @@ -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":"tenzing@hitobito.example.com","Category":"Private"}], "Customers":[{"Id":600002,"SubjectId":600002,"Status":"Active"}]}\r @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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