Skip to content

Commit 7ae59e6

Browse files
[#267] Removed partij constraint and fixed tests
1 parent 6afde15 commit 7ae59e6

12 files changed

+802
-825
lines changed

src/openklant/components/klantinteracties/admin/partijen.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,20 @@ class Meta:
3030

3131
def clean(self):
3232
cleaned_data = super().clean()
33-
partij_identificator = {
34-
"code_objecttype": cleaned_data["partij_identificator_code_objecttype"],
35-
"code_soort_object_id": cleaned_data[
33+
PartijIdentificatorTypesValidator()(
34+
code_register=cleaned_data["partij_identificator_code_register"],
35+
code_objecttype=cleaned_data["partij_identificator_code_objecttype"],
36+
code_soort_object_id=cleaned_data[
3637
"partij_identificator_code_soort_object_id"
3738
],
38-
"object_id": cleaned_data["partij_identificator_object_id"],
39-
"code_register": cleaned_data["partij_identificator_code_register"],
40-
}
41-
42-
PartijIdentificatorTypesValidator(
43-
partij_identificator=partij_identificator
44-
).validate()
45-
46-
queryset = PartijIdentificator.objects.exclude()
47-
if self.instance:
48-
queryset = queryset.exclude(pk=self.instance.pk)
39+
object_id=cleaned_data["partij_identificator_object_id"],
40+
)
4941

5042
PartijIdentificatorUniquenessValidator(
51-
instance=self.instance,
52-
partij_identificator=partij_identificator,
43+
code_soort_object_id=cleaned_data[
44+
"partij_identificator_code_soort_object_id"
45+
],
5346
sub_identificator_van=cleaned_data["sub_identificator_van"],
54-
partij=cleaned_data["partij"],
5547
)()
5648

5749
return cleaned_data

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

+22-13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
PartijIdentificatorTypesValidator,
4747
PartijIdentificatorUniquenessValidator,
4848
)
49+
from openklant.utils.decorators import handle_db_exceptions
4950
from openklant.utils.serializers import get_field_instance_by_uuid, get_field_value
5051

5152

@@ -371,10 +372,7 @@ class Meta:
371372
"code_soort_object_id": {"required": True},
372373
"object_id": {"required": True},
373374
}
374-
375-
def validate(self, attrs):
376-
PartijIdentificatorTypesValidator(partij_identificator=attrs)()
377-
return super().validate(attrs)
375+
validators = []
378376

379377

380378
class PartijIdentificatorSerializer(
@@ -420,27 +418,38 @@ class Meta:
420418
}
421419

422420
def validate(self, attrs):
423-
instance = getattr(self, "instance", None)
424421
partij_identificator = get_field_value(self, attrs, "partij_identificator")
425-
426422
sub_identificator_van = get_field_instance_by_uuid(
427423
self, attrs, "sub_identificator_van", PartijIdentificator
428424
)
429425
partij = get_field_instance_by_uuid(self, attrs, "partij", Partij)
430426

427+
PartijIdentificatorTypesValidator()(
428+
code_objecttype=partij_identificator["code_objecttype"],
429+
code_soort_object_id=partij_identificator["code_soort_object_id"],
430+
object_id=partij_identificator["object_id"],
431+
code_register=partij_identificator["code_register"],
432+
)
431433
PartijIdentificatorUniquenessValidator(
432-
instance=instance,
433-
partij_identificator=partij_identificator,
434+
code_soort_object_id=partij_identificator["code_soort_object_id"],
434435
sub_identificator_van=sub_identificator_van,
435-
partij=partij,
436436
)()
437437

438-
attrs["sub_identificator_van"] = get_field_instance_by_uuid(
439-
self, attrs, "sub_identificator_van", PartijIdentificator
440-
)
441-
attrs["partij"] = get_field_instance_by_uuid(self, attrs, "partij", Partij)
438+
attrs["sub_identificator_van"] = sub_identificator_van
439+
attrs["partij"] = partij
440+
442441
return super().validate(attrs)
443442

443+
@handle_db_exceptions
444+
@transaction.atomic
445+
def update(self, instance, validated_data):
446+
return super().update(instance, validated_data)
447+
448+
@handle_db_exceptions
449+
@transaction.atomic
450+
def create(self, validated_data):
451+
return super().create(validated_data)
452+
444453

445454
class PartijSerializer(NestedGegevensGroepMixin, PolymorphicSerializer):
446455
from openklant.components.klantinteracties.api.serializers.rekeningnummers import (

0 commit comments

Comments
 (0)