Skip to content

Commit

Permalink
feat(Diagnostique): nouveau champ service_type pour stocker le type d…
Browse files Browse the repository at this point in the history
…e service proposé par la cantine (#4720)
  • Loading branch information
raphodn authored Dec 11, 2024
1 parent bdb9fad commit 0e57f40
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/serializers/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"other_waste_comments",
"has_diversification_plan",
"diversification_plan_actions",
"service_type",
"vegetarian_weekly_recurrence",
"vegetarian_menu_type",
"vegetarian_menu_bases",
Expand Down
2 changes: 2 additions & 0 deletions api/tests/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_create_full_diagnostic(self):
"other_waste_comments": "We do our best",
"has_diversification_plan": True,
"diversification_plan_actions": ["PRODUCTS", "TRAINING"],
"service_type": "MULTIPLE_SELF",
"vegetarian_weekly_recurrence": "DAILY",
"vegetarian_menu_type": "UNIQUE",
"vegetarian_menu_bases": ["GRAIN", "READYMADE", "CHEESE"],
Expand Down Expand Up @@ -245,6 +246,7 @@ def test_create_full_diagnostic(self):
self.assertIn("AWARENESS", diagnostic.waste_actions)
self.assertEqual(diagnostic.duration_leftovers_measurement, 30)
self.assertIn("TRAINING", diagnostic.diversification_plan_actions)
self.assertEqual("MULTIPLE_SELF", diagnostic.service_type)
self.assertEqual("DAILY", diagnostic.vegetarian_weekly_recurrence)
self.assertIn("GRAIN", diagnostic.vegetarian_menu_bases)
self.assertIn("CHEESE", diagnostic.vegetarian_menu_bases)
Expand Down
1 change: 1 addition & 0 deletions data/admin/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class DiagnosticAdmin(SimpleHistoryAdmin):
"tunnel_diversification",
"has_diversification_plan",
"diversification_plan_actions",
"service_type",
"vegetarian_weekly_recurrence",
"vegetarian_menu_type",
"vegetarian_menu_bases",
Expand Down
64 changes: 64 additions & 0 deletions data/migrations/0160_diagnostic_service_type_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 5.0.7 on 2024-12-04 12:01

from django.db import migrations, models


def init_service_type(apps, schema_editor):
Diagnostic = apps.get_model("data", "Diagnostic")
for diagnostic in Diagnostic.objects.all():
if diagnostic.vegetarian_menu_type:
if diagnostic.vegetarian_menu_type == "UNIQUE":
diagnostic.service_type = "UNIQUE"
elif diagnostic.vegetarian_menu_type in ["SEVERAL", "ALTERNATIVES"]:
diagnostic.service_type = "MULTIPLE_SELF"
diagnostic.save(update_fields=["service_type"])

def reverse_init_service_type(apps, schema_editor):
pass


class Migration(migrations.Migration):

dependencies = [
("data", "0159_alter_canteen_line_ministry_and_more"),
]

operations = [
migrations.AddField(
model_name="diagnostic",
name="service_type",
field=models.CharField(
blank=True,
choices=[
("UNIQUE", "Menu unique"),
("MULTIPLE_SELF", "Choix multiple en libre-service"),
(
"MULTIPLE_RESERVATION",
"Choix multiple avec réservation à l’avance au jour le jour",
),
],
max_length=255,
null=True,
verbose_name="type de service",
),
),
migrations.AddField(
model_name="historicaldiagnostic",
name="service_type",
field=models.CharField(
blank=True,
choices=[
("UNIQUE", "Menu unique"),
("MULTIPLE_SELF", "Choix multiple en libre-service"),
(
"MULTIPLE_RESERVATION",
"Choix multiple avec réservation à l’avance au jour le jour",
),
],
max_length=255,
null=True,
verbose_name="type de service",
),
),
migrations.RunPython(init_service_type, reverse_init_service_type),
]
12 changes: 12 additions & 0 deletions data/models/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class DiagnosticType(models.TextChoices):
class CreationSource(models.TextChoices):
TUNNEL = "TUNNEL", "Tunnel"

class ServiceType(models.TextChoices):
UNIQUE = "UNIQUE", "Menu unique"
MULTIPLE_SELF = "MULTIPLE_SELF", "Choix multiple en libre-service"
MULTIPLE_RESERVATION = "MULTIPLE_RESERVATION", "Choix multiple avec réservation à l’avance au jour le jour"

class VegetarianMenuFrequency(models.TextChoices):
NEVER = "NEVER", "Jamais"
LOW = "LOW", "Moins d'une fois par semaine"
Expand Down Expand Up @@ -433,6 +438,13 @@ class PublicationStatus(models.TextChoices):
size=None,
verbose_name="actions inclus dans le plan de diversification des protéines",
)
service_type = models.CharField(
max_length=255,
choices=ServiceType.choices,
null=True,
blank=True,
verbose_name="type de service",
)
vegetarian_weekly_recurrence = models.CharField(
max_length=255,
choices=VegetarianMenuFrequency.choices,
Expand Down
3 changes: 2 additions & 1 deletion data/models/teledeclaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def create_from_diagnostic(diagnostic, applicant, status=None):
"""
from data.factories import TeledeclarationFactory # Avoids circular import

version = "11" # Helps identify which data will be present. Use incremental int values
version = "12" # Helps identify which data will be present. Use incremental int values
# Version 12 - New Diagnostic service_type field (and stop filling vegetarian_menu_type)
# Version 11 - Requires diagnostic mode to be defined for central production types (in validate_diagnostic)
# Version 10 - Add department and region fields
# Version 9 - removes legacy fields: value_pat_ht, value_label_hve, value_label_rouge, value_label_aoc_igp and value_pat_ht
Expand Down

0 comments on commit 0e57f40

Please sign in to comment.