Skip to content

Commit

Permalink
Merge branch 'staging' into 1277-saisine-ansees-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alemangui committed Dec 17, 2024
2 parents 224a41a + 9d7aae2 commit 47b2fe6
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 22 deletions.
4 changes: 3 additions & 1 deletion clevercloud/run_succeeded_hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ 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
mkdir csv-data/$DATE/
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
2 changes: 1 addition & 1 deletion data/admin/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion data/admin/microorganism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion data/admin/plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
24 changes: 22 additions & 2 deletions data/admin/substance.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -104,6 +114,7 @@ def get_ingredients(self, obj):
},
),
]
inlines = (SubstanceSynonymInline,)
readonly_fields = [
"siccrf_name",
"siccrf_name_en",
Expand All @@ -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"]
3 changes: 1 addition & 2 deletions data/etl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions data/tests/test_csv_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
</p>
</div>

<ElementStatusBadge
:text="model.element.status"
v-if="showElementAuthorization && model.element?.status === 'non autorisé'"
class="self-center ml-2"
/>

<DsfrBadge v-if="novelFood" label="Novel Food" type="new" class="self-center ml-2" small />
<DsfrBadge v-if="model.new" label="Nouvel ingrédient" type="info" class="self-center ml-2" small />
<DsfrBadge v-if="!model.active" label="Non-actif" type="none" class="self-center ml-2" small />
Expand Down Expand Up @@ -38,13 +44,14 @@ import { getElementName } from "@/utils/elements"
import { useRootStore } from "@/stores/root"
import { storeToRefs } from "pinia"
import ElementCommentModal from "@/components/ElementCommentModal"
import ElementStatusBadge from "@/components/ElementStatusBadge"
const { plantParts, units, preparations, loggedUser } = storeToRefs(useRootStore())
const isInstructor = computed(() => loggedUser.value?.globalRoles.some((x) => x.name === "InstructionRole"))
const model = defineModel()
const props = defineProps({ objectType: { type: String } })
const props = defineProps({ objectType: { type: String }, showElementAuthorization: { type: Boolean } })
const plantPartName = computed(() => plantParts.value?.find((x) => x.id === model.value.usedPart)?.name || "Aucune")
const unitName = computed(() => units.value?.find((x) => x.id === model.value.unit)?.name || "")
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/components/DeclarationSummary/SummaryElementList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
<template v-slot:title>
<SummaryElementListTitle :objectType="objectType" :elementCount="`${elements.length}`" />
</template>
<SummaryElementListItems :objectType="objectType" :elements="elements" />
<SummaryElementListItems
:showElementAuthorization="showElementAuthorization"
:objectType="objectType"
:elements="elements"
/>
</DsfrAccordion>

<!-- Affichage sans les accordéons, tous les ingrédients sont affichés -->
<div v-else>
<SummaryElementListTitle class="mt-6 mb-3" :objectType="objectType" />
<SummaryElementListItems :objectType="objectType" :elements="elements" />
<SummaryElementListItems
:showElementAuthorization="showElementAuthorization"
:objectType="objectType"
:elements="elements"
/>
</div>
</div>
</template>
Expand All @@ -20,5 +28,10 @@
import SummaryElementListTitle from "./SummaryElementListTitle"
import SummaryElementListItems from "./SummaryElementListItems"
defineProps({ objectType: { type: String }, elements: { type: Array }, useAccordions: { type: Boolean } })
defineProps({
objectType: { type: String },
elements: { type: Array },
useAccordions: { type: Boolean },
showElementAuthorization: { type: Boolean },
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
:key="`summary-${objectType}-${index}`"
v-model="elements[index]"
:objectType="objectType"
:showElementAuthorization="showElementAuthorization"
/>
</ul>
</template>

<script setup>
import SummaryElementItem from "./SummaryElementItem"
defineProps({ objectType: { type: String }, elements: { type: Array } })
defineProps({ objectType: { type: String }, elements: { type: Array }, showElementAuthorization: { type: Boolean } })
</script>
22 changes: 19 additions & 3 deletions frontend/src/components/DeclarationSummary/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,54 @@
<SummaryModificationButton class="ml-4" v-if="!readonly" @click="router.push(editLink(1))" />
</h3>

<SummaryElementList :useAccordions="useAccordions" objectType="plant" :elements="payload.declaredPlants" />
<SummaryElementList
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
objectType="plant"
:elements="payload.declaredPlants"
/>
<SummaryElementList
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
objectType="microorganism"
:elements="payload.declaredMicroorganisms"
/>
<SummaryElementList
objectType="form_of_supply"
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
:elements="getObjectSubTypeList(payload.declaredIngredients, 'form_of_supply')"
/>
<SummaryElementList
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
objectType="aroma"
:elements="getObjectSubTypeList(payload.declaredIngredients, 'aroma')"
/>
<SummaryElementList
objectType="additive"
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
:elements="getObjectSubTypeList(payload.declaredIngredients, 'additive')"
/>
<SummaryElementList
objectType="active_ingredient"
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
:elements="getObjectSubTypeList(payload.declaredIngredients, 'active_ingredient')"
/>
<SummaryElementList
objectType="non_active_ingredient"
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
:elements="getObjectSubTypeList(payload.declaredIngredients, 'non_active_ingredient')"
/>
<SummaryElementList objectType="substance" :useAccordions="useAccordions" :elements="payload.declaredSubstances" />
<SummaryElementList
objectType="substance"
:useAccordions="useAccordions"
:showElementAuthorization="showElementAuthorization"
:elements="payload.declaredSubstances"
/>

<p class="font-bold mt-8">Substances contenues dans la composition :</p>
<SubstancesTable v-model="payload" readonly />
Expand Down Expand Up @@ -107,7 +123,7 @@ const router = useRouter()
const { units, populations, conditions, effects, galenicFormulations } = storeToRefs(useRootStore())
const payload = defineModel()
defineProps({ readonly: Boolean, showArticle: Boolean, useAccordions: Boolean })
defineProps({ readonly: Boolean, showArticle: Boolean, useAccordions: Boolean, showElementAuthorization: Boolean })
const unitInfo = computed(() => {
if (!payload.value.unitQuantity) return null
const unitMeasurement = units.value?.find?.((x) => x.id === payload.value.unitMeasurement)?.name || "-"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ElementStatusBadge.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<DsfrBadge v-if="text === 'autorisé'" :label="text" small type="success" />
<DsfrBadge v-if="text === 'non autorisé'" :label="text" small type="error" />
<DsfrBadge v-else-if="text === 'non autorisé'" :label="text" small type="error" />
</template>

<script setup>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SubstancesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
'!text-red-marianne-425 font-bold':
(payload.computedSubstances[rowIndex].substance.maxQuantity ||
payload.computedSubstances[rowIndex].substance.maxQuantity === 0) &&
payload.computedSubstances[rowIndex].quantity >=
payload.computedSubstances[rowIndex].quantity >
payload.computedSubstances[rowIndex].substance.maxQuantity,
}"
v-if="props.readonly"
Expand All @@ -55,7 +55,7 @@
v-if="
(payload.computedSubstances[rowIndex].substance.maxQuantity ||
payload.computedSubstances[rowIndex].substance.maxQuantity === 0) &&
payload.computedSubstances[rowIndex].quantity >=
payload.computedSubstances[rowIndex].quantity >
payload.computedSubstances[rowIndex].substance.maxQuantity
"
>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/InstructionPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<DeclarationSummary
:showArticle="true"
:useAccordions="true"
:showElementAuthorization="true"
:readonly="true"
v-model="declaration"
v-if="isAwaitingInstruction"
Expand All @@ -48,6 +49,7 @@
:externalResults="$externalResults"
:readonly="true"
:useAccordions="true"
:showElementAuthorization="true"
:declarationId="declaration?.id"
:user="declarant"
:company="company"
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/views/ProducerFormPage/AttachmentTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<DsfrInputGroup>
<DsfrFileUpload
:label="otherAttachmentsLabel"
:acceptTypes="['image/jpeg, image/gif, image/png, application/pdf']"
:acceptTypes="acceptedTypes"
hint="Taille maximale du fichier : 2 Mo"
@change="addOtherFiles"
v-model="selectedOtherFile"
Expand All @@ -37,6 +37,7 @@ import { ref, computed } from "vue"
import FileGrid from "./FileGrid"
import SectionTitle from "@/components/SectionTitle"
const acceptedTypes = ["image/jpeg", "image/gif", "image/png", "application/pdf"]
const props = defineProps(["externalResults"])
const payload = defineModel()
Expand Down Expand Up @@ -77,6 +78,13 @@ const addFiles = async (files, container, resetModel, defaultData) => {
window.alert(`Le fichier ${files[i].name} dépasse la taille limite de 2 Mo`)
continue
}
const formatIsValid = acceptedTypes.indexOf(files[i].type) > -1
if (!formatIsValid) {
window.alert(
`Le format du fichier ${files[i].name} n'est pas supporté. Merci de joindre un fichier en JPG, GIF, PNG ou PDF.`
)
continue
}
const base64 = await toBase64(files[i])
container.push({
...{
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/VisaPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<DeclarationSummary
:showArticle="true"
:useAccordions="true"
:showElementAuthorization="true"
:readonly="true"
v-model="declaration"
v-if="isAwaitingVisa"
Expand All @@ -46,6 +47,7 @@
:readonly="true"
:declarationId="declaration?.id"
:useAccordions="true"
:showElementAuthorization="true"
:user="declarant"
:company="company"
@decision-done="onDecisionDone"
Expand Down

0 comments on commit 47b2fe6

Please sign in to comment.