Skip to content

Commit

Permalink
[#3993] Added deriveAddress for addressNL component
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Jun 13, 2024
1 parent d378fdd commit 1b15b48
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 32 deletions.
45 changes: 43 additions & 2 deletions docs/manual/forms/examples/autofill_address.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@
Adres automatisch aanvullen
===========================

.. warning::

De oude functionaliteit (door gebruik te maken van een **Tekstveld** component)
zal uitgefaseerd worden in een nieuwere versie. In plaats hiervan dient gebruik
gemaakt te worden van het **addressNL** component, dat op dezelfde manier functioneert.

Configuratie (nieuwe versie)
============================

Eerst moet het volgende geconfigureerd worden:

* :ref:`BAG configuratie <configuration_prefill_bag>`: Voor het opzoeken van adressen.


Formulier maken
===============

1. Maak een formulier aan met de volgende waardes:

**Naam** : Demo adres

2. Klik op de **Stappen en velden** tab.
3. Klik in het menu links op **Stap toevoegen** en kies **Maak een nieuwe formulierdefinitie**.
4. Voer de volgende waardes in onder **(Herbruikbare) stapgegevens**:

**Naam** : Adresgegevens

5. Scroll naar **Velden**.
6. Klik op **Speciale velden** en sleep een **AddressNL** veld in het formulier:

**Label** : AddressNL

7. Vink **Adres afleiden** aan en klik op **Opslaan**.
8. Klik linksonderaan op **Opslaan** om het formulier op te slaan.

Je kunt nu het formulier bekijken door in de lijst te klikken op **Toon formulier**

Het nieuwe **addressNL** component werkt op dezelfde manier als de oude aanpak met het **Tekstveld** component.
Door de verplichte gegevens in te voeren (postcode en huisnummer) worden de stad en straatnaam afgeleid en
automatisch ingevuld in de juiste velden.

In dit voorbeeld maken we een deel-formulier bestaande uit 1 stap, waarbij de
straatnaam en stad automatisch worden ingevuld zodra de postcode en huisnummer
zijn ingevuld.
Expand All @@ -21,8 +62,8 @@ In dit voorbeeld gaan we er van uit dat u een
Download: :download:`autofill_address_2.zip <_assets/autofill_address_2.zip>`


Configuratie
============
Configuratie (deprecated)
==========================

Voor dit formulier is bepaalde configuratie nodig. Hieronder staan de onderdelen
die geconfigureerd moeten zijn:
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@open-formulieren/design-tokens": "^0.51.0",
"@open-formulieren/formio-builder": "^0.19.1",
"@open-formulieren/formio-builder": "^0.20.0",
"@open-formulieren/leaflet-tools": "^1.0.0",
"@rjsf/core": "^4.2.1",
"@tinymce/tinymce-react": "^4.3.2",
Expand Down
4 changes: 4 additions & 0 deletions src/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8289,6 +8289,10 @@ components:
city:
type: string
description: Found city
secretStreetCity:
type: string
title: city and street name secret
description: Secret for the combination of city and street name
required:
- city
- streetName
Expand Down
3 changes: 3 additions & 0 deletions src/openforms/contrib/brk/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class AddressValue(TypedDict):
house_number: str
house_letter: NotRequired[str]
house_number_addition: NotRequired[str]
city: NotRequired[str]
streetName: NotRequired[str]
secretStreetCity: NotRequired[str]
5 changes: 5 additions & 0 deletions src/openforms/contrib/kadaster/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class GetStreetNameAndCityViewResultSerializer(serializers.Serializer):
label=_("street name"), help_text=_("Found street name")
)
city = serializers.CharField(label=_("city"), help_text=_("Found city"))
secret_street_city = serializers.CharField(
label=_("city and street name secret"),
help_text=_("Secret for the combination of city and street name"),
required=False,
)


class LatitudeLongitudeSerializer(serializers.Serializer):
Expand Down
19 changes: 17 additions & 2 deletions src/openforms/contrib/kadaster/clients/bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests

from openforms.contrib.hal_client import HALClient
from openforms.formio.components.utils import salt_location_message

logger = logging.getLogger(__name__)

Expand All @@ -13,6 +14,7 @@
class AddressResult:
street_name: str
city: str
secret_street_city: str = ""


class BAGClient(HALClient):
Expand Down Expand Up @@ -53,7 +55,20 @@ def get_address(
return None

first_result = response_data["_embedded"]["adressen"][0]
street_name = first_result.pop("korteNaam")
city = first_result.pop("woonplaatsNaam")

secret_street_city = salt_location_message(
{
"postcode": postcode.upper().replace(" ", ""),
"number": house_number,
"city": city,
"street_name": street_name,
}
)

return AddressResult(
street_name=first_result.pop("korteNaam"),
city=first_result.pop("woonplaatsNaam"),
street_name=street_name,
city=city,
secret_street_city=secret_street_city,
)
7 changes: 6 additions & 1 deletion src/openforms/contrib/kadaster/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@


def check_bag_config_for_address_fields() -> str:
# this combines the old functionality of deriving the city and streetname
# via textbox, which is deprecated and will be removed, and the new one via
# the addressNL component
has_bag_usage = any(
component.get("deriveCity") or component.get("deriveStreetName")
component.get("deriveCity")
or component.get("deriveStreetName")
or component.get("deriveAddress")
for form in Form.objects.live()
for component in form.iter_components()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
@patch("openforms.contrib.kadaster.api.views.lookup_address")
def test_getting_street_name_and_city(self, m_lookup_address):
m_lookup_address.return_value = AddressResult(
street_name="Keizersgracht", city="Amsterdam"
street_name="Keizersgracht", city="Amsterdam", secret_street_city=""
)

response = self.client.get(
Expand All @@ -44,9 +44,10 @@ def test_getting_street_name_and_city(self, m_lookup_address):
)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()), 2)
self.assertEqual(len(response.json()), 3)
self.assertEqual(response.json()["streetName"], "Keizersgracht")
self.assertEqual(response.json()["city"], "Amsterdam")
self.assertEqual(response.json()["secretStreetCity"], "")

@patch(
"openforms.api.exception_handling.uuid.uuid4",
Expand Down Expand Up @@ -117,7 +118,7 @@ def test_getting_street_name_and_city_with_extra_query_params_ignores_extra_para
self, m_lookup_address
):
m_lookup_address.return_value = AddressResult(
street_name="Keizersgracht", city="Amsterdam"
street_name="Keizersgracht", city="Amsterdam", secret_street_city=""
)

response = self.client.get(
Expand All @@ -126,9 +127,10 @@ def test_getting_street_name_and_city_with_extra_query_params_ignores_extra_para
)

self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()), 2)
self.assertEqual(len(response.json()), 3)
self.assertEqual(response.json()["streetName"], "Keizersgracht")
self.assertEqual(response.json()["city"], "Amsterdam")
self.assertEqual(response.json()["secretStreetCity"], "")

@patch("openforms.contrib.kadaster.api.views.lookup_address")
def test_address_not_found_returns_empty_200_response(self, m_lookup_address):
Expand All @@ -146,7 +148,7 @@ def test_address_not_found_returns_empty_200_response(self, m_lookup_address):
@patch("openforms.contrib.kadaster.api.views.lookup_address")
def test_endpoint_uses_caching(self, m_lookup_address):
m_lookup_address.return_value = AddressResult(
street_name="Keizersgracht", city="Amsterdam"
street_name="Keizersgracht", city="Amsterdam", secret_street_city=""
)
endpoint = reverse("api:get-street-name-and-city-list")

Expand Down
54 changes: 54 additions & 0 deletions src/openforms/emails/tests/test_digest_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,60 @@ def test_invalid_bag_configuration_without_required_property_is_not_collected(

self.assertEqual(broken_configuration, [])

@patch("openforms.contrib.kadaster.models.KadasterApiConfig.get_solo")
def test_invalid_bag_configuration_for_address_nl_component_is_collected(
self, kd_config
):
kd_config.return_value = KadasterApiConfig(bag_service=None)

FormFactory.create(
generate_minimal_setup=True,
formstep__form_definition__configuration={
"components": [
{
"key": "addressNl",
"type": "addressNL",
"label": "Address NL",
"deriveAddress": True,
}
]
},
)

broken_configuration = collect_broken_configurations()

self.assertEqual(len(broken_configuration), 2)
self.assertIn(
"BAG Client", [config.config_name for config in broken_configuration]
)

@patch("openforms.contrib.kadaster.models.KadasterApiConfig.get_solo")
def test_invalid_bag_configuration_for_address_nl_component_not_collected_when_disabled(
self, kd_config
):
kd_config.return_value = KadasterApiConfig(bag_service=None)

FormFactory.create(
generate_minimal_setup=True,
formstep__form_definition__configuration={
"components": [
{
"key": "addressNl",
"type": "addressNL",
"label": "Address NL",
"deriveAddress": False,
}
]
},
)

broken_configuration = collect_broken_configurations()

self.assertEqual(len(broken_configuration), 1)
self.assertNotIn(
"BAG Client", [config.config_name for config in broken_configuration]
)


@override_settings(LANGUAGE_CODE="en")
class InvalidCertificatesTests(TestCase):
Expand Down
Loading

0 comments on commit 1b15b48

Please sign in to comment.