Skip to content

Commit 7d784ef

Browse files
[#239] Fixed test
1 parent f2ca7c0 commit 7d784ef

File tree

3 files changed

+714
-43
lines changed

3 files changed

+714
-43
lines changed

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

+19-14
Original file line numberDiff line numberDiff line change
@@ -427,24 +427,24 @@ def validate(self, attrs):
427427
self, attrs, "sub_identificator_van", PartijIdentificator
428428
)
429429
partij = get_field_instance_by_uuid(self, attrs, "partij", Partij)
430-
431-
PartijIdentificatorTypesValidator()(
432-
code_objecttype=partij_identificator["code_objecttype"],
433-
code_soort_object_id=partij_identificator["code_soort_object_id"],
434-
object_id=partij_identificator["object_id"],
435-
code_register=partij_identificator["code_register"],
436-
)
437-
PartijIdentificatorUniquenessValidator(
438-
code_soort_object_id=partij_identificator["code_soort_object_id"],
439-
sub_identificator_van=sub_identificator_van,
440-
)()
430+
if partij_identificator:
431+
PartijIdentificatorTypesValidator()(
432+
code_objecttype=partij_identificator["code_objecttype"],
433+
code_soort_object_id=partij_identificator["code_soort_object_id"],
434+
object_id=partij_identificator["object_id"],
435+
code_register=partij_identificator["code_register"],
436+
)
437+
PartijIdentificatorUniquenessValidator(
438+
code_soort_object_id=partij_identificator["code_soort_object_id"],
439+
sub_identificator_van=sub_identificator_van,
440+
)()
441441

442442
attrs["sub_identificator_van"] = sub_identificator_van
443443
attrs["partij"] = partij
444444

445445
return super().validate(attrs)
446446

447-
def assert_partij(self, partij):
447+
def validate_partij(self, partij):
448448
if not partij:
449449
raise serializers.ValidationError(
450450
{"identificeerdePartij": _("Dit veld is vereist.")},
@@ -454,13 +454,13 @@ def assert_partij(self, partij):
454454
@handle_db_exceptions
455455
@transaction.atomic
456456
def update(self, instance, validated_data):
457-
self.assert_partij(validated_data["partij"])
457+
self.validate_partij(validated_data["partij"])
458458
return super().update(instance, validated_data)
459459

460460
@handle_db_exceptions
461461
@transaction.atomic
462462
def create(self, validated_data):
463-
self.assert_partij(validated_data["partij"])
463+
self.validate_partij(validated_data["partij"])
464464
return super().create(validated_data)
465465

466466

@@ -634,6 +634,11 @@ def validate_partij_identificatoren(self, attrs):
634634
return attrs
635635

636636
def update_or_create_partij_identificator(self, partij_identificator):
637+
sub_identificator_van = partij_identificator["sub_identificator_van"]
638+
if isinstance(sub_identificator_van, PartijIdentificator):
639+
partij_identificator["sub_identificator_van"] = {
640+
"uuid": sub_identificator_van.uuid
641+
}
637642
partij_identificator_serializer = PartijIdentificatorSerializer(
638643
data=partij_identificator
639644
)

0 commit comments

Comments
 (0)