From 8b4ccf1b394454bc917f50561ca8a8b25291add2 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Thu, 6 Feb 2025 12:19:45 +0100 Subject: [PATCH 1/9] feat(regulations): variables dict accept default value --- app/domain/regulations_helper.py | 10 ++++++++++ app/tests/regulations/test_utils.py | 25 ++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/domain/regulations_helper.py b/app/domain/regulations_helper.py index c7e4b6ce..b5a274cd 100644 --- a/app/domain/regulations_helper.py +++ b/app/domain/regulations_helper.py @@ -1,3 +1,6 @@ +DEFAULT_KEY = "default" + + def resolve_variables(dict_var, business): res_dict = {} for key, val in dict_var.items(): @@ -6,10 +9,17 @@ def resolve_variables(dict_var, business): if transport_type != business.transport_type.name: continue if isinstance(val2, dict): + default_value = None for business_type, val3 in val2.items(): + if business_type == DEFAULT_KEY: + default_value = val3 + continue if business_type != business.business_type.name: continue res_dict[key] = val3 + break + if not (key in res_dict) and default_value: + res_dict[key] = default_value else: res_dict[key] = val2 else: diff --git a/app/tests/regulations/test_utils.py b/app/tests/regulations/test_utils.py index 5f5954bf..4f256bc9 100644 --- a/app/tests/regulations/test_utils.py +++ b/app/tests/regulations/test_utils.py @@ -1,6 +1,6 @@ from unittest import TestCase -from app.domain.regulations_helper import resolve_variables +from app.domain.regulations_helper import resolve_variables, DEFAULT_KEY from app.models import Business from app.models.business import TransportType, BusinessType @@ -18,6 +18,9 @@ def setUp(self): transport_type=TransportType.TRV, business_type=BusinessType.FREQUENT, ) + self.business_vtc = Business( + transport_type=TransportType.TRV, business_type=BusinessType.VTC + ) self.dict_simple = {KEY: RES_SIMPLE} self.dict_granular = { KEY: { @@ -28,6 +31,15 @@ def setUp(self): str(TransportType.TRV.name): 4, } } + self.dict_default_value = { + KEY: { + str(TransportType.TRM.name): 1, + str(TransportType.TRV.name): { + str(BusinessType.VTC.name): 2, + DEFAULT_KEY: 3, + }, + } + } def test_simple_dict(self): @@ -52,3 +64,14 @@ def test_granular(self): dict_var=self.dict_granular, business=self.business_trv_frequent ) self.assertEqual(res_trm[KEY], 4) + + def test_default_value(self): + res_vtc = resolve_variables( + dict_var=self.dict_default_value, business=self.business_vtc + ) + self.assertEqual(res_vtc[KEY], 2) + res_trv = resolve_variables( + dict_var=self.dict_default_value, + business=self.business_trv_frequent, + ) + self.assertEqual(res_trv[KEY], 3) From 57e94188a3ea26e4547025d15a01f43195c1244c Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Thu, 6 Feb 2025 12:20:43 +0100 Subject: [PATCH 2/9] feat(regulations,tests): trv max work time depends on amplitude --- .../regulations/test_maximum_work_day_time.py | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) diff --git a/app/tests/regulations/test_maximum_work_day_time.py b/app/tests/regulations/test_maximum_work_day_time.py index dcb3952d..69eaa48e 100644 --- a/app/tests/regulations/test_maximum_work_day_time.py +++ b/app/tests/regulations/test_maximum_work_day_time.py @@ -365,3 +365,241 @@ def test_no_night_hours_end(self): self.assertIsNotNone(regulatory_alert) extra_info = regulatory_alert.extra self.assertEqual(extra_info["night_work"], False) + + ## T3P (Taxi, VTC, LOTI) + ## 9h if amplitude > 12h + ## 10h if amplitude <= 12h + def test_ok_t3p_low_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_vtc() + + self._log_and_validate_mission( + mission_name="11h amplitude - 9h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=12, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=17, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNone(regulatory_alert) + + def test_ko_t3p_low_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_vtc() + + self._log_and_validate_mission( + mission_name="11h amplitude - 10h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=17, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNotNone(regulatory_alert) + + def test_ok_t3p_high_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_vtc() + + self._log_and_validate_mission( + mission_name="13h amplitude - 8h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=15, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=19, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNone(regulatory_alert) + + def test_ko_t3p_high_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_vtc() + + self._log_and_validate_mission( + mission_name="13h amplitude - 9h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=14, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=19, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNotNone(regulatory_alert) + + ## TRV Frequent + ## 9h if amplitude > 13h + ## 10h if amplitude <= 13h + def test_ok_trv_frequent_low_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_trv() + + self._log_and_validate_mission( + mission_name="12h amplitude - 9h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=13, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=18, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNone(regulatory_alert) + + def test_ko_trv_frequent_low_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_trv() + + self._log_and_validate_mission( + mission_name="12h amplitude - 10h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=12, minute=30 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=18, minute=0 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNotNone(regulatory_alert) + + def test_ok_trv_frequent_high_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_trv() + + self._log_and_validate_mission( + mission_name="13h30 amplitude - 8h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=16, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=19, minute=30 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNone(regulatory_alert) + + def test_ko_trv_frequent_high_amplitude(self): + how_many_days_ago = 2 + self.convert_employee_to_trv() + + self._log_and_validate_mission( + mission_name="13h30 amplitude - 9h30 travail", + submitter=self.employee, + work_periods=[ + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=6, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=11, minute=0 + ), + ], + [ + get_time( + how_many_days_ago=how_many_days_ago, hour=15, minute=0 + ), + get_time( + how_many_days_ago=how_many_days_ago, hour=19, minute=30 + ), + ], + ], + ) + regulatory_alert = _get_alert(days_ago=how_many_days_ago) + self.assertIsNotNone(regulatory_alert) From 2e1f9f454141dedd84b8e5f4fdbb993073a54a6f Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Thu, 6 Feb 2025 13:19:10 +0100 Subject: [PATCH 3/9] feat(regulations): trv max work time depends on amplitude - implementation --- app/domain/regulations_per_day.py | 23 ++++++++++++++++++++++- app/services/get_regulation_checks.py | 22 +++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/domain/regulations_per_day.py b/app/domain/regulations_per_day.py index 349b1e2d..fb8420b2 100644 --- a/app/domain/regulations_per_day.py +++ b/app/domain/regulations_per_day.py @@ -252,13 +252,34 @@ def check_max_work_day_time(activity_groups, regulation_check, business): MAXIMUM_DURATION_OF_DAY_WORK_IN_HOURS = dict_variables[ "MAXIMUM_DURATION_OF_DAY_WORK_IN_HOURS" ] + AMPLITUDE_TRIGGER_IN_HOURS = dict_variables.get( + "AMPLITUDE_TRIGGER_IN_HOURS", None + ) + MAXIMUM_DURATION_OF_DAY_WORK_IF_HIGH_AMPLITUDE_IN_HOURS = ( + dict_variables.get( + "MAXIMUM_DURATION_OF_DAY_WORK_IF_HIGH_AMPLITUDE_IN_HOURS", None + ) + ) extra = None for group in activity_groups: + max_work_day_time_in_hours = MAXIMUM_DURATION_OF_DAY_WORK_IN_HOURS + + # For some TRV businesses, max work day time is different if amplitude is above a particular value + if ( + AMPLITUDE_TRIGGER_IN_HOURS + and MAXIMUM_DURATION_OF_DAY_WORK_IF_HIGH_AMPLITUDE_IN_HOURS + ): + amplitude = group.service_duration + if amplitude > AMPLITUDE_TRIGGER_IN_HOURS * HOUR: + max_work_day_time_in_hours = ( + MAXIMUM_DURATION_OF_DAY_WORK_IF_HIGH_AMPLITUDE_IN_HOURS + ) + night_work = group.total_night_work_legislation_duration > 0 max_time_in_hours = ( MAXIMUM_DURATION_OF_NIGHT_WORK_IN_HOURS if night_work - else MAXIMUM_DURATION_OF_DAY_WORK_IN_HOURS + else max_work_day_time_in_hours ) worked_time_in_seconds = group.total_work_duration extra = dict( diff --git a/app/services/get_regulation_checks.py b/app/services/get_regulation_checks.py index 1ef44168..39bb8762 100644 --- a/app/services/get_regulation_checks.py +++ b/app/services/get_regulation_checks.py @@ -2,6 +2,7 @@ from datetime import date, datetime from typing import Optional +from app.domain.regulations_helper import DEFAULT_KEY from app.models.business import TransportType, BusinessType from app.models.regulation_check import ( RegulationCheckType, @@ -22,6 +23,10 @@ class RegulationCheckData: date_application_end: Optional[date] = None +DESCRIPTION_MAX_WORK_TRV_FREQUENT = "La durée du travail quotidien est limitée à 10h si l’amplitude de la journée est inférieure à 13h, et à 9h si l’amplitude est supérieure à 13h (article D. 3312-6 du Code des transports). Attention, les dérogations ne sont pas intégrées dans Mobilic." +DESCRIPTION_MAX_WORK_TRV_INFREQUENT = "La durée du travail quotidien est limitée à 10h (article D. 3312-6 du Code des transports). Attention, les dérogations ne sont pas intégrées dans Mobilic." +DESCRIPTION_MAX_WORK_TRV_OTHERS = "La durée du travail quotidien est limitée à 10h si l’amplitude de la journée est inférieure à 12h, et à 9h si l’amplitude est supérieure à 12h (article D. 3312-6 du Code des transports). Attention, les dérogations ne sont pas intégrées dans Mobilic." + REGULATION_CHECK_MAXIMUM_WORK_IN_CALENDAR_WEEK = RegulationCheckData( id=6, type=RegulationCheckType.MAXIMUM_WORK_IN_CALENDAR_WEEK, @@ -81,13 +86,24 @@ def get_regulation_checks(): str(TransportType.TRM.name): 12, str(TransportType.TRV.name): 10, }, + AMPLITUDE_TRIGGER_IN_HOURS={ + str(TransportType.TRM.name): None, + str(TransportType.TRV.name): { + BusinessType.FREQUENT.name: 13, + BusinessType.INFREQUENT.name: None, + DEFAULT_KEY: 12, + }, + }, + MAXIMUM_DURATION_OF_DAY_WORK_IF_HIGH_AMPLITUDE_IN_HOURS=9, DESCRIPTION={ str( TransportType.TRM.name ): "La durée du travail quotidien est limitée à 12h (article R. 3312-a51 du Code des transports).", - str( - TransportType.TRV.name - ): "La durée du travail quotidien est limitée à 10h (article D. 3312-6 du Code des transports). Attention, les dérogations ne sont pas intégrées dans Mobilic.", + str(TransportType.TRV.name): { + BusinessType.FREQUENT.name: DESCRIPTION_MAX_WORK_TRV_FREQUENT, + BusinessType.INFREQUENT.name: DESCRIPTION_MAX_WORK_TRV_INFREQUENT, + DEFAULT_KEY: DESCRIPTION_MAX_WORK_TRV_OTHERS, + }, }, NIGHT_WORK_DESCRIPTION={ str( From abd07c45f7f62a9c07856515bf35ea75d5dc6001 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Thu, 6 Feb 2025 13:19:33 +0100 Subject: [PATCH 4/9] feat(regulations, tests): trv max work time depends on amplitude - fixed tests --- app/services/get_businesses.py | 20 ++++++++++++++++++++ app/tests/regulations/__init__.py | 20 +++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/services/get_businesses.py b/app/services/get_businesses.py index aebd4a1b..3d0f1330 100644 --- a/app/services/get_businesses.py +++ b/app/services/get_businesses.py @@ -37,4 +37,24 @@ def get_businesses(): transport_type=TransportType.TRV, business_type=BusinessType.INFREQUENT, ), + BusinessData( + id=6, + transport_type=TransportType.TRV, + business_type=BusinessType.TAXI_GENERAL, + ), + BusinessData( + id=7, + transport_type=TransportType.TRV, + business_type=BusinessType.TAXI_REGULATED, + ), + BusinessData( + id=8, + transport_type=TransportType.TRV, + business_type=BusinessType.VTC, + ), + BusinessData( + id=9, + transport_type=TransportType.TRV, + business_type=BusinessType.LOTI, + ), ] diff --git a/app/tests/regulations/__init__.py b/app/tests/regulations/__init__.py index 5317d460..2c70e05d 100644 --- a/app/tests/regulations/__init__.py +++ b/app/tests/regulations/__init__.py @@ -101,16 +101,18 @@ def _log_and_validate_mission( ) return mission - def convert_employee_to_trv(self): - trv_business = Business.query.filter( - Business.business_type == BusinessType.FREQUENT.value + def _convert_employee_to_business(self, business_type): + business = Business.query.filter( + Business.business_type == business_type.value ).one_or_none() - self.employee.employments[0].business = trv_business + self.employee.employments[0].business = business db.session.commit() + def convert_employee_to_vtc(self): + self._convert_employee_to_business(BusinessType.VTC) + + def convert_employee_to_trv(self): + self._convert_employee_to_business(BusinessType.FREQUENT) + def convert_employee_to_trm_short_distance(self): - trm_short_distance_business = Business.query.filter( - Business.business_type == BusinessType.SHORT_DISTANCE.value - ).one_or_none() - self.employee.employments[0].business = trm_short_distance_business - db.session.commit() + self._convert_employee_to_business(BusinessType.SHORT_DISTANCE) From 02609a2bede132bc4def4722626dc6f3a45a81f2 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Thu, 6 Feb 2025 13:19:33 +0100 Subject: [PATCH 5/9] feat(regulations, tests): trv max work time depends on amplitude - fixed tests --- app/services/get_businesses.py | 20 ++++++++++ app/tests/regulations/__init__.py | 20 +++++----- ...7a_trv_max_work_time_based_on_amplitude.py | 40 +++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py diff --git a/app/services/get_businesses.py b/app/services/get_businesses.py index aebd4a1b..3d0f1330 100644 --- a/app/services/get_businesses.py +++ b/app/services/get_businesses.py @@ -37,4 +37,24 @@ def get_businesses(): transport_type=TransportType.TRV, business_type=BusinessType.INFREQUENT, ), + BusinessData( + id=6, + transport_type=TransportType.TRV, + business_type=BusinessType.TAXI_GENERAL, + ), + BusinessData( + id=7, + transport_type=TransportType.TRV, + business_type=BusinessType.TAXI_REGULATED, + ), + BusinessData( + id=8, + transport_type=TransportType.TRV, + business_type=BusinessType.VTC, + ), + BusinessData( + id=9, + transport_type=TransportType.TRV, + business_type=BusinessType.LOTI, + ), ] diff --git a/app/tests/regulations/__init__.py b/app/tests/regulations/__init__.py index 5317d460..2c70e05d 100644 --- a/app/tests/regulations/__init__.py +++ b/app/tests/regulations/__init__.py @@ -101,16 +101,18 @@ def _log_and_validate_mission( ) return mission - def convert_employee_to_trv(self): - trv_business = Business.query.filter( - Business.business_type == BusinessType.FREQUENT.value + def _convert_employee_to_business(self, business_type): + business = Business.query.filter( + Business.business_type == business_type.value ).one_or_none() - self.employee.employments[0].business = trv_business + self.employee.employments[0].business = business db.session.commit() + def convert_employee_to_vtc(self): + self._convert_employee_to_business(BusinessType.VTC) + + def convert_employee_to_trv(self): + self._convert_employee_to_business(BusinessType.FREQUENT) + def convert_employee_to_trm_short_distance(self): - trm_short_distance_business = Business.query.filter( - Business.business_type == BusinessType.SHORT_DISTANCE.value - ).one_or_none() - self.employee.employments[0].business = trm_short_distance_business - db.session.commit() + self._convert_employee_to_business(BusinessType.SHORT_DISTANCE) diff --git a/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py new file mode 100644 index 00000000..abc319f2 --- /dev/null +++ b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py @@ -0,0 +1,40 @@ +"""update_trv_descriptions_max_work_time_based_on_amplitude + +Revision ID: 373e565a327a +Revises: 7e8f71c49544 +Create Date: 2025-02-06 09:41:41.254918 + +""" +import json + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.orm import Session + +from app.services.get_regulation_checks import get_regulation_checks + + +# revision identifiers, used by Alembic. +revision = "373e565a327a" +down_revision = "7e8f71c49544" +branch_labels = None +depends_on = None + + +def upgrade(): + session = Session(bind=op.get_bind()) + regulation_check_data = get_regulation_checks() + for r in regulation_check_data: + session.execute( + sa.text( + "UPDATE regulation_check SET variables = :variables WHERE type = :type;" + ), + dict( + variables=json.dumps(r.variables), + type=r.type, + ), + ) + + +def downgrade(): + pass From 7d01b2a2ed13504eeb4a2757f1348bd7879f6e14 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Fri, 7 Feb 2025 11:11:09 +0100 Subject: [PATCH 6/9] refacto(migrations,regulations): refacto update regulation check variables --- app/services/get_regulation_checks.py | 17 +++++++++++++++++ ...650780_regulation_check_description_in_.py | 17 ++++------------- ...pdate_regulation_check_variables_based_.py | 19 ++++--------------- ...7a_trv_max_work_time_based_on_amplitude.py | 18 ++++-------------- 4 files changed, 29 insertions(+), 42 deletions(-) diff --git a/app/services/get_regulation_checks.py b/app/services/get_regulation_checks.py index 39bb8762..768fc9e8 100644 --- a/app/services/get_regulation_checks.py +++ b/app/services/get_regulation_checks.py @@ -1,3 +1,6 @@ +import json + +import sqlalchemy as sa from dataclasses import dataclass from datetime import date, datetime from typing import Optional @@ -166,3 +169,17 @@ def get_regulation_checks(): unit=UnitType.DAY, ), ] + + +def update_regulation_check_variables(session): + regulation_check_data = get_regulation_checks() + for r in regulation_check_data: + session.execute( + sa.text( + "UPDATE regulation_check SET variables = :variables WHERE type = :type;" + ), + dict( + variables=json.dumps(r.variables), + type=r.type, + ), + ) diff --git a/migrations/versions/061ed7650780_regulation_check_description_in_.py b/migrations/versions/061ed7650780_regulation_check_description_in_.py index 8fe72a58..ada5d927 100644 --- a/migrations/versions/061ed7650780_regulation_check_description_in_.py +++ b/migrations/versions/061ed7650780_regulation_check_description_in_.py @@ -5,13 +5,14 @@ Create Date: 2024-07-16 15:23:52.773817 """ -import json from alembic import op import sqlalchemy as sa from sqlalchemy.orm import Session -from app.services.get_regulation_checks import get_regulation_checks +from app.services.get_regulation_checks import ( + update_regulation_check_variables, +) # revision identifiers, used by Alembic. revision = "061ed7650780" @@ -22,17 +23,7 @@ def upgrade(): session = Session(bind=op.get_bind()) - regulation_check_data = get_regulation_checks() - for r in regulation_check_data: - session.execute( - sa.text( - "UPDATE regulation_check SET variables = :variables WHERE type = :type;" - ), - dict( - variables=json.dumps(r.variables), - type=r.type, - ), - ) + update_regulation_check_variables(session) op.drop_column("regulation_check", "description") diff --git a/migrations/versions/209c1d0a5cf9_update_regulation_check_variables_based_.py b/migrations/versions/209c1d0a5cf9_update_regulation_check_variables_based_.py index 86121dc0..79c9abc4 100644 --- a/migrations/versions/209c1d0a5cf9_update_regulation_check_variables_based_.py +++ b/migrations/versions/209c1d0a5cf9_update_regulation_check_variables_based_.py @@ -5,13 +5,12 @@ Create Date: 2024-07-09 11:25:29.813283 """ -import json - from alembic import op -import sqlalchemy as sa from sqlalchemy.orm import Session -from app.services.get_regulation_checks import get_regulation_checks +from app.services.get_regulation_checks import ( + update_regulation_check_variables, +) # revision identifiers, used by Alembic. revision = "209c1d0a5cf9" @@ -22,17 +21,7 @@ def upgrade(): session = Session(bind=op.get_bind()) - regulation_check_data = get_regulation_checks() - for r in regulation_check_data: - session.execute( - sa.text( - "UPDATE regulation_check SET variables = :variables WHERE type = :type;" - ), - dict( - variables=json.dumps(r.variables), - type=r.type, - ), - ) + update_regulation_check_variables(session) def downgrade(): diff --git a/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py index abc319f2..5add380a 100644 --- a/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py +++ b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py @@ -8,11 +8,11 @@ import json from alembic import op -import sqlalchemy as sa from sqlalchemy.orm import Session -from app.services.get_regulation_checks import get_regulation_checks - +from app.services.get_regulation_checks import ( + update_regulation_check_variables, +) # revision identifiers, used by Alembic. revision = "373e565a327a" @@ -23,17 +23,7 @@ def upgrade(): session = Session(bind=op.get_bind()) - regulation_check_data = get_regulation_checks() - for r in regulation_check_data: - session.execute( - sa.text( - "UPDATE regulation_check SET variables = :variables WHERE type = :type;" - ), - dict( - variables=json.dumps(r.variables), - type=r.type, - ), - ) + update_regulation_check_variables(session) def downgrade(): From 3b193745fc4ca286614fecee071aa2eddb5b6ce0 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Fri, 7 Feb 2025 11:11:44 +0100 Subject: [PATCH 7/9] feat(regulations): update description no lic for TRV + migration --- app/services/get_regulation_checks.py | 9 +++++- ...fc43b10_update_description_natinf_25666.py | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/44bebfc43b10_update_description_natinf_25666.py diff --git a/app/services/get_regulation_checks.py b/app/services/get_regulation_checks.py index 768fc9e8..d437702b 100644 --- a/app/services/get_regulation_checks.py +++ b/app/services/get_regulation_checks.py @@ -164,7 +164,14 @@ def get_regulation_checks(): label="Absence de livret individuel de contrôle à bord", regulation_rule=None, variables=dict( - DESCRIPTION="Défaut de documents nécessaires au décompte de la durée du travail (L. 3121-67 du Code du travail et R. 3312-58 du Code des transports + arrêté du 20 juillet 1998)." + DESCRIPTION={ + str( + TransportType.TRM.name + ): "Défaut de documents nécessaires au décompte de la durée du travail (L. 3121-67 du Code du travail et R. 3312-58 du Code des transports + arrêté du 20 juillet 1998).", + str( + TransportType.TRV.name + ): "Défaut de documents nécessaires au décompte de la durée du travail (L. 3121-67 du Code du travail et R. 3312-19 du Code des transports + arrêté du 20 juillet 1998).", + } ), unit=UnitType.DAY, ), diff --git a/migrations/versions/44bebfc43b10_update_description_natinf_25666.py b/migrations/versions/44bebfc43b10_update_description_natinf_25666.py new file mode 100644 index 00000000..a85a3395 --- /dev/null +++ b/migrations/versions/44bebfc43b10_update_description_natinf_25666.py @@ -0,0 +1,28 @@ +"""update description natinf 25666 + +Revision ID: 44bebfc43b10 +Revises: 373e565a327a +Create Date: 2025-02-07 10:39:30.719398 + +""" +from alembic import op +from sqlalchemy.orm import Session + +from app.services.get_regulation_checks import ( + update_regulation_check_variables, +) + +# revision identifiers, used by Alembic. +revision = "44bebfc43b10" +down_revision = "373e565a327a" +branch_labels = None +depends_on = None + + +def upgrade(): + session = Session(bind=op.get_bind()) + update_regulation_check_variables(session) + + +def downgrade(): + pass From 8ac0b74c1ced40681bdcf2c8fa46e3f504618aed Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Mon, 10 Feb 2025 11:23:27 +0100 Subject: [PATCH 8/9] fix(sonar): sonar issues --- app/domain/regulations_helper.py | 2 +- .../373e565a327a_trv_max_work_time_based_on_amplitude.py | 1 + .../versions/44bebfc43b10_update_description_natinf_25666.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/domain/regulations_helper.py b/app/domain/regulations_helper.py index b5a274cd..c7cb6d4b 100644 --- a/app/domain/regulations_helper.py +++ b/app/domain/regulations_helper.py @@ -18,7 +18,7 @@ def resolve_variables(dict_var, business): continue res_dict[key] = val3 break - if not (key in res_dict) and default_value: + if key not in res_dict and default_value: res_dict[key] = default_value else: res_dict[key] = val2 diff --git a/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py index 5add380a..0921d238 100644 --- a/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py +++ b/migrations/versions/373e565a327a_trv_max_work_time_based_on_amplitude.py @@ -27,4 +27,5 @@ def upgrade(): def downgrade(): + # we don't maintain a history of regulation checks pass diff --git a/migrations/versions/44bebfc43b10_update_description_natinf_25666.py b/migrations/versions/44bebfc43b10_update_description_natinf_25666.py index a85a3395..1bfa640e 100644 --- a/migrations/versions/44bebfc43b10_update_description_natinf_25666.py +++ b/migrations/versions/44bebfc43b10_update_description_natinf_25666.py @@ -25,4 +25,5 @@ def upgrade(): def downgrade(): + # we don't maintain a history of regulation checks pass From 55cc6de43326a96ea129d56d0f47ee1ce850fa53 Mon Sep 17 00:00:00 2001 From: Tristan Gueguen Date: Mon, 10 Feb 2025 11:28:33 +0100 Subject: [PATCH 9/9] fix(emails): replace assistance@mobilic... -> contact@... --- app/templates/cgu_employee_rejected.html | 2 +- app/templates/cgu_suspended_company.html | 2 +- app/templates/companies_about_to_lose_certificate.html | 2 +- app/templates/transactional_base.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/templates/cgu_employee_rejected.html b/app/templates/cgu_employee_rejected.html index 803133c1..dcfd1975 100644 --- a/app/templates/cgu_employee_rejected.html +++ b/app/templates/cgu_employee_rejected.html @@ -9,6 +9,6 @@

Nous vous informons que votre salarié {{employee_full_name }} (identifiant Mobilic : {{employee_id }}) n’a pas accepté nos nouvelles conditions générales d’utilisation adressées le {{release_date | full_format_day}}.

En cas d'erreur, votre salarié peut modifier son choix pendant 10 jours. Pour cela, il doit se connecter sur Mobilic et accepter les CGU.

S’il ne le fait pas, son compte restera bloqué et sera supprimé. Il ne pourra plus saisir de temps de travail via Mobilic pour votre entreprise. Pour être en règle en cas de contrôle, il doit, dès maintenant, utiliser le livret individuel de contrôle (articles R3312-19 et R3312-58 du Code des transports).

-

Si la période de 10 jours est déjà passée, votre salarié peut nous contacter à l’adresse suivante : assistance@mobilic.beta.gouv.fr. Nous pourrons ainsi réactiver son compte.

+

Si la période de 10 jours est déjà passée, votre salarié peut nous contacter à l’adresse suivante : contact@mobilic.beta.gouv.fr. Nous pourrons ainsi réactiver son compte.

Cordialement,

{% endblock %} diff --git a/app/templates/cgu_suspended_company.html b/app/templates/cgu_suspended_company.html index ecee9769..946633fe 100644 --- a/app/templates/cgu_suspended_company.html +++ b/app/templates/cgu_suspended_company.html @@ -9,6 +9,6 @@

Nous vous avons adressé la mise à jour de nos conditions générales d’utilisation en date du {{release_date | full_format_day}}. En l’absence d’acceptation de ces conditions générales d’utilisation dans le délai de 10 jours ouvrés, nous avons été dans l’obligation de suspendre votre compte.

Nous souhaiterions indiquer que vos salariés ont accepté les conditions mais ne peuvent continuer à utiliser l’application Mobilic en l’absence de gestionnaire désigné sur votre entreprise.

L'équipe Mobilic tient à vous rappeler que, conformément aux articles R3312-19 et R3312-58 du Code des transports, le suivi du temps de travail de vos salariés doit s’effectuer soit par le livret individuel de contrôle au format papier, soit au format numérique par Mobilic.

-

Si vous souhaitez conserver le format numérique assurant une fiabilité et la facilité de saisie pour vos salariés, nous vous invitons à écrire à l’adresse assistance@mobilic.beta.gouv.fr.

+

Si vous souhaitez conserver le format numérique assurant une fiabilité et la facilité de saisie pour vos salariés, nous vous invitons à écrire à l’adresse contact@mobilic.beta.gouv.fr.

Au plaisir de vous retrouver !

{% endblock %} diff --git a/app/templates/companies_about_to_lose_certificate.html b/app/templates/companies_about_to_lose_certificate.html index 1f52a692..4be9a05b 100644 --- a/app/templates/companies_about_to_lose_certificate.html +++ b/app/templates/companies_about_to_lose_certificate.html @@ -8,6 +8,6 @@

Cependant, nous avons pu constater que, depuis cette date, vous n’aviez pas respecté certains critères indispensables à son obtention. Vous trouverez la liste de ces critères dans l'onglet "Certificat" de votre interface Mobilic.

Ainsi, pour que nous puissions renouveler votre certificat à la fin de sa période de validité, veillez à y remédier dans les trois mois à venir.

Vous trouverez sur ce lien le détail des critères à respecter : Comment obtenir le certificat Mobilic ?

-

N’hésitez pas à nous écrire pour toute question à ce sujet sur : assistance@mobilic.beta.gouv.fr.

+

N’hésitez pas à nous écrire pour toute question à ce sujet sur : contact@mobilic.beta.gouv.fr.

A bientôt sur Mobilic !

{% endblock %} diff --git a/app/templates/transactional_base.html b/app/templates/transactional_base.html index 69e23ee8..6af0cdc1 100644 --- a/app/templates/transactional_base.html +++ b/app/templates/transactional_base.html @@ -398,7 +398,7 @@ Mobilic est un service numérique de l'Etat incubé à la Fabrique numérique du ministère de la Transition écologique, membre du réseau d’incubateurs beta.gouv. Pour contacter l’équipe, veuillez écrire à - assistance@mobilic.beta.gouv.fr.
+ contact@mobilic.beta.gouv.fr.
Accéder au site