@@ -1321,6 +1321,202 @@ def test_invalid_filters(self):
13211321 self .assertEqual (error ["code" ], UNKNOWN_PARAMETERS_CODE )
13221322 self .assertEqual (error ["reason" ], ("Onbekende query parameters: invalid" ))
13231323
1324+ def test_filter_by_vestigingsnummer_and_kvk_returns_correct_partij (self ):
1325+ company_a , company_b = PartijFactory .create_batch (2 )
1326+
1327+ kvk_a = PartijIdentificatorFactory .create (
1328+ partij = company_a ,
1329+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1330+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1331+ partij_identificator_object_id = "12345678" ,
1332+ )
1333+
1334+ kvk_b = PartijIdentificatorFactory .create (
1335+ partij = company_b ,
1336+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1337+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1338+ partij_identificator_object_id = "87654321" ,
1339+ )
1340+
1341+ vestiging_a = PartijFactory .create ()
1342+ vestiging_b = PartijFactory .create ()
1343+
1344+ PartijIdentificatorFactory .create (
1345+ partij = vestiging_a ,
1346+ sub_identificator_van = kvk_a ,
1347+ partij_identificator_code_objecttype = "vestiging" ,
1348+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1349+ partij_identificator_object_id = "000012345678" ,
1350+ )
1351+
1352+ PartijIdentificatorFactory .create (
1353+ partij = vestiging_b ,
1354+ sub_identificator_van = kvk_b ,
1355+ partij_identificator_code_objecttype = "vestiging" ,
1356+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1357+ partij_identificator_object_id = "000012345678" ,
1358+ )
1359+
1360+ response = self .client .get (
1361+ self .url ,
1362+ {
1363+ "subIdentificatorVan__objectId" : "12345678" ,
1364+ "partijIdentificator__objectId" : "000012345678" ,
1365+ },
1366+ )
1367+
1368+ self .assertEqual (response .status_code , status .HTTP_200_OK )
1369+
1370+ data = response .json ()["results" ]
1371+
1372+ self .assertEqual (1 , len (data ))
1373+ self .assertEqual (str (vestiging_a .uuid ), data [0 ]["uuid" ])
1374+
1375+ def test_filter_only_by_vestigingsnummer_returns_multiple (self ):
1376+ company_a , company_b = PartijFactory .create_batch (2 )
1377+
1378+ kvk_a = PartijIdentificatorFactory .create (
1379+ partij = company_a ,
1380+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1381+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1382+ partij_identificator_object_id = "12345678" ,
1383+ )
1384+
1385+ kvk_b = PartijIdentificatorFactory .create (
1386+ partij = company_b ,
1387+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1388+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1389+ partij_identificator_object_id = "87654321" ,
1390+ )
1391+
1392+ vestiging_a = PartijFactory .create ()
1393+ vestiging_b = PartijFactory .create ()
1394+
1395+ PartijIdentificatorFactory .create (
1396+ partij = vestiging_a ,
1397+ sub_identificator_van = kvk_a ,
1398+ partij_identificator_code_objecttype = "vestiging" ,
1399+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1400+ partij_identificator_object_id = "000012345678" ,
1401+ )
1402+
1403+ PartijIdentificatorFactory .create (
1404+ partij = vestiging_b ,
1405+ sub_identificator_van = kvk_b ,
1406+ partij_identificator_code_objecttype = "vestiging" ,
1407+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1408+ partij_identificator_object_id = "000012345678" ,
1409+ )
1410+
1411+ response = self .client .get (
1412+ self .url ,
1413+ {"partijIdentificator__objectId" : "000012345678" },
1414+ )
1415+
1416+ self .assertEqual (response .status_code , status .HTTP_200_OK )
1417+
1418+ data = response .json ()["results" ]
1419+
1420+ self .assertEqual (2 , len (data ))
1421+ self .assertEqual (data [0 ]["uuid" ], str (vestiging_b .uuid ))
1422+ self .assertEqual (data [1 ]["uuid" ], str (vestiging_a .uuid ))
1423+
1424+ def test_filter_by_sub_identificator_code_objecttype (self ):
1425+ company = PartijFactory .create ()
1426+
1427+ kvk = PartijIdentificatorFactory .create (
1428+ partij = company ,
1429+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1430+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1431+ partij_identificator_object_id = "12345678" ,
1432+ )
1433+
1434+ vestiging = PartijFactory .create ()
1435+
1436+ PartijIdentificatorFactory .create (
1437+ partij = vestiging ,
1438+ sub_identificator_van = kvk ,
1439+ partij_identificator_code_objecttype = "vestiging" ,
1440+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1441+ partij_identificator_object_id = "000012345678" ,
1442+ )
1443+
1444+ response = self .client .get (
1445+ self .url , {"subIdentificatorVan__codeObjecttype" : "niet_natuurlijk_persoon" }
1446+ )
1447+
1448+ self .assertEqual (response .status_code , status .HTTP_200_OK )
1449+
1450+ data = response .json ()["results" ]
1451+
1452+ self .assertEqual (1 , len (data ))
1453+ self .assertEqual (str (vestiging .uuid ), data [0 ]["uuid" ])
1454+
1455+ def test_filter_by_sub_identificator_code_soort_object_id (self ):
1456+ company = PartijFactory .create ()
1457+
1458+ kvk = PartijIdentificatorFactory .create (
1459+ partij = company ,
1460+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1461+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1462+ partij_identificator_object_id = "12345678" ,
1463+ )
1464+
1465+ vestiging = PartijFactory .create ()
1466+
1467+ PartijIdentificatorFactory .create (
1468+ partij = vestiging ,
1469+ sub_identificator_van = kvk ,
1470+ partij_identificator_code_objecttype = "vestiging" ,
1471+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1472+ partij_identificator_object_id = "000012345678" ,
1473+ )
1474+
1475+ response = self .client .get (
1476+ self .url , {"subIdentificatorVan__codeSoortObjectId" : "kvk_nummer" }
1477+ )
1478+
1479+ self .assertEqual (response .status_code , status .HTTP_200_OK )
1480+
1481+ data = response .json ()["results" ]
1482+
1483+ self .assertEqual (1 , len (data ))
1484+ self .assertEqual (str (vestiging .uuid ), data [0 ]["uuid" ])
1485+
1486+ def test_filter_by_sub_identificator_code_register (self ):
1487+ company = PartijFactory .create ()
1488+
1489+ kvk = PartijIdentificatorFactory .create (
1490+ partij = company ,
1491+ partij_identificator_code_objecttype = "niet_natuurlijk_persoon" ,
1492+ partij_identificator_code_soort_object_id = "kvk_nummer" ,
1493+ partij_identificator_object_id = "12345678" ,
1494+ partij_identificator_code_register = "hr" ,
1495+ )
1496+
1497+ vestiging = PartijFactory .create ()
1498+
1499+ PartijIdentificatorFactory .create (
1500+ partij = vestiging ,
1501+ sub_identificator_van = kvk ,
1502+ partij_identificator_code_objecttype = "vestiging" ,
1503+ partij_identificator_code_soort_object_id = "vestigingsnummer" ,
1504+ partij_identificator_object_id = "000012345678" ,
1505+ partij_identificator_code_register = "hr" ,
1506+ )
1507+
1508+ response = self .client .get (
1509+ self .url ,
1510+ {"subIdentificatorVan__codeRegister" : "hr" },
1511+ )
1512+
1513+ self .assertEqual (response .status_code , status .HTTP_200_OK )
1514+
1515+ data = response .json ()["results" ]
1516+
1517+ self .assertEqual (1 , len (data ))
1518+ self .assertEqual (str (vestiging .uuid ), data [0 ]["uuid" ])
1519+
13241520
13251521class CategorieRelatieFiltersetTests (APITestCase ):
13261522 url = reverse ("klantinteracties:categorierelatie-list" )
0 commit comments