Skip to content

Commit

Permalink
Merge pull request #466 from MTES-MCT/use_data_from_hedge_input_ui
Browse files Browse the repository at this point in the history
Utilise le linéaire à arracher issue de la saisie des haies
  • Loading branch information
thibault authored Nov 12, 2024
2 parents bdc4888 + 609f695 commit f28b295
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
9 changes: 9 additions & 0 deletions envergo/moulinette/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ def clean(self):

return data

def clean_haies(self):
haies = self.cleaned_data["haies"]
if haies.length_to_remove() == 0:
self.add_error(
"haies",
"Vous devez indiquer les haies à arracher.",
)
return haies


class TriageFormHaie(forms.Form):
department = DisplayCharField(
Expand Down
20 changes: 6 additions & 14 deletions envergo/moulinette/regulations/conditionnalitepac.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@


class Bcae8Form(forms.Form):
lineaire_detruit = DisplayIntegerField(
label="Linéaire de haie détruit :",
required=True,
min_value=0,
widget=forms.TextInput(attrs={"placeholder": "En mètres"}),
display_unit="m",
)

lineaire_total = DisplayIntegerField(
label="Linéaire total de haie sur l’exploitation :",
label="Linéaire total de haies sur l’exploitation :",
required=True,
min_value=0,
widget=forms.TextInput(attrs={"placeholder": "En mètres"}),
Expand Down Expand Up @@ -102,19 +94,19 @@ class Bcae8(CriterionEvaluator):

def get_result_data(self):
is_petit = False
if "lineaire_detruit" in self.catalog and "lineaire_total" in self.catalog:
lineaire_detruit = self.catalog["haies"].length_to_remove()
if "lineaire_total" in self.catalog:
is_petit = (
self.catalog["lineaire_detruit"] <= 5
or self.catalog["lineaire_detruit"]
<= 0.02 * self.catalog["lineaire_total"]
lineaire_detruit <= 5
or lineaire_detruit <= 0.02 * self.catalog["lineaire_total"]
)

return (
self.catalog["profil"],
self.catalog["motif"],
self.catalog["reimplantation"],
is_petit,
self.catalog.get("lineaire_detruit"),
lineaire_detruit,
self.catalog.get("amenagement_dup"),
self.catalog.get("motif_qc"),
)
Expand Down
16 changes: 11 additions & 5 deletions envergo/moulinette/tests/test_conditionnalite_pac.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import MagicMock

import pytest

from envergo.geodata.conftest import france_map # noqa
Expand Down Expand Up @@ -27,11 +29,14 @@ def conditionnalite_pac_criteria(france_map): # noqa

def test_conditionnalite_pac_only_for_agri_pac():
ConfigHaieFactory()
haies = MagicMock()
haies.length_to_remove.return_value = 10
data = {
"profil": "autre",
"motif": "chemin_acces",
"reimplantation": "remplacement",
"department": "44",
"haies": haies,
}
for motif_choice in [
"transfert_parcelles",
Expand All @@ -58,20 +63,21 @@ def test_conditionnalite_pac_for_agri_pac():
"motif": "chemin_acces",
"reimplantation": "remplacement",
"department": "44",
"haies": MagicMock(),
}

moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
assert moulinette.result == "non_disponible", data

data["lineaire_detruit"] = 5
data["haies"].length_to_remove.return_value = 5
data["lineaire_total"] = 100
moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
assert moulinette.result == "non_soumis", data
assert moulinette.conditionnalite_pac.bcae8.result_code == "non_soumis_petit", data

data["lineaire_detruit"] = 6
data["haies"].length_to_remove.return_value = 6
data["lineaire_total"] = 100
moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
Expand All @@ -80,7 +86,7 @@ def test_conditionnalite_pac_for_agri_pac():
moulinette.conditionnalite_pac.bcae8.result_code == "soumis_remplacement"
), data

data["lineaire_detruit"] = 6
data["haies"].length_to_remove.return_value = 6
data["lineaire_total"] = 300
moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
Expand All @@ -101,7 +107,7 @@ def test_conditionnalite_pac_for_agri_pac():
moulinette.conditionnalite_pac.bcae8.result_code == "soumis_chemin_acces"
), data

data["lineaire_detruit"] = 11
data["haies"].length_to_remove.return_value = 11
moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
assert moulinette.result == "interdit", data
Expand Down Expand Up @@ -184,7 +190,7 @@ def test_conditionnalite_pac_for_agri_pac():
moulinette.conditionnalite_pac.bcae8.result_code == "interdit_chemin_acces"
), data

data["lineaire_detruit"] = 10
data["haies"].length_to_remove.return_value = 10
moulinette = MoulinetteHaie(data, data, False)
assert moulinette.is_evaluation_available()
assert moulinette.result == "soumis", data
Expand Down
5 changes: 4 additions & 1 deletion envergo/static/sass/project_haie.scss
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,14 @@ div#app {

dialog#hedge-input-modal {
width: 100%;
max-width: 100%;
height: 100%;
max-height: 100%;
overscroll-behavior: contain;
overflow: hidden;
border: none;
filter: drop-shadow(var(--lifted-shadow));
margin: 0;
padding: 0;
}

div#statistics {
Expand Down

0 comments on commit f28b295

Please sign in to comment.