Skip to content

Commit

Permalink
[#267] Removed partij constraint and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Feb 27, 2025
1 parent 6afde15 commit 7ae59e6
Show file tree
Hide file tree
Showing 12 changed files with 802 additions and 825 deletions.
26 changes: 9 additions & 17 deletions src/openklant/components/klantinteracties/admin/partijen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,20 @@ class Meta:

def clean(self):
cleaned_data = super().clean()
partij_identificator = {
"code_objecttype": cleaned_data["partij_identificator_code_objecttype"],
"code_soort_object_id": cleaned_data[
PartijIdentificatorTypesValidator()(
code_register=cleaned_data["partij_identificator_code_register"],
code_objecttype=cleaned_data["partij_identificator_code_objecttype"],
code_soort_object_id=cleaned_data[
"partij_identificator_code_soort_object_id"
],
"object_id": cleaned_data["partij_identificator_object_id"],
"code_register": cleaned_data["partij_identificator_code_register"],
}

PartijIdentificatorTypesValidator(
partij_identificator=partij_identificator
).validate()

queryset = PartijIdentificator.objects.exclude()
if self.instance:
queryset = queryset.exclude(pk=self.instance.pk)
object_id=cleaned_data["partij_identificator_object_id"],
)

PartijIdentificatorUniquenessValidator(
instance=self.instance,
partij_identificator=partij_identificator,
code_soort_object_id=cleaned_data[
"partij_identificator_code_soort_object_id"
],
sub_identificator_van=cleaned_data["sub_identificator_van"],
partij=cleaned_data["partij"],
)()

return cleaned_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
PartijIdentificatorTypesValidator,
PartijIdentificatorUniquenessValidator,
)
from openklant.utils.decorators import handle_db_exceptions
from openklant.utils.serializers import get_field_instance_by_uuid, get_field_value


Expand Down Expand Up @@ -371,10 +372,7 @@ class Meta:
"code_soort_object_id": {"required": True},
"object_id": {"required": True},
}

def validate(self, attrs):
PartijIdentificatorTypesValidator(partij_identificator=attrs)()
return super().validate(attrs)
validators = []


class PartijIdentificatorSerializer(
Expand Down Expand Up @@ -420,27 +418,38 @@ class Meta:
}

def validate(self, attrs):
instance = getattr(self, "instance", None)
partij_identificator = get_field_value(self, attrs, "partij_identificator")

sub_identificator_van = get_field_instance_by_uuid(
self, attrs, "sub_identificator_van", PartijIdentificator
)
partij = get_field_instance_by_uuid(self, attrs, "partij", Partij)

PartijIdentificatorTypesValidator()(
code_objecttype=partij_identificator["code_objecttype"],
code_soort_object_id=partij_identificator["code_soort_object_id"],
object_id=partij_identificator["object_id"],
code_register=partij_identificator["code_register"],
)
PartijIdentificatorUniquenessValidator(
instance=instance,
partij_identificator=partij_identificator,
code_soort_object_id=partij_identificator["code_soort_object_id"],
sub_identificator_van=sub_identificator_van,
partij=partij,
)()

attrs["sub_identificator_van"] = get_field_instance_by_uuid(
self, attrs, "sub_identificator_van", PartijIdentificator
)
attrs["partij"] = get_field_instance_by_uuid(self, attrs, "partij", Partij)
attrs["sub_identificator_van"] = sub_identificator_van
attrs["partij"] = partij

return super().validate(attrs)

@handle_db_exceptions
@transaction.atomic
def update(self, instance, validated_data):
return super().update(instance, validated_data)

@handle_db_exceptions
@transaction.atomic
def create(self, validated_data):
return super().create(validated_data)


class PartijSerializer(NestedGegevensGroepMixin, PolymorphicSerializer):
from openklant.components.klantinteracties.api.serializers.rekeningnummers import (
Expand Down
Loading

0 comments on commit 7ae59e6

Please sign in to comment.