diff --git a/loko/contracts/locale/en/LC_MESSAGES/django.mo b/loko/contracts/locale/en/LC_MESSAGES/django.mo index bf73ab1..a0c431b 100644 Binary files a/loko/contracts/locale/en/LC_MESSAGES/django.mo and b/loko/contracts/locale/en/LC_MESSAGES/django.mo differ diff --git a/loko/contracts/locale/en/LC_MESSAGES/django.po b/loko/contracts/locale/en/LC_MESSAGES/django.po index 29d547d..23cf9b3 100644 --- a/loko/contracts/locale/en/LC_MESSAGES/django.po +++ b/loko/contracts/locale/en/LC_MESSAGES/django.po @@ -2371,3 +2371,7 @@ msgstr "Automatically assign a control team" msgid "Si activé, une équipe de contrôle est automatiquement assignée aux interventions correctives de ce contrat." msgstr "If enabled, a control team is automatically assigned to corrective interventions for this contract." +#: contracts/templates/contracts/contracts_orders_detail.html:755 +msgid "Contrôleur assigné" +msgstr "Assigned controller" + diff --git a/loko/contracts/locale/fr/LC_MESSAGES/django.mo b/loko/contracts/locale/fr/LC_MESSAGES/django.mo index 0d49398..fe4478f 100644 Binary files a/loko/contracts/locale/fr/LC_MESSAGES/django.mo and b/loko/contracts/locale/fr/LC_MESSAGES/django.mo differ diff --git a/loko/contracts/locale/fr/LC_MESSAGES/django.po b/loko/contracts/locale/fr/LC_MESSAGES/django.po index ac0c7a3..4052f8e 100644 --- a/loko/contracts/locale/fr/LC_MESSAGES/django.po +++ b/loko/contracts/locale/fr/LC_MESSAGES/django.po @@ -2421,3 +2421,7 @@ msgstr "Assigner automatiquement une équipe de contrôle" msgid "Si activé, une équipe de contrôle est automatiquement assignée aux interventions correctives de ce contrat." msgstr "Si activé, une équipe de contrôle est automatiquement assignée aux interventions correctives de ce contrat." +#: contracts/templates/contracts/contracts_orders_detail.html:755 +msgid "Contrôleur assigné" +msgstr "Contrôleur assigné" + diff --git a/loko/contracts/locale/nl/LC_MESSAGES/django.mo b/loko/contracts/locale/nl/LC_MESSAGES/django.mo index 13b871d..a53d5cc 100644 Binary files a/loko/contracts/locale/nl/LC_MESSAGES/django.mo and b/loko/contracts/locale/nl/LC_MESSAGES/django.mo differ diff --git a/loko/contracts/locale/nl/LC_MESSAGES/django.po b/loko/contracts/locale/nl/LC_MESSAGES/django.po index d97110e..b7eba89 100644 --- a/loko/contracts/locale/nl/LC_MESSAGES/django.po +++ b/loko/contracts/locale/nl/LC_MESSAGES/django.po @@ -2377,3 +2377,7 @@ msgstr "Automatisch een controleteam toewijzen" msgid "Si activé, une équipe de contrôle est automatiquement assignée aux interventions correctives de ce contrat." msgstr "Indien geactiveerd wordt automatisch een controleteam toegewezen aan de correctieve interventies van dit contract." +#: contracts/templates/contracts/contracts_orders_detail.html:755 +msgid "Contrôleur assigné" +msgstr "Toegewezen controleur" + diff --git a/loko/contracts/templates/contracts/contracts_orders_detail.html b/loko/contracts/templates/contracts/contracts_orders_detail.html index 9adcc39..c57b9fe 100644 --- a/loko/contracts/templates/contracts/contracts_orders_detail.html +++ b/loko/contracts/templates/contracts/contracts_orders_detail.html @@ -751,18 +751,35 @@ {% translate "Titre" %} {% translate "Début" %} {% translate "Statut" %} + {% if order.contract.auto_assign_control_team %} + {% translate "Contrôleur assigné" %} + {% endif %} - - {% for intervention in interventions %} - - {{ intervention.code }} - {{ intervention.title }} - {{ intervention.begin_time|date:"d-m-Y H:i" }} - {{ intervention.get_status_display }} - - {% endfor %} - + + {% for intervention in interventions %} + + {{ intervention.code }} + {{ intervention.title }} + {{ intervention.begin_time|date:"d-m-Y H:i" }} + {{ intervention.get_status_display }} + {% if order.contract.auto_assign_control_team %} + + {% if intervention.assigned_controller %} + {{ intervention.assigned_controller.name }} + {% if intervention.assigned_control_team %} + ({{ intervention.assigned_control_team.name }}) + {% endif %} + {% elif intervention.assigned_control_team %} + {{ intervention.assigned_control_team.name }} + {% else %} + - + {% endif %} + + {% endif %} + + {% endfor %} + diff --git a/loko/contracts/tests.py b/loko/contracts/tests.py index 8bf0da5..9d21ca2 100644 --- a/loko/contracts/tests.py +++ b/loko/contracts/tests.py @@ -344,3 +344,119 @@ class GenerateClaimDeclarationTimelineTests(TestCase): self.assertEqual(timeline_event_2.event_type, "status_change") self.assertEqual(timeline_event_2.event_user, self.user) + +class ContractOrderDetailControllerDisplayTests(TestCase): + def setUp(self): + from datetime import date + from contracts.models import Contract, ContractOrder, Company, CompanyTeam, CompanyMember + from common.models import UserContractAccess + from interventions.models import Intervention + + self.client = Client() + self.user = User.objects.create_user(username="order_admin_user", password="password") + self.user_config = UserConfig.objects.create(user=self.user, is_intern=True) + self.admin_role, _ = Role.objects.get_or_create(name="admin") + self.user_config.roles.add(self.admin_role) + self.client.login(username="order_admin_user", password="password") + + self.company = Company.objects.create(name="Société Test Contrôle") + self.team_ctrl = CompanyTeam.objects.create( + name="Équipe Contrôle Nord", + company=self.company, + operation_types=[CompanyTeam.OPERATION_CONTROLS], + ) + ctrl_user = User.objects.create_user(username="ctrl_member_user", password="password") + self.controller_member = CompanyMember.objects.create( + user=ctrl_user, + name="Jean Contrôleur", + ) + self.controller_member.teams.add(self.team_ctrl) + + self.contract_with_ctrl = Contract.objects.create( + company=self.company, + contract_number="CTR-CTRL-001", + start_date=date(2025, 1, 1), + end_date=date(2026, 1, 1), + auto_assign_control_team=True, + ) + UserContractAccess.objects.create( + user_config=self.user_config, + contract=self.contract_with_ctrl, + can_view_interventions=True, + ) + self.order_with_ctrl = ContractOrder.objects.create( + contract=self.contract_with_ctrl, + order_code="ORD-CTRL-01", + order_status="pending", + order_date=date(2025, 1, 1), + delivery_date=date(2025, 1, 15), + description="Commande avec marché contrôlé", + ) + self.itv1 = Intervention.objects.create( + code="ITV-C01", + title="Intervention avec contrôleur", + contract=self.contract_with_ctrl, + order=self.order_with_ctrl, + assigned_control_team=self.team_ctrl, + assigned_controller=self.controller_member, + status="finished", + ) + self.itv2 = Intervention.objects.create( + code="ITV-C02", + title="Intervention équipe seule", + contract=self.contract_with_ctrl, + order=self.order_with_ctrl, + assigned_control_team=self.team_ctrl, + status="processed", + ) + + self.contract_without_ctrl = Contract.objects.create( + company=self.company, + contract_number="CTR-NO-CTRL-002", + start_date=date(2025, 1, 1), + end_date=date(2026, 1, 1), + auto_assign_control_team=False, + ) + UserContractAccess.objects.create( + user_config=self.user_config, + contract=self.contract_without_ctrl, + can_view_interventions=True, + ) + self.order_without_ctrl = ContractOrder.objects.create( + contract=self.contract_without_ctrl, + order_code="ORD-NO-CTRL-02", + order_status="pending", + order_date=date(2025, 1, 1), + delivery_date=date(2025, 1, 15), + description="Commande sans marché contrôlé", + ) + self.itv3 = Intervention.objects.create( + code="ITV-NC01", + title="Intervention classique", + contract=self.contract_without_ctrl, + order=self.order_without_ctrl, + status="finished", + ) + + def test_order_detail_shows_controller_when_contract_has_auto_assign_control_team(self): + url = reverse("contracts:contracts_orders_detail", kwargs={"order_id": self.order_with_ctrl.id}) + response = self.client.get(url, HTTP_ACCEPT_LANGUAGE='fr') + self.assertEqual(response.status_code, 200) + + # Check th exists + self.assertContains(response, 'data-field="assigned_controller"') + self.assertContains(response, 'Contrôleur assigné') + + # Check td contents + self.assertContains(response, 'Jean Contrôleur') + self.assertContains(response, 'Équipe Contrôle Nord') + + def test_order_detail_hides_controller_when_contract_does_not_have_auto_assign_control_team(self): + url = reverse("contracts:contracts_orders_detail", kwargs={"order_id": self.order_without_ctrl.id}) + response = self.client.get(url, HTTP_ACCEPT_LANGUAGE='fr') + self.assertEqual(response.status_code, 200) + + # Check th does not exist + self.assertNotContains(response, 'data-field="assigned_controller"') + self.assertNotContains(response, 'Contrôleur assigné') + diff --git a/loko/contracts/views.py b/loko/contracts/views.py index 78bfdde..27659fd 100644 --- a/loko/contracts/views.py +++ b/loko/contracts/views.py @@ -108,8 +108,8 @@ def contracts_detail(request, contract_id): @order_view_required def contracts_orders_detail(request, order_id): - order = ContractOrder.objects.get(id=order_id) - interventions = order.interventions.all() + order = ContractOrder.objects.select_related('contract').get(id=order_id) + interventions = order.interventions.all().select_related('assigned_controller', 'assigned_control_team') # Normalize numeric values to Decimal to avoid float/Decimal mixing errors total = order.total_amount diff --git a/loko/home/templates/home/widgets/controller_shortcuts.html b/loko/home/templates/home/widgets/controller_shortcuts.html index 974a5e3..7f4c537 100644 --- a/loko/home/templates/home/widgets/controller_shortcuts.html +++ b/loko/home/templates/home/widgets/controller_shortcuts.html @@ -3,7 +3,7 @@ {# ========== Widget raccourcis pour les contrôleurs ========== #}
- {% translate "Interventions à contrôler" %} @@ -15,7 +15,7 @@ {# --- Compteur principal et sous-raccourcis --- #} @@ -64,7 +64,7 @@