Skip to content

Commit

Permalink
Merge pull request #4347 from GeotrekCE/fix_intervention_status_check
Browse files Browse the repository at this point in the history
🐛 [BUG] Fix error when creating an intervention without a report (suricate workflow)
  • Loading branch information
justinefricou authored Oct 22, 2024
2 parents be885a5 + 7da5e49 commit f49f3c5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
**Bug fixes**

- Fix `loadinfrastructure` condition when adding to infra without `eid-field` option (#4328)
- Fix intervention creation when target is not a report (suricate workflow)


2.109.2+dev (XXXX-XX-XX)
Expand Down
11 changes: 5 additions & 6 deletions geotrek/maintenance/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ def clean(self, *args, **kwargs):
if 'geotrek.feedback' in settings.INSTALLED_APPS and settings.SURICATE_WORKFLOW_ENABLED:
target = self.instance.target
intervention_is_updated = self.instance.pk
target_is_a_report = target and isinstance(target, Report)
report_is_programmed_or_late = target.status and target.status.identifier in ["programmed", "late_resolution"]
intervention_is_being_resolved_without_end_date = status == InterventionStatus.objects.get(order=30) and end_date is None
if intervention_is_updated and target_is_a_report and report_is_programmed_or_late and \
intervention_is_being_resolved_without_end_date:
self.add_error('end_date', _('End date is required.'))
if target and isinstance(target, Report):
report_is_programmed_or_late = target.status and target.status.identifier in ["programmed", "late_resolution"]
intervention_is_being_resolved_without_end_date = status == InterventionStatus.objects.get(order=30) and end_date is None
if intervention_is_updated and report_is_programmed_or_late and intervention_is_being_resolved_without_end_date:
self.add_error('end_date', _('End date is required.'))
return clean_data

def save(self, *args, **kwargs):
Expand Down
29 changes: 27 additions & 2 deletions geotrek/maintenance/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.test import TestCase
from unittest import skipIf

from django.conf import settings
from django.test import TestCase, override_settings
from geotrek.authent.tests.factories import UserFactory
from geotrek.common.tests import TranslationResetMixin
from geotrek.maintenance.tests.factories import InterventionJobFactory, LightInterventionFactory, ManDayFactory
from geotrek.maintenance.tests.factories import InterventionJobFactory, LightInterventionFactory, ManDayFactory, InterventionStatusFactory
from geotrek.signage.tests.factories import SignageFactory
from geotrek.core.tests.factories import TopologyFactory, PathFactory
from geotrek.maintenance.forms import InterventionForm, ManDayForm, ProjectForm


Expand Down Expand Up @@ -50,6 +55,11 @@ class InterventionFormTest(TestCase):
def setUpTestData(cls):
cls.interv = LightInterventionFactory()
cls.user = UserFactory()
topo = TopologyFactory()
path = PathFactory()
cls.topology = '[{"pk": %d, "paths": [%d], "positions": {"0": [0.674882030756843, 0.110030805790642]}}]' % (topo.pk, path.pk)
cls.target = SignageFactory(),
cls.interv_status = InterventionStatusFactory(order=30)

def test_end_date_after_start_date(self):
form = InterventionForm(
Expand All @@ -60,6 +70,21 @@ def test_end_date_after_start_date(self):
self.assertFalse(form.is_valid())
self.assertIn("Begin date is after end date", str(form.errors))

@skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only')
@override_settings(SURICATE_WORKFLOW_ENABLED=True)
def test_create_intervention_if_target_is_not_report(self):
form = InterventionForm(
data={
"name": "abc",
"topology": self.topology,
"target": self.target,
"begin_date": "10/02/2024",
"status": self.interv_status
},
user=self.user,
)
self.assertTrue(form.is_valid())


class ProjectDateFormTest(TranslationResetMixin, TestCase):

Expand Down

0 comments on commit f49f3c5

Please sign in to comment.