diff --git a/clevercloud/run_succeeded_hook.sh b/clevercloud/run_succeeded_hook.sh index 538b78ea4..0a1c51e73 100755 --- a/clevercloud/run_succeeded_hook.sh +++ b/clevercloud/run_succeeded_hook.sh @@ -6,7 +6,8 @@ DATE=${FILEPATH##"s3://csv-data/"} DATE=${DATE%"/"} mkdir csv-data # if this date doesn't exist yet -if ls csv-data/$DATE ; then +LAST_DATE=$(psql postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME -t -1 -c "select * from data_last_import order by import_date desc limit 1;") +if [[ "$LAST_DATE" == *"$DATE"* ]] ; then echo "This data has already been loaded" else # retrieve most recent files @@ -14,4 +15,5 @@ else s3cmd get s3://csv-data/$DATE/ --recursive csv-data/$DATE/ # import those files to database (django models) python ~/$APP_ID/manage.py load_ingredients -d csv-data/$DATE $DATE + psql postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME -c "insert into data_last_import (import_date) values ('$DATE');" fi diff --git a/data/admin/ingredient.py b/data/admin/ingredient.py index 0601bb1cc..178d86fe6 100644 --- a/data/admin/ingredient.py +++ b/data/admin/ingredient.py @@ -38,7 +38,7 @@ class IngredientAdmin(ElementAdminWithChangeReason): SubstanceInlineAdmin, IngredientSynonymInline, ) - list_display = ("name", "status", "is_risky", "novel_food") + list_display = ("name", "is_obsolete", "status", "is_risky", "novel_food") list_filter = ("is_obsolete", "status", "is_risky", "novel_food") show_facets = admin.ShowFacets.NEVER readonly_fields = ( diff --git a/data/admin/microorganism.py b/data/admin/microorganism.py index af37b1456..200592025 100644 --- a/data/admin/microorganism.py +++ b/data/admin/microorganism.py @@ -57,7 +57,7 @@ class MicroorganismAdmin(ElementAdminWithChangeReason): ), ] - list_display = ("name", "status", "is_risky", "novel_food") + list_display = ("name", "is_obsolete", "status", "is_risky", "novel_food") list_filter = ("is_obsolete", "status", "is_risky", "novel_food") show_facets = admin.ShowFacets.NEVER readonly_fields = ( diff --git a/data/admin/plant.py b/data/admin/plant.py index 849506bcc..dc7d44b04 100644 --- a/data/admin/plant.py +++ b/data/admin/plant.py @@ -80,7 +80,7 @@ class PlantAdmin(ElementAdminWithChangeReason): SubstanceInlineAdmin, PlantSynonymInline, ) - list_display = ("name", "family", "status", "is_risky", "novel_food") + list_display = ("name", "is_obsolete", "family", "status", "is_risky", "novel_food") list_filter = ("is_obsolete", "family", "status", "is_risky", "novel_food") show_facets = admin.ShowFacets.NEVER readonly_fields = ( diff --git a/data/admin/substance.py b/data/admin/substance.py index d915be728..bfc0a2d44 100644 --- a/data/admin/substance.py +++ b/data/admin/substance.py @@ -1,9 +1,10 @@ from django import forms from django.contrib import admin +from django.db import models from django.urls import reverse from django.utils.html import format_html -from data.models import Substance +from data.models import Substance, SubstanceSynonym from .abstract_admin import ElementAdminWithChangeReason @@ -19,6 +20,15 @@ class Meta: } +class SubstanceSynonymInline(admin.TabularInline): + model = SubstanceSynonym + extra = 1 + + formfield_overrides = { + models.TextField: {"widget": forms.Textarea(attrs={"cols": 60, "rows": 1})}, + } + + @admin.register(Substance) class SubstanceAdmin(ElementAdminWithChangeReason): @classmethod @@ -104,6 +114,7 @@ def get_ingredients(self, obj): }, ), ] + inlines = (SubstanceSynonymInline,) readonly_fields = [ "siccrf_name", "siccrf_name_en", @@ -121,7 +132,16 @@ def get_ingredients(self, obj): "get_microorganisms", "get_ingredients", ] - list_display = ("name", "get_plants", "get_microorganisms", "get_ingredients", "status", "is_risky", "novel_food") + list_display = ( + "name", + "is_obsolete", + "get_plants", + "get_microorganisms", + "get_ingredients", + "status", + "is_risky", + "novel_food", + ) list_filter = ("is_obsolete", "status", "is_risky", "novel_food") show_facets = admin.ShowFacets.NEVER search_fields = ["id", "name"] diff --git a/data/etl/utils.py b/data/etl/utils.py index 8424c23cd..85c7f5cf2 100644 --- a/data/etl/utils.py +++ b/data/etl/utils.py @@ -23,8 +23,7 @@ def pre_import_treatments(field, value): new_fields = {"siccrf_max_quantity": clean_value(value, field), "ca_must_specify_quantity": True} elif field.name == "siccrf_status": new_fields = { - "siccrf_status": clean_value(value, field), - "ca_status": convert_status(clean_value(value, field)), + "siccrf_status": convert_status(clean_value(value, field)), } # si le status SICCRF correspond à "à inscrire" if int(value) == 3: diff --git a/data/tests/test_csv_importer.py b/data/tests/test_csv_importer.py index 6da021d91..14e2c7a09 100644 --- a/data/tests/test_csv_importer.py +++ b/data/tests/test_csv_importer.py @@ -216,11 +216,13 @@ def test_status_import(self): self.assertEqual(len(Plant.objects.filter(siccrf_status=1)), 2) self.assertEqual(len(Microorganism.objects.filter(status=IngredientStatus.AUTHORIZED)), 2) - self.assertEqual(len(Microorganism.objects.filter(siccrf_status=3)), 2) + self.assertEqual(len(Microorganism.objects.filter(siccrf_status=3)), 0) # ce status est converti + self.assertEqual(len(Microorganism.objects.filter(siccrf_status=1)), 2) self.assertEqual(len(Microorganism.objects.filter(to_be_entered_in_next_decree=True)), 2) self.assertEqual(len(Ingredient.objects.filter(status=IngredientStatus.NO_STATUS)), 2) - self.assertEqual(len(Ingredient.objects.filter(siccrf_status=4)), 2) + self.assertEqual(len(Ingredient.objects.filter(siccrf_status=4)), 0) # ce status est converti + self.assertEqual(len(Ingredient.objects.filter(siccrf_status=3)), 2) self.assertEqual(len(Ingredient.objects.filter(status=IngredientStatus.AUTHORIZED)), 0) self.assertEqual(len(Substance.objects.filter(status=IngredientStatus.NOT_AUTHORIZED)), 2) diff --git a/frontend/src/components/DeclarationSummary/SummaryElementItem.vue b/frontend/src/components/DeclarationSummary/SummaryElementItem.vue index 3ca9b99ca..71829c45f 100644 --- a/frontend/src/components/DeclarationSummary/SummaryElementItem.vue +++ b/frontend/src/components/DeclarationSummary/SummaryElementItem.vue @@ -10,6 +10,12 @@
+Substances contenues dans la composition :