diff --git a/apptax/taxonomie/models.py b/apptax/taxonomie/models.py index 49e94a0e..90dcfe9c 100644 --- a/apptax/taxonomie/models.py +++ b/apptax/taxonomie/models.py @@ -216,6 +216,10 @@ def where_id_liste(cls, id_liste, *, query): def where_params(cls, filters=None, *, query): for filter in filters: + # Test empty values + if not filters[filter]: + continue + if hasattr(Taxref, filter) and isinstance(filters[filter], list): col = getattr(Taxref, filter) query = query.filter(col.in_(tuple(filters[filter]))) diff --git a/apptax/taxonomie/routestaxref.py b/apptax/taxonomie/routestaxref.py index abf500d3..a31088c3 100644 --- a/apptax/taxonomie/routestaxref.py +++ b/apptax/taxonomie/routestaxref.py @@ -163,10 +163,13 @@ def get_taxref_list(): page = request.values.get("page", 1, int) id_liste = None cd_nom = None + if "id_liste" in request.values: - id_liste = request.values.get("id_liste").split(",") + id_liste = ( + request.values.get("id_liste").split(",") if request.values.get("id_liste") else None + ) if "cd_nom" in request.values: - cd_nom = request.values.get("cd_nom").split(",") + cd_nom = request.values.get("cd_nom").split(",") if request.values.get("cd_nom") else None fields = request.values.get("fields", type=str, default=[]) parameters = request.values.to_dict() @@ -187,7 +190,6 @@ def get_taxref_list(): if id_liste and "-1" not in id_liste: query = Taxref.where_id_liste(id_liste, query=query) - count_filter = db.session.scalar( db.select(func.count()).select_from( Taxref.where_params(parameters, query=query), diff --git a/apptax/tests/test_taxref.py b/apptax/tests/test_taxref.py index cea8cf17..fe78249d 100644 --- a/apptax/tests/test_taxref.py +++ b/apptax/tests/test_taxref.py @@ -308,6 +308,7 @@ def test_get_taxref_list(self, liste_with_names): def test_get_taxref_list_filters_cd_noms(self): # Test de la route taxref avec des filtres sur le cd_nom + # 1 cd_nom response = self.client.get( url_for("taxref.get_taxref_list"), query_string={"cd_nom": 103536}, @@ -315,8 +316,16 @@ def test_get_taxref_list_filters_cd_noms(self): assert response.status_code == 200 assert len(response.json["items"]) == 1 + # Plusieurs cd_nom response = self.client.get( url_for("taxref.get_taxref_list"), query_string={"cd_nom": "103536, 461885,2891"}, ) assert len(response.json["items"]) == 3 + + # Valeur vide + response = self.client.get( + url_for("taxref.get_taxref_list"), + query_string={"cd_nom": ""}, + ) + assert response.status_code == 200