Skip to content

Commit

Permalink
Merge pull request #227 from open-zaak/issue/zaaktype-identificatie-w…
Browse files Browse the repository at this point in the history
…rong-format

Issue/zaaktype identificatie wrong format
  • Loading branch information
joeribekker committed Nov 19, 2019
2 parents 5dfcd99 + ac725d6 commit c77385e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/openzaak/components/catalogi/admin/zaaktypen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ZaakTypeAdmin(

# List
list_display = (
"zaaktype_identificatie",
"identificatie",
"zaaktype_omschrijving",
"catalogus",
"uuid",
Expand All @@ -82,9 +82,9 @@ class ZaakTypeAdmin(
"indicatie_intern_of_extern",
"vertrouwelijkheidaanduiding",
)
ordering = ("catalogus", "zaaktype_identificatie")
ordering = ("catalogus", "identificatie")
search_fields = (
"zaaktype_identificatie",
"identificatie",
"zaaktype_omschrijving",
"zaaktype_omschrijving_generiek",
"zaakcategorie",
Expand All @@ -100,7 +100,7 @@ class ZaakTypeAdmin(
_("Algemeen"),
{
"fields": (
"zaaktype_identificatie",
"identificatie",
"zaaktype_omschrijving",
"zaaktype_omschrijving_generiek",
"doel",
Expand Down
1 change: 0 additions & 1 deletion src/openzaak/components/catalogi/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class ZaakTypeFilter(FilterSet):
field_name="concept", method=status_filter, help_text=STATUS_HELP_TEXT
)
trefwoorden = CharArrayFilter(field_name="trefwoorden", lookup_expr="contains")
identificatie = filters.NumberFilter(field_name="zaaktype_identificatie")

class Meta:
model = ZaakType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class Meta:
)
extra_kwargs = {
"url": {"lookup_field": "uuid"},
"identificatie": {"source": "zaaktype_identificatie"},
"omschrijving": {"source": "zaaktype_omschrijving"},
"omschrijving_generiek": {"source": "zaaktype_omschrijving_generiek"},
"catalogus": {"lookup_field": "uuid"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.4 on 2019-11-12 09:03

from django.db import migrations, models
import vng_api_common.validators


class Migration(migrations.Migration):

dependencies = [
("catalogi", "0006_auto_20191024_1000"),
]

operations = [
migrations.AlterField(
model_name="zaaktype",
name="zaaktype_identificatie",
field=models.CharField(
blank=True,
db_index=True,
help_text="Unieke identificatie van het ZAAKTYPE binnen de CATALOGUS waarin het ZAAKTYPE voorkomt.",
max_length=50,
validators=[vng_api_common.validators.AlphanumericExcludingDiacritic()],
verbose_name="identificatie",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2019-11-12 11:11

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("catalogi", "0007_auto_20191112_0903"),
]

operations = [
migrations.RenameField(
model_name="zaaktype",
old_name="zaaktype_identificatie",
new_name="identificatie",
),
]
17 changes: 13 additions & 4 deletions src/openzaak/components/catalogi/models/zaaktype.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from vng_api_common.descriptors import GegevensGroepType
from vng_api_common.fields import DaysDurationField, VertrouwelijkheidsAanduidingField
from vng_api_common.models import APIMixin
from vng_api_common.utils import generate_unique_identification
from vng_api_common.validators import alphanumeric_excluding_diacritic

from ..constants import InternExtern
from .mixins import ConceptMixin, GeldigheidMixin
Expand Down Expand Up @@ -140,12 +142,14 @@ class ZaakType(APIMixin, ConceptMixin, GeldigheidMixin, models.Model):
uuid = models.UUIDField(
unique=True, default=uuid.uuid4, help_text="Unieke resource identifier (UUID4)"
)
zaaktype_identificatie = models.PositiveIntegerField( # N5, integer with max_length of 5
identificatie = models.CharField(
_("identificatie"),
validators=[MaxValueValidator(99999)],
max_length=50,
blank=True,
help_text=_(
"Unieke identificatie van het ZAAKTYPE binnen de CATALOGUS waarin het ZAAKTYPE voorkomt."
),
validators=[alphanumeric_excluding_diacritic],
db_index=True,
)
zaaktype_omschrijving = models.CharField(
Expand Down Expand Up @@ -353,14 +357,19 @@ class ZaakType(APIMixin, ConceptMixin, GeldigheidMixin, models.Model):
help_text=_("URL-referentie naar de CATALOGUS waartoe dit ZAAKTYPE behoort."),
)

IDENTIFICATIE_PREFIX = "ZAAKTYPE"

class Meta:
verbose_name = _("Zaaktype")
verbose_name_plural = _("Zaaktypen")

def __str__(self):
return "{} - {}".format(self.catalogus, self.zaaktype_identificatie)
def __str__(self) -> str:
return self.identificatie

def save(self, *args, **kwargs):
if not self.identificatie:
self.identificatie = generate_unique_identification(self, "versiedatum")

if not self.verlenging_mogelijk:
self.verlengingstermijn = None
elif not self.verlengingstermijn:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


class ZaakTypeFactory(factory.django.DjangoModelFactory):
zaaktype_identificatie = factory.Sequence(lambda n: n)
doel = factory.Faker("paragraph")
aanleiding = factory.Faker("paragraph")
indicatie_intern_of_extern = factory.fuzzy.FuzzyChoice(choices=InternExtern.values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ZaaktypeValidationTests(TestCase):
def test_same_id_different_dates(self):
zaaktype = ZaakTypeFactory.create(
zaaktype_omschrijving="test",
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid="2018-01-01",
datum_einde_geldigheid="2018-12-31",
)
Expand All @@ -27,7 +27,7 @@ def test_same_id_different_dates(self):
data={
"uuid": uuid.uuid4(),
"catalogus": catalogus.id,
"zaaktype_identificatie": 1,
"identificatie": 1,
"zaaktype_omschrijving": "test",
"datum_begin_geldigheid": "2019-01-01",
"vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
Expand All @@ -54,7 +54,7 @@ def test_same_id_different_dates(self):
def test_same_id_overlapping_dates(self):
zaaktype = ZaakTypeFactory.create(
zaaktype_omschrijving="test",
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid="2018-01-01",
datum_einde_geldigheid="2018-12-31",
)
Expand All @@ -64,7 +64,7 @@ def test_same_id_overlapping_dates(self):
data={
"uuid": uuid.uuid4(),
"catalogus": catalogus.id,
"zaaktype_identificatie": 1,
"identificatie": 1,
"zaaktype_omschrijving": "test",
"datum_begin_geldigheid": "2018-10-01",
"vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_same_id_overlapping_dates(self):
def test_same_id_no_end_date(self):
zaaktype = ZaakTypeFactory.create(
zaaktype_omschrijving="test",
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid="2018-01-01",
)
catalogus = zaaktype.catalogus
Expand All @@ -105,7 +105,7 @@ def test_same_id_no_end_date(self):
data={
"uuid": uuid.uuid4(),
"catalogus": catalogus.id,
"zaaktype_identificatie": 1,
"identificatie": 1,
"zaaktype_omschrijving": "test",
"datum_begin_geldigheid": "2019-01-01",
"vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
Expand Down
55 changes: 48 additions & 7 deletions src/openzaak/components/catalogi/tests/test_zaaktype.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_get_detail(self):
self.assertResponseTypes(
response_data,
(
("identificatie", int),
("identificatie", str),
("omschrijving", str),
("omschrijvingGeneriek", str),
("catalogus", str),
Expand All @@ -76,7 +76,7 @@ def test_get_detail(self):
)
expected = {
"url": f"http://testserver{zaaktype_detail_url}",
"identificatie": zaaktype.zaaktype_identificatie,
"identificatie": zaaktype.identificatie,
"productenOfDiensten": ["https://example.com/product/123"],
"publicatieIndicatie": zaaktype.publicatie_indicatie,
"trefwoorden": [],
Expand Down Expand Up @@ -191,6 +191,47 @@ def test_create_zaaktype(self):
)
self.assertEqual(zaaktype.concept, True)

def test_create_zaaktype_generate_unique_identificatie(self):
zaaktype1 = ZaakTypeFactory.create(catalogus=self.catalogus)

zaaktype_list_url = get_operation_url("zaaktype_list")
data = {
"doel": "some test",
"aanleiding": "some test",
"indicatieInternOfExtern": InternExtern.extern,
"handelingInitiator": "indienen",
"onderwerp": "Klacht",
"handelingBehandelaar": "uitvoeren",
"doorlooptijd": "P30D",
"opschortingEnAanhoudingMogelijk": False,
"verlengingMogelijk": True,
"verlengingstermijn": "P30D",
"publicatieIndicatie": True,
"verantwoordingsrelatie": [],
"productenOfDiensten": ["https://example.com/product/123"],
"vertrouwelijkheidaanduiding": VertrouwelijkheidsAanduiding.openbaar,
"omschrijving": "some test",
"gerelateerdeZaaktypen": [
{
"zaaktype": "http://example.com/zaaktype/1",
"aard_relatie": AardRelatieChoices.bijdrage,
"toelichting": "test relations",
}
],
"referentieproces": {"naam": "ReferentieProces 0", "link": ""},
"catalogus": f"http://testserver{self.catalogus_detail_url}",
"besluittypen": [],
"beginGeldigheid": "2018-01-01",
"versiedatum": "2018-01-01",
}
response = self.client.post(zaaktype_list_url, data)

self.assertEqual(response.data["identificatie"], "ZAAKTYPE-2018-0000000002")

zaaktype2 = ZaakType.objects.get(zaaktype_omschrijving="some test")

self.assertNotEqual(zaaktype1.identificatie, zaaktype2.identificatie)

def test_create_zaaktype_fail_besluittype_non_concept(self):
besluittype = BesluitTypeFactory.create(concept=False, catalogus=self.catalogus)
besluittype_url = get_operation_url("besluittype_read", uuid=besluittype.uuid)
Expand Down Expand Up @@ -1051,7 +1092,7 @@ def setUpTestData(cls):
def test_overlap_specified_dates(self):
ZaakTypeFactory.create(
catalogus=self.catalogus,
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid=date(2019, 1, 1),
datum_einde_geldigheid=date(2020, 1, 1),
zaaktype_omschrijving="zaaktype",
Expand Down Expand Up @@ -1090,7 +1131,7 @@ def test_overlap_specified_dates(self):
def test_overlap_open_end_date(self):
ZaakTypeFactory.create(
catalogus=self.catalogus,
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid=date(2019, 1, 1),
datum_einde_geldigheid=None,
zaaktype_omschrijving="zaaktype",
Expand Down Expand Up @@ -1129,7 +1170,7 @@ def test_overlap_open_end_date(self):
def test_no_overlap(self):
ZaakTypeFactory.create(
catalogus=self.catalogus,
zaaktype_identificatie=1,
identificatie=1,
datum_begin_geldigheid=date(2019, 1, 1),
datum_einde_geldigheid=date(2020, 1, 1),
zaaktype_omschrijving="zaaktype",
Expand Down Expand Up @@ -1207,8 +1248,8 @@ def test_filter_zaaktype_status_definitief(self):
self.assertEqual(data[0]["url"], f"http://testserver{zaaktype2_url}")

def test_filter_identificatie(self):
zaaktype1 = ZaakTypeFactory.create(concept=False, zaaktype_identificatie=123)
zaaktype2 = ZaakTypeFactory.create(concept=False, zaaktype_identificatie=456)
zaaktype1 = ZaakTypeFactory.create(concept=False, identificatie=123)
zaaktype2 = ZaakTypeFactory.create(concept=False, identificatie=456)
zaaktype_list_url = get_operation_url("zaaktype_list")
zaaktype1_url = get_operation_url("zaaktype_read", uuid=zaaktype1.uuid)

Expand Down

0 comments on commit c77385e

Please sign in to comment.