Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [BUG] Fix error when creating an intervention without a report (suricate workflow) #4347

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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
Loading