diff --git a/src/open_inwoner/accounts/views/contactmoments.py b/src/open_inwoner/accounts/views/contactmoments.py index 679cffe74..a0d265142 100644 --- a/src/open_inwoner/accounts/views/contactmoments.py +++ b/src/open_inwoner/accounts/views/contactmoments.py @@ -267,5 +267,11 @@ def get(self, request, *args, **kwargs): raise Http404 return HttpResponseRedirect( - reverse("cases:contactmoment_detail", kwargs={"kcm_uuid": kcm.uuid}) + reverse( + "cases:contactmoment_detail", + kwargs={ + "api_source": KlantenServiceType.esuite, + "kcm_uuid": kcm.uuid, + }, + ) ) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 9efa197b9..6a4242966 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -20,7 +20,6 @@ from django.views.generic import FormView, TemplateView from django_htmx.http import HttpResponseClientRedirect -from glom import glom from mail_editor.helpers import find_template from view_breadcrumbs import BaseBreadcrumbMixin from zgw_consumers.api_models.constants import RolOmschrijving @@ -28,11 +27,7 @@ from open_inwoner.mail.service import send_contact_confirmation_mail from open_inwoner.openklant.models import OpenKlantConfig from open_inwoner.openklant.services import eSuiteKlantenService, eSuiteVragenService -from open_inwoner.openklant.wrap import ( - contactmoment_has_new_answer, - get_fetch_parameters, - get_kcm_answer_mapping, -) +from open_inwoner.openklant.wrap import get_fetch_parameters from open_inwoner.openzaak.api_models import Status, StatusType, Zaak from open_inwoner.openzaak.clients import CatalogiClient, ZakenClient from open_inwoner.openzaak.documents import ( @@ -164,36 +159,16 @@ def get_context_data(self, **kwargs): # questions/E-suite contactmomenten try: - service = eSuiteVragenService(config=openklant_config) + esuite_service = eSuiteVragenService(config=openklant_config) except RuntimeError: logger.error("Failed to build eSuiteVragenService") - objectcontactmomenten = [] + questions = [] else: - objectcontactmomenten = service.retrieve_objectcontactmomenten_for_zaak( - self.case - ) - - questions = [] - for ocm in objectcontactmomenten: - question = getattr(ocm, "contactmoment", None) - if question: - questions.append(question) - questions.sort(key=lambda q: q.registratiedatum, reverse=True) - - kcm_answer_mapping = get_kcm_answer_mapping(questions, self.request.user) - for question in questions: - question.new_answer_available = contactmoment_has_new_answer( - question, kcm_answer_mapping + questions = esuite_service.retrieve_questions_for_zaak( + self.case, user=self.request.user ) - # filter questions - openklant_config = OpenKlantConfig.get_solo() - if exclude_range := openklant_config.exclude_contactmoment_kanalen: - questions = [ - item - for item in questions - if glom(item, "kanaal") not in exclude_range - ] + # TODO: fetch OpenKlant2 questions + combine statustypen = [] catalogi_client = api_group.catalogi_client diff --git a/src/open_inwoner/openklant/services.py b/src/open_inwoner/openklant/services.py index 77e7dcff0..2914ef1cb 100644 --- a/src/open_inwoner/openklant/services.py +++ b/src/open_inwoner/openklant/services.py @@ -701,6 +701,31 @@ def retrieve_question( return self._get_question_data(kcm), zaak_with_api_group + def retrieve_questions_for_zaak(self, zaak, user: User) -> list[Question]: + objectcontactmomenten = self.retrieve_objectcontactmomenten_for_zaak(zaak) + + questions = [] + for ocm in objectcontactmomenten: + question = getattr(ocm, "contactmoment", None) + if question: + questions.append(question) + questions.sort(key=lambda q: q.registratiedatum, reverse=True) + + kcm_answer_mapping = get_kcm_answer_mapping(questions, user) + for question in questions: + question.new_answer_available = contactmoment_has_new_answer( + question, kcm_answer_mapping + ) + + if exclude_range := self.config.exclude_contactmoment_kanalen: + questions = [ + item + for item in questions + if glom.glom(item, "kanaal") not in exclude_range + ] + + return questions + @dataclass(frozen=True) class OpenKlant2Answer: diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index 12948e00d..4b89c1ea1 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -28,7 +28,10 @@ from open_inwoner.accounts.tests.factories import UserFactory, eHerkenningUserFactory from open_inwoner.cms.cases.views.status import InnerCaseDetailView, SimpleFile from open_inwoner.openklant.api_models import ObjectContactMoment -from open_inwoner.openklant.constants import Status as ContactMomentStatus +from open_inwoner.openklant.constants import ( + KlantenServiceType, + Status as ContactMomentStatus, +) from open_inwoner.openklant.models import OpenKlantConfig from open_inwoner.openklant.services import eSuiteVragenService from open_inwoner.openklant.tests.factories import make_contactmoment @@ -2550,7 +2553,10 @@ def test_kcm_redirect(self, m): response, reverse( "cases:contactmoment_detail", - kwargs={"kcm_uuid": uuid_from_url(klant_contactmoment["url"])}, + kwargs={ + "api_source": KlantenServiceType.esuite, + "kcm_uuid": uuid_from_url(klant_contactmoment["url"]), + }, ), status_code=302, target_status_code=200,