Skip to content

Commit 80e0138

Browse files
[#239] Fix updatePartij
1 parent a7f4a61 commit 80e0138

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/openklant/components/klantinteracties/api/serializers/partijen.py

+12
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ def get_vertegenwoordigden(self, obj):
571571
def update(self, instance, validated_data):
572572
method = self.context.get("request").method
573573
partij_identificatie = validated_data.pop("partij_identificatie", None)
574+
partij_identificatoren = validated_data.pop("partijidentificator_set", [])
574575

575576
if "digitaaladres_set" in validated_data:
576577
existing_digitale_adressen = instance.digitaaladres_set.all()
@@ -717,6 +718,17 @@ def update(self, instance, validated_data):
717718

718719
partij = super().update(instance, validated_data)
719720

721+
if partij_identificatoren:
722+
partij.partijidentificator_set.all().delete()
723+
for partij_identificator in partij_identificatoren:
724+
partij_identificator["partij"] = {"uuid": str(partij.uuid)}
725+
partij_identificator_serializer = PartijIdentificatorSerializer(
726+
data=partij_identificator
727+
)
728+
partij_identificator_serializer.is_valid(raise_exception=True)
729+
partij_identificator_serializer.create(partij_identificator)
730+
731+
720732
if partij_identificatie:
721733
serializer_class = self.discriminator.mapping[
722734
validated_data.get("soort_partij")

src/openklant/components/klantinteracties/api/tests/test_partijen.py

+39
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,14 @@ def test_update_partij(self):
680680
rekeningnummer = RekeningnummerFactory.create(partij=partij)
681681
rekeningnummer2 = RekeningnummerFactory.create()
682682

683+
partij_identificator = PartijIdentificatorFactory.create(
684+
partij=partij,
685+
partij_identificator_code_objecttype="natuurlijk_persoon",
686+
partij_identificator_code_soort_object_id="bsn",
687+
partij_identificator_object_id="296648875",
688+
partij_identificator_code_register="brp",
689+
)
690+
683691
detail_url = reverse(
684692
"klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)}
685693
)
@@ -745,6 +753,16 @@ def test_update_partij(self):
745753
},
746754
)
747755

756+
self.assertEqual(
757+
data["partijIdentificatoren"][0]["partijIdentificator"],
758+
{
759+
"codeObjecttype": partij_identificator.partij_identificator_code_objecttype,
760+
"codeSoortObjectId": partij_identificator.partij_identificator_code_soort_object_id,
761+
"objectId": partij_identificator.partij_identificator_object_id,
762+
"codeRegister": partij_identificator.partij_identificator_code_register,
763+
},
764+
)
765+
748766
data = {
749767
"nummer": "6427834668",
750768
"interneNotitie": "changed",
@@ -778,6 +796,17 @@ def test_update_partij(self):
778796
"achternaam": "Bennette",
779797
}
780798
},
799+
"partijIdentificatoren": [
800+
{
801+
"anderePartijIdentificator": "string",
802+
"partijIdentificator": {
803+
"codeObjecttype": "niet_natuurlijk_persoon",
804+
"codeSoortObjectId": "rsin",
805+
"objectId": "296648875",
806+
"codeRegister": "hr",
807+
},
808+
}
809+
],
781810
}
782811

783812
response = self.client.put(detail_url, data)
@@ -846,6 +875,16 @@ def test_update_partij(self):
846875
},
847876
},
848877
)
878+
self.assertEqual(len(data["partijIdentificatoren"]), 1)
879+
self.assertEqual(
880+
data["partijIdentificatoren"][0]["partijIdentificator"],
881+
{
882+
"codeObjecttype": "niet_natuurlijk_persoon",
883+
"codeSoortObjectId": "rsin",
884+
"objectId": "296648875",
885+
"codeRegister": "hr",
886+
},
887+
)
849888

850889
with self.subTest(
851890
"test_voorkeurs_digitaal_adres_must_be_part_of_digitale_adressen"

0 commit comments

Comments
 (0)