Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#132] added api validation to check if nummeraanduiding_i… #133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/openklant/components/contactgegevens/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ class Meta:
model = Organisatie
gegevensgroep = "adres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het adres ingevuld is."
),
}
)

return super().validate(attrs)


class OrganisatieSerializer(
NestedGegevensGroepMixin,
Expand Down Expand Up @@ -48,6 +61,19 @@ class Meta:
model = Persoon
gegevensgroep = "adres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het adres ingevuld is."
),
}
)

return super().validate(attrs)


class PersoonSerializer(
NestedGegevensGroepMixin,
Expand Down
18 changes: 18 additions & 0 deletions src/openklant/components/contactgegevens/api/tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_create_persoon(self):
"geslacht": "m",
"voornamen": "Devin",
"adres": {
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -41,6 +42,7 @@ def test_create_persoon(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -57,6 +59,7 @@ def test_update_persoon(self):
geslacht="m",
voorvoegsel="",
voornamen="Devin",
adres_nummeraanduiding_id="nummeraanduiding_id",
adres_adresregel1="adresregel1",
adres_adresregel2="adresregel2",
adres_adresregel3="adresregel3",
Expand All @@ -83,6 +86,7 @@ def test_update_persoon(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -99,6 +103,7 @@ def test_update_persoon(self):
"voorvoegsel": "changed",
"voornamen": "changed",
"adres": {
"nummeraanduidingId": "changed",
"adresregel1": "changed",
"adresregel2": "changed",
"adresregel3": "changed",
Expand All @@ -117,6 +122,7 @@ def test_update_persoon(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "changed",
"adresregel1": "changed",
"adresregel2": "changed",
"adresregel3": "changed",
Expand All @@ -133,6 +139,7 @@ def test_update_partial_persoon(self):
geslacht="m",
voorvoegsel="",
voornamen="Devin",
adres_nummeraanduiding_id="nummeraanduiding_id",
adres_adresregel1="adresregel1",
adres_adresregel2="adresregel2",
adres_adresregel3="adresregel3",
Expand All @@ -159,6 +166,7 @@ def test_update_partial_persoon(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -182,6 +190,7 @@ def test_update_partial_persoon(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -199,6 +208,7 @@ def test_create_organisatie(self):
"handelsnaam": "Devin Townsend",
"oprichtingsdatum": "1996-03-12",
"adres": {
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -219,6 +229,7 @@ def test_create_organisatie(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -232,6 +243,7 @@ def test_update_organisatie(self):
handelsnaam="Devin Townsend",
oprichtingsdatum="1996-03-12",
opheffingsdatum=None,
adres_nummeraanduiding_id="nummeraanduiding_id",
adres_adresregel1="adresregel1",
adres_adresregel2="adresregel2",
adres_adresregel3="adresregel3",
Expand All @@ -255,6 +267,7 @@ def test_update_organisatie(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -268,6 +281,7 @@ def test_update_organisatie(self):
"oprichtingsdatum": "1996-03-13",
"opheffingsdatum": "2023-11-22",
"adres": {
"nummeraanduidingId": "changed",
"adresregel1": "changed",
"adresregel2": "changed",
"adresregel3": "changed",
Expand All @@ -283,6 +297,7 @@ def test_update_organisatie(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "changed",
"adresregel1": "changed",
"adresregel2": "changed",
"adresregel3": "changed",
Expand All @@ -296,6 +311,7 @@ def test_update_partial_organisatie(self):
handelsnaam="Devin Townsend",
oprichtingsdatum="1996-03-12",
opheffingsdatum=None,
adres_nummeraanduiding_id="nummeraanduiding_id",
adres_adresregel1="adresregel1",
adres_adresregel2="adresregel2",
adres_adresregel3="adresregel3",
Expand All @@ -319,6 +335,7 @@ def test_update_partial_organisatie(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand All @@ -340,6 +357,7 @@ def test_update_partial_organisatie(self):
self.assertEqual(
data["adres"],
{
"nummeraanduidingId": "nummeraanduiding_id",
"adresregel1": "adresregel1",
"adresregel2": "adresregel2",
"adresregel3": "adresregel3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.23 on 2024-01-10 11:36

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("contactgegevens", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="organisatie",
name="adres_nummeraanduiding_id",
field=models.CharField(
blank=True,
help_text="Identificatie van het adres bij de Basisregistratie Adressen en Gebouwen.",
max_length=255,
verbose_name="nummeraanduiding ID",
),
),
migrations.AddField(
model_name="persoon",
name="adres_nummeraanduiding_id",
field=models.CharField(
blank=True,
help_text="Identificatie van het adres bij de Basisregistratie Adressen en Gebouwen.",
max_length=255,
verbose_name="nummeraanduiding ID",
),
),
]
16 changes: 16 additions & 0 deletions src/openklant/components/contactgegevens/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@


class AdresMixin(models.Model):
adres_nummeraanduiding_id = models.CharField(
_("nummeraanduiding ID"),
help_text=_(
"Identificatie van het adres bij de Basisregistratie Adressen en Gebouwen."
),
max_length=255,
blank=True,
)
adres_adresregel1 = models.CharField(
_("adresregel 1"),
help_text=_(
Expand Down Expand Up @@ -46,11 +54,19 @@ class AdresMixin(models.Model):

adres = GegevensGroepType(
{
"nummeraanduiding_id": adres_nummeraanduiding_id,
"adresregel_1": adres_adresregel1,
"adresregel_2": adres_adresregel2,
"adresregel_3": adres_adresregel3,
"land": adres_land,
},
optional=(
"nummeraanduiding_id",
"adresregel_1",
"adresregel_2",
"adresregel_3",
"land",
),
)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,39 @@ class Meta:
model = Betrokkene
gegevensgroep = "bezoekadres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het bezoekadres ingevuld is."
),
}
)

return super().validate(attrs)


class CorrespondentieadresSerializer(GegevensGroepSerializer):
class Meta:
model = Betrokkene
gegevensgroep = "correspondentieadres"
ref_name = "BetrokkeneCorrespondentieadres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het correspondentieadres ingevuld is."
),
}
)

return super().validate(attrs)


class ContactnaamSerializer(GegevensGroepSerializer):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,39 @@ class Meta:
model = Partij
gegevensgroep = "bezoekadres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het bezoekadres ingevuld is."
),
}
)

return super().validate(attrs)


class CorrespondentieadresSerializer(GegevensGroepSerializer):
class Meta:
model = Partij
gegevensgroep = "correspondentieadres"
ref_name = "PartijCorrespondentieadres"

def validate(self, attrs):
if any(attrs.values()):
if not attrs.get("nummeraanduiding_id"):
raise serializers.ValidationError(
{
"nummeraanduiding_id": _(
"nummeraanduiding_id is verplicht wanneer het correspondentieadres ingevuld is."
),
}
)

return super().validate(attrs)


class OrganisatieSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
Loading