From 5ec61b8415dd697220a3842a1660c87e112b25f2 Mon Sep 17 00:00:00 2001 From: Joaquim Nallar Date: Wed, 7 Feb 2024 13:56:25 +0100 Subject: [PATCH] add contractor on intervention model --- geotrek/maintenance/filters.py | 2 +- geotrek/maintenance/forms.py | 7 +++---- .../locale/de/LC_MESSAGES/django.po | 11 +++++++---- .../locale/en/LC_MESSAGES/django.po | 11 +++++++---- .../locale/es/LC_MESSAGES/django.po | 11 +++++++---- .../locale/fr/LC_MESSAGES/django.po | 11 +++++++---- .../locale/it/LC_MESSAGES/django.po | 11 +++++++---- .../locale/nl/LC_MESSAGES/django.po | 11 +++++++---- .../0026_intervention_contractors.py | 18 ++++++++++++++++++ geotrek/maintenance/models.py | 13 ++++++++++--- .../maintenance/intervention_detail.html | 6 ++++++ .../templates/maintenance/project_detail.html | 6 ++++++ .../maintenance/sql/post_20_views.sql | 8 ++++++++ geotrek/maintenance/tests/test_models.py | 10 +++++++++- geotrek/maintenance/tests/test_views.py | 2 ++ geotrek/maintenance/views.py | 4 ++-- 16 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 geotrek/maintenance/migrations/0026_intervention_contractors.py diff --git a/geotrek/maintenance/filters.py b/geotrek/maintenance/filters.py index 6ad9c6451c..fa2081e468 100644 --- a/geotrek/maintenance/filters.py +++ b/geotrek/maintenance/filters.py @@ -151,7 +151,7 @@ class InterventionFilterSet(AltimetryInterventionFilterSet, ZoningFilterSet, Str class Meta(StructureRelatedFilterSet.Meta): model = Intervention fields = StructureRelatedFilterSet.Meta.fields + [ - 'status', 'type', 'stake', 'subcontracting', 'project', 'on', + 'status', 'type', 'stake', 'subcontracting', 'project', 'contractors', 'on', ] def __init__(self, *args, **kwargs): diff --git a/geotrek/maintenance/forms.py b/geotrek/maintenance/forms.py index 5c95367441..3662b6b245 100644 --- a/geotrek/maintenance/forms.py +++ b/geotrek/maintenance/forms.py @@ -90,6 +90,7 @@ class InterventionForm(CommonForm): 'height', 'stake', 'project', + 'contractors', 'access', 'description', 'material_cost', @@ -104,7 +105,7 @@ class Meta(CommonForm.Meta): model = Intervention fields = CommonForm.Meta.fields + \ ['structure', 'name', 'begin_date', 'end_date', 'status', 'disorders', 'type', 'description', 'subcontracting', 'length', 'width', - 'height', 'stake', 'project', 'access', 'material_cost', 'heliport_cost', 'subcontract_cost', 'topology'] + 'height', 'stake', 'project', 'contractors', 'access', 'material_cost', 'heliport_cost', 'subcontract_cost', 'topology'] def __init__(self, *args, target_type=None, target_id=None, **kwargs): super().__init__(*args, **kwargs) @@ -204,9 +205,7 @@ class ProjectForm(CommonForm): 'constraint', 'global_cost', 'comments', - - css_class="span6"), - Div('project_owner', + 'project_owner', 'project_manager', 'contractors', Fieldset(_("Fundings")), diff --git a/geotrek/maintenance/locale/de/LC_MESSAGES/django.po b/geotrek/maintenance/locale/de/LC_MESSAGES/django.po index b10bb88ad5..41b3c487bf 100644 --- a/geotrek/maintenance/locale/de/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,6 +161,9 @@ msgstr "" msgid "Subcontract cost" msgstr "" +msgid "Contractors" +msgstr "" + msgid "3D Length" msgstr "" @@ -266,9 +269,6 @@ msgstr "" msgid "Domain" msgstr "" -msgid "Contractors" -msgstr "" - msgid "Project owner" msgstr "" @@ -281,6 +281,9 @@ msgstr "" msgid "Projects" msgstr "" +msgid "Interventions contractors" +msgstr "" + msgid "Period" msgstr "" diff --git a/geotrek/maintenance/locale/en/LC_MESSAGES/django.po b/geotrek/maintenance/locale/en/LC_MESSAGES/django.po index b10bb88ad5..41b3c487bf 100644 --- a/geotrek/maintenance/locale/en/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,6 +161,9 @@ msgstr "" msgid "Subcontract cost" msgstr "" +msgid "Contractors" +msgstr "" + msgid "3D Length" msgstr "" @@ -266,9 +269,6 @@ msgstr "" msgid "Domain" msgstr "" -msgid "Contractors" -msgstr "" - msgid "Project owner" msgstr "" @@ -281,6 +281,9 @@ msgstr "" msgid "Projects" msgstr "" +msgid "Interventions contractors" +msgstr "" + msgid "Period" msgstr "" diff --git a/geotrek/maintenance/locale/es/LC_MESSAGES/django.po b/geotrek/maintenance/locale/es/LC_MESSAGES/django.po index b10bb88ad5..41b3c487bf 100644 --- a/geotrek/maintenance/locale/es/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/es/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,6 +161,9 @@ msgstr "" msgid "Subcontract cost" msgstr "" +msgid "Contractors" +msgstr "" + msgid "3D Length" msgstr "" @@ -266,9 +269,6 @@ msgstr "" msgid "Domain" msgstr "" -msgid "Contractors" -msgstr "" - msgid "Project owner" msgstr "" @@ -281,6 +281,9 @@ msgstr "" msgid "Projects" msgstr "" +msgid "Interventions contractors" +msgstr "" + msgid "Period" msgstr "" diff --git a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po index 6637f48ce8..e336384292 100644 --- a/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -163,6 +163,9 @@ msgstr "Coût héliportage" msgid "Subcontract cost" msgstr "Coût sous-traitance" +msgid "Contractors" +msgstr "Prestataires" + msgid "3D Length" msgstr "Longueur 3D" @@ -268,9 +271,6 @@ msgstr "Commentaires" msgid "Domain" msgstr "Domaine" -msgid "Contractors" -msgstr "Prestataires" - msgid "Project owner" msgstr "Maître d'ouvrage" @@ -283,6 +283,9 @@ msgstr "Financeurs" msgid "Projects" msgstr "Chantiers" +msgid "Interventions contractors" +msgstr "Prestataires des interventions" + msgid "Period" msgstr "Période" diff --git a/geotrek/maintenance/locale/it/LC_MESSAGES/django.po b/geotrek/maintenance/locale/it/LC_MESSAGES/django.po index b10bb88ad5..41b3c487bf 100644 --- a/geotrek/maintenance/locale/it/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/it/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,6 +161,9 @@ msgstr "" msgid "Subcontract cost" msgstr "" +msgid "Contractors" +msgstr "" + msgid "3D Length" msgstr "" @@ -266,9 +269,6 @@ msgstr "" msgid "Domain" msgstr "" -msgid "Contractors" -msgstr "" - msgid "Project owner" msgstr "" @@ -281,6 +281,9 @@ msgstr "" msgid "Projects" msgstr "" +msgid "Interventions contractors" +msgstr "" + msgid "Period" msgstr "" diff --git a/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po b/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po index b10bb88ad5..41b3c487bf 100644 --- a/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po +++ b/geotrek/maintenance/locale/nl/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-11 15:38+0000\n" +"POT-Creation-Date: 2024-02-07 12:56+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,6 +161,9 @@ msgstr "" msgid "Subcontract cost" msgstr "" +msgid "Contractors" +msgstr "" + msgid "3D Length" msgstr "" @@ -266,9 +269,6 @@ msgstr "" msgid "Domain" msgstr "" -msgid "Contractors" -msgstr "" - msgid "Project owner" msgstr "" @@ -281,6 +281,9 @@ msgstr "" msgid "Projects" msgstr "" +msgid "Interventions contractors" +msgstr "" + msgid "Period" msgstr "" diff --git a/geotrek/maintenance/migrations/0026_intervention_contractors.py b/geotrek/maintenance/migrations/0026_intervention_contractors.py new file mode 100644 index 0000000000..829bc7c315 --- /dev/null +++ b/geotrek/maintenance/migrations/0026_intervention_contractors.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2024-02-05 09:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('maintenance', '0025_remove_intervention_date'), + ] + + operations = [ + migrations.AddField( + model_name='intervention', + name='contractors', + field=models.ManyToManyField(blank=True, related_name='interventions', to='maintenance.Contractor', verbose_name='Contractors'), + ), + ] diff --git a/geotrek/maintenance/models.py b/geotrek/maintenance/models.py index 0a860c789e..e6ce410c25 100755 --- a/geotrek/maintenance/models.py +++ b/geotrek/maintenance/models.py @@ -23,7 +23,7 @@ from geotrek.zoning.mixins import ZoningPropertiesMixin from mapentity.models import DuplicateMixin - +from django.contrib.postgres.aggregates import ArrayAgg if 'geotrek.signage' in settings.INSTALLED_APPS: from geotrek.signage.models import Blade @@ -50,6 +50,8 @@ class Intervention(ZoningPropertiesMixin, AddPropertyMixin, GeotrekMapEntityMixi material_cost = models.FloatField(default=0.0, blank=True, null=True, verbose_name=_("Material cost")) heliport_cost = models.FloatField(default=0.0, blank=True, null=True, verbose_name=_("Heliport cost")) subcontract_cost = models.FloatField(default=0.0, blank=True, null=True, verbose_name=_("Subcontract cost")) + contractors = models.ManyToManyField('Contractor', related_name="interventions", blank=True, + verbose_name=_("Contractors")) # AltimetryMixin for denormalized fields from related topology, updated via trigger. length = models.FloatField(editable=True, default=0.0, null=True, blank=True, verbose_name=_("3D Length")) @@ -549,8 +551,13 @@ def interventions_csv_display(self): return [str(i) for i in self.interventions.existing()] @property - def contractors_display(self): - return [str(c) for c in self.contractors.all()] + def intervention_contractors(self): + return self.interventions.aggregate( + intervention_contractors=ArrayAgg('contractors__contractor', distinct=True))['intervention_contractors'] + + @classproperty + def intervention_contractors_verbose_name(cls): + return _("Interventions contractors") @property def founders_display(self): diff --git a/geotrek/maintenance/templates/maintenance/intervention_detail.html b/geotrek/maintenance/templates/maintenance/intervention_detail.html index 660445d5da..4e6b9e4db2 100644 --- a/geotrek/maintenance/templates/maintenance/intervention_detail.html +++ b/geotrek/maintenance/templates/maintenance/intervention_detail.html @@ -95,6 +95,12 @@ {% else %} {% trans "None" %} {% endif %} + + + {{ intervention|verbose:"contractors" }} + + {% valuelist intervention.contractors.all %} + {% trans "Related object" %} diff --git a/geotrek/maintenance/templates/maintenance/project_detail.html b/geotrek/maintenance/templates/maintenance/project_detail.html index 9be09c10f0..db3a89b083 100644 --- a/geotrek/maintenance/templates/maintenance/project_detail.html +++ b/geotrek/maintenance/templates/maintenance/project_detail.html @@ -59,6 +59,12 @@ {% valuelist project.contractors.all %} + + {{ project|verbose:"intervention_contractors" }} + + {% valuelist project.intervention_contractors %} + + {% trans "Fundings" %} diff --git a/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql b/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql index 82fe311bdf..7d98b9c7ca 100644 --- a/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql +++ b/geotrek/maintenance/templates/maintenance/sql/post_20_views.sql @@ -25,6 +25,7 @@ SELECT a.id, j.nb_days AS "Cost", (a.material_cost+a.heliport_cost+a.subcontract_cost)::float AS "Total cost", h.name AS "Project", + m.contractor AS "Contractors", CASE WHEN k.app_label = 'core' THEN 'Tronçons' WHEN k.app_label = 'infrastructure' THEN 'Aménagements' @@ -38,6 +39,13 @@ SELECT a.id, a.date_update AS "Update date", a.geom_3d FROM maintenance_intervention a +LEFT JOIN + (SELECT array_to_string(array_agg(a.contractor), ', '::text, '_'::text) contractor, + intervention_id + FROM maintenance_contractor a + JOIN maintenance_intervention_contractors b ON a.id = b.contractor_id + JOIN maintenance_intervention c ON b.intervention_id = c.id + GROUP BY intervention_id) m ON a.id = m.intervention_id LEFT JOIN maintenance_interventiontype b ON a.type_id = b.id LEFT JOIN maintenance_interventionstatus c ON a.status_id = c.id LEFT JOIN core_stake d ON a.stake_id = d.id diff --git a/geotrek/maintenance/tests/test_models.py b/geotrek/maintenance/tests/test_models.py index b05e4837ed..9e469cfef4 100644 --- a/geotrek/maintenance/tests/test_models.py +++ b/geotrek/maintenance/tests/test_models.py @@ -17,7 +17,7 @@ FundingFactory, InfrastructureInterventionFactory, InfrastructurePointInterventionFactory, InterventionDisorderFactory, InterventionFactory, InterventionJobFactory, ManDayFactory, ProjectFactory, - SignageInterventionFactory) + SignageInterventionFactory, ContractorFactory) from geotrek.outdoor.tests.factories import CourseFactory, SiteFactory from geotrek.signage.tests.factories import BladeFactory, SignageFactory @@ -361,3 +361,11 @@ def test_trails_property(self): project.interventions.add(intervention_blade) project.interventions.add(intervention_course) self.assertQuerysetEqual(list(project.trails), ['trail_1', 'trail_2', 'trail_signage'], ordered=False, transform=str) + + def test_intervention_contractors(self): + project = ProjectFactory.create() + contractor1 = ContractorFactory.create(contractor="contractor1") + contractor2 = ContractorFactory.create(contractor="contractor2") + intervention = InterventionFactory.create(project=project) + intervention.contractors.set([contractor1, contractor2]) + self.assertEqual(project.intervention_contractors, ["contractor1", "contractor2"]) diff --git a/geotrek/maintenance/tests/test_views.py b/geotrek/maintenance/tests/test_views.py index 6b30a4293b..d207582589 100644 --- a/geotrek/maintenance/tests/test_views.py +++ b/geotrek/maintenance/tests/test_views.py @@ -84,6 +84,7 @@ def get_good_data(self): 'stake': StakeFactory.create().pk, 'height': 0.0, 'project': '', + 'contractors': [], 'width': 0.0, 'length': 0.0, 'status': InterventionStatus.objects.all()[0].pk, @@ -527,6 +528,7 @@ def get_good_data(self): 'global_cost': '12', 'comments': '', 'contractors': ContractorFactory.create().pk, + 'intervention_contractors_verbose_name': [], 'project_owner': OrganismFactory.create().pk, 'project_manager': OrganismFactory.create().pk, diff --git a/geotrek/maintenance/views.py b/geotrek/maintenance/views.py index 9adee721f5..8a7cdb6fae 100755 --- a/geotrek/maintenance/views.py +++ b/geotrek/maintenance/views.py @@ -98,7 +98,7 @@ def get_mandatory_columns(cls): default_extra_columns = [ 'name', 'begin_date', 'end_date', 'type', 'target', 'status', 'stake', - 'disorders', 'total_manday', 'project', 'subcontracting', + 'disorders', 'total_manday', 'project', 'contractors', 'subcontracting', 'width', 'height', 'area', 'structure', 'description', 'date_insert', 'date_update', 'material_cost', 'heliport_cost', 'subcontract_cost', @@ -198,7 +198,7 @@ class ProjectFormatList(MapEntityFormat, ProjectList): mandatory_columns = ['id'] default_extra_columns = [ 'structure', 'name', 'period', 'type', 'domain', 'constraint', 'global_cost', - 'interventions', 'interventions_total_cost', 'comments', 'contractors', + 'interventions', 'interventions_total_cost', 'comments', 'contractors', 'intervention_contractors', 'project_owner', 'project_manager', 'founders', 'date_insert', 'date_update', 'cities', 'districts', 'areas',