diff --git a/src/open_inwoner/configurations/bootstrap/zgw.py b/src/open_inwoner/configurations/bootstrap/zgw.py index cb6e06f79d..481e7e7630 100644 --- a/src/open_inwoner/configurations/bootstrap/zgw.py +++ b/src/open_inwoner/configurations/bootstrap/zgw.py @@ -29,7 +29,7 @@ class Meta: "skip_notification_statustype_informeren", "reformat_esuite_zaak_identificatie", "fetch_eherkenning_zaken_with_rsin", - "use_zaak_omschrijving_as_title", + "derive_zaak_titel_from", "order_statuses_by_date_set", "title_text", "enable_categories_filtering_with_zaken", diff --git a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_full.yaml b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_full.yaml index 25d37b8e8d..cfcbc05f6b 100644 --- a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_full.yaml +++ b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_full.yaml @@ -6,7 +6,7 @@ openzaak_config: skip_notification_statustype_informeren: false reformat_esuite_zaak_identificatie: true fetch_eherkenning_zaken_with_rsin: false - use_zaak_omschrijving_as_title: 'true' + derive_zaak_titel_from: zaaktype_omschrijving order_statuses_by_date_set: false title_text: title text from setup configuration enable_categories_filtering_with_zaken: true diff --git a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_missing_groups.yaml b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_missing_groups.yaml index 42088a653e..6a3709b08a 100644 --- a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_missing_groups.yaml +++ b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_missing_groups.yaml @@ -6,7 +6,7 @@ openzaak_config: skip_notification_statustype_informeren: false reformat_esuite_zaak_identificatie: true fetch_eherkenning_zaken_with_rsin: false - use_zaak_omschrijving_as_title: 'true' + derive_zaak_titel_from: zaaktype_omschrijving order_statuses_by_date_set: false title_text: title text from setup configuration enable_categories_filtering_with_zaken: true diff --git a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_zero_groups.yaml b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_zero_groups.yaml index c5bda520ee..982703de18 100644 --- a/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_zero_groups.yaml +++ b/src/open_inwoner/configurations/tests/bootstrap/files/zgw_api_step_zero_groups.yaml @@ -6,7 +6,7 @@ openzaak_config: skip_notification_statustype_informeren: false reformat_esuite_zaak_identificatie: true fetch_eherkenning_zaken_with_rsin: false - use_zaak_omschrijving_as_title: 'true' + derive_zaak_titel_from: zaaktype_omschrijving order_statuses_by_date_set: false title_text: title text from setup configuration enable_categories_filtering_with_zaken: true @@ -16,5 +16,5 @@ openzaak_config: - .pdf - .txt # Empty api_groups should not raise a missing exception, but should raise a - # + # api_groups: [] diff --git a/src/open_inwoner/openzaak/admin.py b/src/open_inwoner/openzaak/admin.py index 10bec8e2e7..807a351250 100644 --- a/src/open_inwoner/openzaak/admin.py +++ b/src/open_inwoner/openzaak/admin.py @@ -66,7 +66,6 @@ class OpenZaakConfigAdmin(SingletonModelAdmin): "fields": ( "enable_categories_filtering_with_zaken", "zaken_filter_enabled", - "use_zaak_omschrijving_as_title", "order_statuses_by_date_set", ), }, @@ -78,6 +77,7 @@ class OpenZaakConfigAdmin(SingletonModelAdmin): "skip_notification_statustype_informeren", "reformat_esuite_zaak_identificatie", "fetch_eherkenning_zaken_with_rsin", + "derive_zaak_titel_from", ], }, ), @@ -177,9 +177,11 @@ def process_file_view(self, request): "error_rows": len(import_result.import_errors), } ), - messages.SUCCESS - if not import_result.import_errors - else messages.WARNING, + ( + messages.SUCCESS + if not import_result.import_errors + else messages.WARNING + ), ) if errors := import_result.import_errors: msgs_deduped = set(error.__str__() for error in errors) @@ -485,9 +487,11 @@ def process_file_view(self, request): "error_rows": len(import_result.import_errors), } ), - messages.SUCCESS - if not import_result.import_errors - else messages.WARNING, + ( + messages.SUCCESS + if not import_result.import_errors + else messages.WARNING + ), ) if errors := import_result.import_errors: msgs_deduped = set(error.__str__() for error in errors) diff --git a/src/open_inwoner/openzaak/api_models.py b/src/open_inwoner/openzaak/api_models.py index 0b58d4448e..a399315169 100644 --- a/src/open_inwoner/openzaak/api_models.py +++ b/src/open_inwoner/openzaak/api_models.py @@ -12,6 +12,8 @@ from open_inwoner.utils.glom import glom_multiple +from .constants import ZaakTitleDisplayChoices + logger = logging.getLogger(__name__) @@ -105,9 +107,22 @@ def description(self) -> str: zaak_config = OpenZaakConfig.get_solo() - description = self.zaaktype.omschrijving - if zaak_config.use_zaak_omschrijving_as_title and self.omschrijving: - description = self.omschrijving + description = "" + match zaak_config.derive_zaak_titel_from: + case ZaakTitleDisplayChoices.zaak_omschrijving: + description = self.omschrijving + case ZaakTitleDisplayChoices.zaaktype_omschrijving: + description = self.zaaktype.omschrijving + case ZaakTitleDisplayChoices.zaaktype_onderwerp: + description = self.zaaktype.onderwerp + case _: + raise ValueError( + "Invalid choice `{zaak_config.derive_zaak_titel_from}` for " + " `OpenZaakConfig.derive_zaak_titel_from`" + ) + + if not description: + logger.error("No valid description found for zaak: %s", self.identificatie) return description diff --git a/src/open_inwoner/openzaak/constants.py b/src/open_inwoner/openzaak/constants.py index 7a28d76e8a..a00287b2c0 100644 --- a/src/open_inwoner/openzaak/constants.py +++ b/src/open_inwoner/openzaak/constants.py @@ -7,3 +7,15 @@ class StatusIndicators(models.TextChoices): warning = "warning", _("Warning") failure = "failure", _("Failure") success = "success", _("Success") + + +class ZaakTitleDisplayChoices(models.TextChoices): + zaak_omschrijving = "zaak_omschrijving", _( + "The description of the case (`zaak.omschrijving`)" + ) + zaaktype_omschrijving = "zaaktype_omschrijving", _( + "The description of the case's type (`zaaktype.omschrijving`)" + ) + zaaktype_onderwerp = "zaaktype_onderwerp", _( + "The subject of the case's type (`zaaktype.onderwerp`)" + ) diff --git a/src/open_inwoner/openzaak/migrations/0060_remove_openzaakconfig_use_zaak_omschrijving_as_title_and_more.py b/src/open_inwoner/openzaak/migrations/0060_remove_openzaakconfig_use_zaak_omschrijving_as_title_and_more.py new file mode 100644 index 0000000000..eea3458de0 --- /dev/null +++ b/src/open_inwoner/openzaak/migrations/0060_remove_openzaakconfig_use_zaak_omschrijving_as_title_and_more.py @@ -0,0 +1,90 @@ +# Generated by Django 4.2.18 on 2025-01-22 12:06 +import logging + +from django.db import migrations, models + +logger = logging.getLogger(__name__) + + +def migrate_use_zaak_omschrijving_as_title(apps, _): + from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices + + OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig") + + if config := OpenZaakConfig.objects.first(): + if config.use_zaak_omschrijving_as_title: + logger.info( + "Setting OpenZaakConfig.derive_zaak_titel_from to %s because " + "OpenZaakConfig.use_zaak_omschrijving_as_title = True", + ZaakTitleDisplayChoices.zaak_omschrijving, + ) + config.derive_zaak_titel_from = ZaakTitleDisplayChoices.zaak_omschrijving + else: + logger.info( + "Setting OpenZaakConfig.derive_zaak_titel_from to %s because " + "OpenZaakConfig.use_zaak_omschrijving_as_title = False", + ZaakTitleDisplayChoices.zaaktype_omschrijving, + ) + config.derive_zaak_titel_from = ( + ZaakTitleDisplayChoices.zaaktype_omschrijving + ) + + config.save() + + # ZaakTitleDisplayChoices.zaaktype_omschrijving is a newly added option, so it won't + # be the default for anybody. + + +def reverse_migrate_use_zaak_omschrijving_as_title(apps, _): + from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices + + OpenZaakConfig = apps.get_model("openzaak", "OpenZaakConfig") + + if config := OpenZaakConfig.objects.first(): + if config.derive_zaak_titel_from == ZaakTitleDisplayChoices.zaak_omschrijving: + config.use_zaak_omschrijving_as_title = True + else: + config.use_zaak_omschrijving_as_title = False + + config.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("openzaak", "0059_openzaakconfig_show_cases_without_status"), + ] + + operations = [ + migrations.AddField( + model_name="openzaakconfig", + name="derive_zaak_titel_from", + field=models.CharField( + choices=[ + ( + "zaak_omschrijving", + "The description of the case (`zaak.omschrijving`)", + ), + ( + "zaaktype_omschrijving", + "The description of the case's type (`zaaktype.omschrijving`)", + ), + ( + "zaaktype_onderwerp", + "The subject of the case's type (`zaaktype.onderwerp`)", + ), + ], + default="zaaktype_omschrijving", + help_text="Which field from the underlying zaaksysteem to use to display the title for a zaak (e.g. on the Mijn Aanvragen page).", + verbose_name="Derive the case title from", + ), + ), + migrations.RunPython( + code=migrate_use_zaak_omschrijving_as_title, + reverse_code=reverse_migrate_use_zaak_omschrijving_as_title, + ), + migrations.RemoveField( + model_name="openzaakconfig", + name="use_zaak_omschrijving_as_title", + ), + ] diff --git a/src/open_inwoner/openzaak/models.py b/src/open_inwoner/openzaak/models.py index 8984ea85b0..2552945903 100644 --- a/src/open_inwoner/openzaak/models.py +++ b/src/open_inwoner/openzaak/models.py @@ -26,7 +26,7 @@ ZaakTypeStatusTypeConfigQuerySet, ) -from .constants import StatusIndicators +from .constants import StatusIndicators, ZaakTitleDisplayChoices logger = logging.getLogger(__name__) @@ -411,18 +411,14 @@ def form_service(self, service): ), default=False, ) - - use_zaak_omschrijving_as_title = models.BooleanField( - verbose_name=_( - "Make use of zaak.omschrijving for the title of the cases instead of " - "zaaktype.omschrijving (eSuite)" - ), + derive_zaak_titel_from = models.CharField( + choices=ZaakTitleDisplayChoices.choices, + default=ZaakTitleDisplayChoices.zaaktype_omschrijving, + verbose_name=_("Derive the case title from"), help_text=_( - "If enabled, we use zaak.omschrijving for the title of the cases, and use " - "zaaktype.omschrijving as a fallback in case it is not filled in. " - "If not enabled, we ignore zaak.omschrijving and always use zaaktype.omschrijving." + "Which field from the underlying zaaksysteem to use to display the title " + " for a zaak (e.g. on the Mijn Aanvragen page)." ), - default=False, ) order_statuses_by_date_set = models.BooleanField( verbose_name=_( diff --git a/src/open_inwoner/openzaak/tests/test_api_models.py b/src/open_inwoner/openzaak/tests/test_api_models.py index ff5fdf6257..de81234757 100644 --- a/src/open_inwoner/openzaak/tests/test_api_models.py +++ b/src/open_inwoner/openzaak/tests/test_api_models.py @@ -4,6 +4,7 @@ from zgw_consumers.api_models.base import factory from open_inwoner.openzaak.api_models import Zaak, ZaakType +from open_inwoner.openzaak.constants import ZaakTitleDisplayChoices from open_inwoner.openzaak.models import OpenZaakConfig @@ -111,7 +112,18 @@ def test_zaak_omschrijving(self): self.assertEqual(case.description, "Vergunning") zaak_config = OpenZaakConfig.get_solo() - zaak_config.use_zaak_omschrijving_as_title = True - zaak_config.save() - self.assertEqual(case.description, "Vergunning voor Joeri") + expected = { + ZaakTitleDisplayChoices.zaak_omschrijving: self.zaak_data["omschrijving"], + ZaakTitleDisplayChoices.zaaktype_omschrijving: zaaktype.omschrijving, + ZaakTitleDisplayChoices.zaaktype_onderwerp: zaaktype.onderwerp, + } + # Guard against new values + assert all(choice in expected.keys() for choice in ZaakTitleDisplayChoices) + + for config_setting, expected_value in expected.items(): + with self.subTest(config_setting): + zaak_config.derive_zaak_titel_from = config_setting + zaak_config.save() + + self.assertEqual(case.description, expected_value)