Skip to content

Commit

Permalink
Merge pull request #945 from maykinmedia/feature/1859-contactmoment-s…
Browse files Browse the repository at this point in the history
…ubject

[#1859] Replace e-suite subject with OIP subject in contactmomenten
  • Loading branch information
alextreme authored Jan 11, 2024
2 parents 8df3626 + 9a064fe commit cdb43e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
30 changes: 28 additions & 2 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime
from typing import List, TypedDict

Expand All @@ -14,14 +15,16 @@
from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openklant.api_models import KlantContactMoment
from open_inwoner.openklant.constants import Status
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import ContactFormSubject, OpenKlantConfig
from open_inwoner.openklant.wrap import (
fetch_klantcontactmoment,
fetch_klantcontactmomenten,
get_fetch_parameters,
)
from open_inwoner.utils.views import CommonPageMixin

logger = logging.getLogger(__name__)


class KlantContactMomentAccessMixin(AccessMixin):
"""
Expand Down Expand Up @@ -78,10 +81,33 @@ def get_kcm_data(self, kcm: KlantContactMoment) -> KCMDict:
# eSuite extra
"identificatie": kcm.contactmoment.identificatie,
"type": kcm.contactmoment.type,
"onderwerp": kcm.contactmoment.onderwerp,
"status": Status.safe_label(kcm.contactmoment.status, _("Onbekend")),
"antwoord": kcm.contactmoment.antwoord,
}

# replace e_suite_subject_code with OIP configured subject, if applicable
e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", None)

if not e_suite_subject_code:
data["onderwerp"] = None
else:
try:
subject = ContactFormSubject.objects.get(
subject_code=e_suite_subject_code
)
except (
ContactFormSubject.DoesNotExist,
ContactFormSubject.MultipleObjectsReturned,
) as e:
logger.warning(
"Could not determine subject ('onderwerp') for contactmoment %s (%s)",
kcm.contactmoment.url,
e,
)
data["onderwerp"] = None
else:
data["onderwerp"] = subject.subject

return data

def get_context_data(self, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openklant/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __init__(self):
kanaal="MAIL",
status=Status.afgehandeld,
antwoord="",
onderwerp="e_suite_subject_code",
)
self.contactmoment2 = generate_oas_component(
"cmc",
Expand All @@ -154,6 +155,7 @@ def __init__(self):
kanaal="MAIL",
status=Status.afgehandeld,
antwoord="",
onderwerp="e_suite_subject_code",
)
self.contactmoment_vestiging = generate_oas_component(
"cmc",
Expand Down
17 changes: 12 additions & 5 deletions src/open_inwoner/openklant/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django_webtest import WebTest

from open_inwoner.accounts.tests.factories import UserFactory
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.models import ContactFormSubject, OpenKlantConfig
from open_inwoner.openklant.tests.data import MockAPIReadData
from open_inwoner.utils.test import (
ClearCachesMixin,
Expand All @@ -31,6 +31,13 @@ def setUpTestData(cls):
super().setUpTestData()
MockAPIReadData.setUpServices()

# for testing replacement of e-suite "onderwerp" code with OIP configured subject
cls.contactformsubject = ContactFormSubject.objects.create(
subject="oip_subject",
subject_code="e_suite_subject_code",
config=OpenKlantConfig.get_solo(),
)

def test_list_for_bsn(self, m):
data = MockAPIReadData().install_mocks(m)

Expand All @@ -52,7 +59,7 @@ def test_list_for_bsn(self, m):
),
"channel": data.contactmoment["kanaal"].title(),
"text": data.contactmoment["tekst"],
"onderwerp": data.contactmoment["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment["antwoord"],
"identificatie": data.contactmoment["identificatie"],
"type": data.contactmoment["type"],
Expand Down Expand Up @@ -92,7 +99,7 @@ def test_list_for_kvk_or_rsin(self, m):
),
"channel": data.contactmoment2["kanaal"].title(),
"text": data.contactmoment2["tekst"],
"onderwerp": data.contactmoment2["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment2["antwoord"],
"identificatie": data.contactmoment2["identificatie"],
"type": data.contactmoment2["type"],
Expand Down Expand Up @@ -162,7 +169,7 @@ def test_show_detail_for_bsn(self, m):
),
"channel": data.contactmoment["kanaal"].title(),
"text": data.contactmoment["tekst"],
"onderwerp": data.contactmoment["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment["antwoord"],
"identificatie": data.contactmoment["identificatie"],
"type": data.contactmoment["type"],
Expand Down Expand Up @@ -199,7 +206,7 @@ def test_show_detail_for_kvk_or_rsin(self, m):
),
"channel": data.contactmoment2["kanaal"].title(),
"text": data.contactmoment2["tekst"],
"onderwerp": data.contactmoment2["onderwerp"],
"onderwerp": self.contactformsubject.subject,
"antwoord": data.contactmoment2["antwoord"],
"identificatie": data.contactmoment2["identificatie"],
"type": data.contactmoment2["type"],
Expand Down

0 comments on commit cdb43e8

Please sign in to comment.