Skip to content

Commit

Permalink
[#239] Fix updatePartij
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Feb 4, 2025
1 parent e9a1f98 commit b7b798d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def get_vertegenwoordigden(self, obj):
def update(self, instance, validated_data):
method = self.context.get("request").method
partij_identificatie = validated_data.pop("partij_identificatie", None)
partij_identificatoren = validated_data.pop("partijidentificator_set", [])

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

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

if partij_identificatoren:
partij.partijidentificator_set.all().delete()
for partij_identificator in partij_identificatoren:
partij_identificator["partij"] = {"uuid": str(partij.uuid)}
partij_identificator_serializer = PartijIdentificatorSerializer(
data=partij_identificator
)
partij_identificator_serializer.is_valid(raise_exception=True)
partij_identificator_serializer.create(partij_identificator)


if partij_identificatie:
serializer_class = self.discriminator.mapping[
validated_data.get("soort_partij")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ def test_update_partij(self):
rekeningnummer = RekeningnummerFactory.create(partij=partij)
rekeningnummer2 = RekeningnummerFactory.create()

partij_identificator = PartijIdentificatorFactory.create(
partij=partij,
partij_identificator_code_objecttype="natuurlijk_persoon",
partij_identificator_code_soort_object_id="bsn",
partij_identificator_object_id="296648875",
partij_identificator_code_register="brp",
)

detail_url = reverse(
"klantinteracties:partij-detail", kwargs={"uuid": str(partij.uuid)}
)
Expand Down Expand Up @@ -745,6 +753,16 @@ def test_update_partij(self):
},
)

self.assertEqual(
data["partijIdentificatoren"][0]["partijIdentificator"],
{
"codeObjecttype": partij_identificator.partij_identificator_code_objecttype,
"codeSoortObjectId": partij_identificator.partij_identificator_code_soort_object_id,
"objectId": partij_identificator.partij_identificator_object_id,
"codeRegister": partij_identificator.partij_identificator_code_register,
},
)

data = {
"nummer": "6427834668",
"interneNotitie": "changed",
Expand Down Expand Up @@ -778,6 +796,17 @@ def test_update_partij(self):
"achternaam": "Bennette",
}
},
"partijIdentificatoren": [
{
"anderePartijIdentificator": "string",
"partijIdentificator": {
"codeObjecttype": "niet_natuurlijk_persoon",
"codeSoortObjectId": "rsin",
"objectId": "296648875",
"codeRegister": "hr",
},
}
],
}

response = self.client.put(detail_url, data)
Expand Down Expand Up @@ -846,6 +875,16 @@ def test_update_partij(self):
},
},
)
self.assertEqual(len(data["partijIdentificatoren"]), 1)
self.assertEqual(
data["partijIdentificatoren"][0]["partijIdentificator"],
{
"codeObjecttype": "niet_natuurlijk_persoon",
"codeSoortObjectId": "rsin",
"objectId": "296648875",
"codeRegister": "hr",
},
)

with self.subTest(
"test_voorkeurs_digitaal_adres_must_be_part_of_digitale_adressen"
Expand Down

0 comments on commit b7b798d

Please sign in to comment.