Skip to content

Commit

Permalink
♻️ Use generic fetch_cases for kvk/bsn case fetching
Browse files Browse the repository at this point in the history
to avoid repeating the same logic to determine the fetch parameters
  • Loading branch information
stevenbal committed Feb 15, 2024
1 parent 5f4dea4 commit 6d83c30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
18 changes: 3 additions & 15 deletions src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.htmx.mixins import RequiresHtmxMixin
from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openzaak.cases import preprocess_data
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.formapi import fetch_open_submissions
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.types import UniformCase
from open_inwoner.openzaak.utils import get_fetch_parameters
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import CommonPageMixin

Expand Down Expand Up @@ -61,20 +61,8 @@ def get_cases(self):
if client is None:
return []

if self.request.user.kvk:
kvk_or_rsin = self.request.user.kvk
config = OpenZaakConfig.get_solo()
if config.fetch_eherkenning_zaken_with_rsin:
kvk_or_rsin = self.request.user.rsin
vestigingsnummer = get_kvk_branch_number(self.request.session)
if vestigingsnummer:
raw_cases = client.fetch_cases_by_kvk_or_rsin(
kvk_or_rsin=kvk_or_rsin, vestigingsnummer=vestigingsnummer
)
else:
raw_cases = client.fetch_cases_by_kvk_or_rsin(kvk_or_rsin=kvk_or_rsin)
else:
raw_cases = client.fetch_cases_by_bsn(self.request.user.bsn)
raw_cases = client.fetch_cases(**get_fetch_parameters(self.request))

preprocessed_cases = preprocess_data(raw_cases)
return preprocessed_cases

Expand Down
19 changes: 3 additions & 16 deletions src/open_inwoner/pdc/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

from open_inwoner.accounts.models import User
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openzaak.api_models import Zaak
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.models import OpenZaakConfig, ZaakTypeConfig
from open_inwoner.openzaak.models import ZaakTypeConfig
from open_inwoner.openzaak.utils import get_fetch_parameters


class ProductQueryset(models.QuerySet):
Expand Down Expand Up @@ -56,20 +56,7 @@ def filter_by_zaken_for_request(self, request):
if client is None:
return self.none()

if request.user.bsn:
cases = client.fetch_cases_by_bsn(request.user.bsn)
elif request.user.kvk:
kvk_or_rsin = request.user.kvk
config = OpenZaakConfig.get_solo()
if config.fetch_eherkenning_zaken_with_rsin:
kvk_or_rsin = request.user.rsin
vestigingsnummer = get_kvk_branch_number(request.session)
if vestigingsnummer:
cases = client.fetch_cases_by_kvk_or_rsin(
kvk_or_rsin=kvk_or_rsin, vestigingsnummer=vestigingsnummer
)
else:
cases = client.fetch_cases_by_kvk_or_rsin(kvk_or_rsin=kvk_or_rsin)
cases = client.fetch_cases(**get_fetch_parameters(request))

return self.filter_by_zaken(cases)

Expand Down

0 comments on commit 6d83c30

Please sign in to comment.