feat(observatoire): filtres liste via list_has_any (#72)
This commit is contained in:
@@ -181,4 +181,20 @@ def dashboard_filters_to_sql(
|
|||||||
clauses.append('"sousTraitanceDeclaree" = ?')
|
clauses.append('"sousTraitanceDeclaree" = ?')
|
||||||
params.append(dashboard_marche_sous_traitance_declaree)
|
params.append(dashboard_marche_sous_traitance_declaree)
|
||||||
|
|
||||||
|
if dashboard_marche_techniques:
|
||||||
|
clauses.append("list_has_any(string_split(\"techniques\", ', '), ?::VARCHAR[])")
|
||||||
|
params.append(list(dashboard_marche_techniques))
|
||||||
|
|
||||||
|
if dashboard_marche_considerations_sociales:
|
||||||
|
clauses.append(
|
||||||
|
"list_has_any(string_split(\"considerationsSociales\", ', '), ?::VARCHAR[])"
|
||||||
|
)
|
||||||
|
params.append(list(dashboard_marche_considerations_sociales))
|
||||||
|
|
||||||
|
if dashboard_marche_considerations_environnementales:
|
||||||
|
clauses.append(
|
||||||
|
"list_has_any(string_split(\"considerationsEnvironnementales\", ', '), ?::VARCHAR[])"
|
||||||
|
)
|
||||||
|
params.append(list(dashboard_marche_considerations_environnementales))
|
||||||
|
|
||||||
return " AND ".join(clauses), params
|
return " AND ".join(clauses), params
|
||||||
|
|||||||
@@ -144,3 +144,39 @@ def test_titulaire_id_present_skips_categorie_and_departement():
|
|||||||
)
|
)
|
||||||
assert where_sql == 'YEAR("dateNotification") = ? AND "titulaire_id" LIKE ?'
|
assert where_sql == 'YEAR("dateNotification") = ? AND "titulaire_id" LIKE ?'
|
||||||
assert params == [2025, "%999%"]
|
assert params == [2025, "%999%"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_marche_techniques_uses_list_has_any():
|
||||||
|
where_sql, params = dashboard_filters_to_sql(
|
||||||
|
dashboard_year="2025",
|
||||||
|
dashboard_marche_techniques=["Enchère", "Accord-cadre"],
|
||||||
|
)
|
||||||
|
assert where_sql == (
|
||||||
|
'YEAR("dateNotification") = ? '
|
||||||
|
"AND list_has_any(string_split(\"techniques\", ', '), ?::VARCHAR[])"
|
||||||
|
)
|
||||||
|
assert params == [2025, ["Enchère", "Accord-cadre"]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_considerations_sociales_uses_list_has_any():
|
||||||
|
where_sql, params = dashboard_filters_to_sql(
|
||||||
|
dashboard_year="2025",
|
||||||
|
dashboard_marche_considerations_sociales=["Clause sociale"],
|
||||||
|
)
|
||||||
|
assert where_sql == (
|
||||||
|
'YEAR("dateNotification") = ? '
|
||||||
|
"AND list_has_any(string_split(\"considerationsSociales\", ', '), ?::VARCHAR[])"
|
||||||
|
)
|
||||||
|
assert params == [2025, ["Clause sociale"]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_considerations_environnementales_uses_list_has_any():
|
||||||
|
where_sql, params = dashboard_filters_to_sql(
|
||||||
|
dashboard_year="2025",
|
||||||
|
dashboard_marche_considerations_environnementales=["Clause env."],
|
||||||
|
)
|
||||||
|
assert where_sql == (
|
||||||
|
'YEAR("dateNotification") = ? '
|
||||||
|
"AND list_has_any(string_split(\"considerationsEnvironnementales\", ', '), ?::VARCHAR[])"
|
||||||
|
)
|
||||||
|
assert params == [2025, ["Clause env."]]
|
||||||
|
|||||||
Reference in New Issue
Block a user