Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permet le téléchargement de l'attestation des déclarations en abandon #1393

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions frontend/src/components/DeclarationAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script setup>
import { computed } from "vue"
import { isoToPrettyDate } from "@/utils/date"
const props = defineProps({ declaration: Object, role: { type: String, default: "declarant" } })
const props = defineProps({ declaration: Object, role: { type: String, default: "declarant" }, snapshots: Array })

const displayData = computed(() => {
switch (props.role) {
Expand All @@ -32,6 +32,12 @@ const displayData = computed(() => {
}
})

const canDownloadAbandonedCertificate = computed(() => {
if (!props.snapshots) return false
const latestSnapshot = [...props.snapshots].sort((a, b) => b.creationDate.localeCompare(a.creationDate))?.[0]
return latestSnapshot?.status === "OBJECTION"
})

const declarantDisplayData = computed(() => {
switch (props.declaration.status) {
case "DRAFT":
Expand Down Expand Up @@ -84,7 +90,12 @@ const declarantDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Attestation de déclaration", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: false }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -140,7 +151,12 @@ const instructorDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Cette déclaration a été autorisée", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: false }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -196,7 +212,12 @@ const visorDisplayData = computed(() => {
case "AUTHORIZED":
return { type: "success", title: "Cette déclaration a été autorisée", body: null, canDownloadCertificate: true }
case "ABANDONED":
return { type: "warning", title: "Ce dossier est abandonné", body: null, canDownloadCertificate: false }
return {
type: "warning",
title: "Ce dossier est abandonné",
body: null,
canDownloadCertificate: canDownloadAbandonedCertificate.value,
}
case "REJECTED":
return {
type: "warning",
Expand Down
24 changes: 5 additions & 19 deletions frontend/src/components/HistoryTab.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<div v-if="isFetching" class="flex justify-center items-center min-h-60">
<div v-if="!snapshots" class="flex justify-center items-center min-h-60">
<ProgressSpinner />
</div>
<div v-if="snapshots && snapshots.length" class="flex flex-col gap-6">
Expand All @@ -19,20 +19,11 @@
</template>

<script setup>
import { useFetch } from "@vueuse/core"
import { onMounted, computed } from "vue"
import { handleError } from "@/utils/error-handling"
import { computed } from "vue"
import ProgressSpinner from "@/components/ProgressSpinner"
import SnapshotItem from "@/components/SnapshotItem"

const props = defineProps(["declarationId", "hideInstructionDetails"])

const { response, data, execute, isFetching } = useFetch(
() => `/api/v1/declarations/${props.declarationId}/snapshots/`,
{ immediate: false }
)
.get()
.json()
const props = defineProps(["snapshots", "declarationId", "hideInstructionDetails"])

const snapshots = computed(() => {
if (props.hideInstructionDetails) {
Expand All @@ -46,14 +37,9 @@ const snapshots = computed(() => {
"WITHDRAW",
"ABANDON",
]
return data.value?.filter((x) => allowedActions.indexOf(x.action) > -1)
return props.snapshots?.filter((x) => allowedActions.indexOf(x.action) > -1)
}
return data.value
})

onMounted(async () => {
await execute()
handleError(response)
return props.snapshots
})

const showOnRight = (snapshot) => {
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/views/InstructionPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
<p>Vous pouvez vous assigner cette déclaration pour instruction</p>
<DsfrButton class="mt-2" label="Instruire" tertiary @click="instructDeclaration" />
</DsfrAlert>
<DeclarationAlert class="mb-6" v-else-if="!canInstruct" role="instructor" :declaration="declaration" />
<DeclarationAlert
class="mb-6"
v-else-if="!canInstruct"
role="instructor"
:declaration="declaration"
:snapshots="snapshots"
/>
<div v-if="declaration">
<DeclarationSummary
:showArticle="true"
Expand Down Expand Up @@ -53,6 +59,7 @@
:declarationId="declaration?.id"
:user="declarant"
:company="company"
:snapshots="snapshots"
@decision-done="onDecisionDone"
:showArticle="true"
></component>
Expand Down Expand Up @@ -155,6 +162,14 @@ const {
.get()
.json()

const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.declarationId}/snapshots/`, { immediate: false })
.get()
.json()

// Sauvegarde du commentaire privé
const saveComment = useDebounceFn(async () => {
const { response } = await useFetch(() => `/api/v1/declarations/${declaration.value?.id}`, {
Expand All @@ -181,6 +196,8 @@ onMounted(async () => {
handleError(declarantResponse)
await executeCompanyFetch()
handleError(companyResponse)
await executeSnapshotsFetch()
handleError(snapshotsResponse)
isFetching.value = false
})

Expand Down
13 changes: 12 additions & 1 deletion frontend/src/views/ProducerFormPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<div v-else class="mb-4">
<DeclarationAlert v-if="payload" role="declarant" :declaration="payload" class="mb-4" />
<DeclarationAlert v-if="payload" role="declarant" :declaration="payload" :snapshots="snapshots" class="mb-4" />

<DsfrAlert
class="mb-4"
Expand Down Expand Up @@ -61,6 +61,7 @@
:externalResults="$externalResults"
:readonly="readonly"
:declarationId="id"
:snapshots="snapshots"
@withdraw="onWithdrawal"
:hideInstructionDetails="true"
></component>
Expand Down Expand Up @@ -159,9 +160,19 @@ const { response, data, isFetching, execute } = useFetch(`/api/v1/declarations/$
.get()
.json()

const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.id}/snapshots/`, { immediate: false })
.get()
.json()

if (!isNewDeclaration.value || route.query.duplicate) execute()
if (!isNewDeclaration.value && !route.query.duplicate) executeSnapshotsFetch()

watch(response, () => handleError(response))
watch(snapshotsResponse, () => handleError(snapshotsResponse))
watch(data, () => {
const shouldDuplicate = route.query.duplicate && !props.id
if (shouldDuplicate) {
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/views/VisaPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<p>Vous pouvez vous assigner cette déclaration pour visa / signature</p>
<DsfrButton class="mt-2" label="Prendre pour validation" tertiary @click="takeDeclaration" />
</DsfrAlert>
<DeclarationAlert role="visor" class="mb-4" v-else :declaration="declaration" />
<DeclarationAlert role="visor" class="mb-4" v-else :declaration="declaration" :snapshots="snapshots" />
<div v-if="declaration">
<DeclarationSummary
:showArticle="true"
Expand Down Expand Up @@ -50,6 +50,7 @@
:showElementAuthorization="true"
:user="declarant"
:company="company"
:snapshots="snapshots"
@decision-done="onDecisionDone"
></component>
</DsfrTabContent>
Expand Down Expand Up @@ -150,6 +151,14 @@ const {
.get()
.json()

const {
response: snapshotsResponse,
data: snapshots,
execute: executeSnapshotsFetch,
} = useFetch(() => `/api/v1/declarations/${props.declarationId}/snapshots/`, { immediate: false })
.get()
.json()

const privateNotesInstruction = ref(declaration.value?.privateNotesInstruction || "")
const privateNotesVisa = ref(declaration.value?.privateNotesVisa || "")
onMounted(async () => {
Expand All @@ -168,6 +177,8 @@ onMounted(async () => {
handleError(declarantResponse)
await executeCompanyFetch()
handleError(companyResponse)
await executeSnapshotsFetch()
handleError(snapshotsResponse)
isFetching.value = false
})

Expand Down
31 changes: 24 additions & 7 deletions web/views/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from xhtml2pdf import pisa

from api.permissions import CanAccessIndividualDeclaration
from data.models import Declaration
from data.models import Declaration, Snapshot

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,29 +53,46 @@ def get_template_path(self, declaration):
status.ONGOING_VISA,
]:
return f"certificates/certificate-submitted-art-{article}.html"
if declaration.status in [status.AUTHORIZED, status.WITHDRAWN]:

template_status = declaration.status

# La mise en abandon ne produit pas de Snapshot (car pas effectué en tant qu'action usager).
# On vérifie donc le status du dernier snapshot pour calculer le template
if template_status == status.ABANDONED:
template_status = declaration.snapshots.latest("creation_date").status

if template_status in [status.AUTHORIZED, status.WITHDRAWN]:
return f"certificates/certificate-art-{article}.html"
if declaration.status == status.OBJECTION:
if template_status == status.OBJECTION:
return "certificates/certificate-objected.html"
if declaration.status == status.REJECTED:
if template_status == status.REJECTED:
return "certificates/certificate-rejected.html"

raise NotFound()

def get_context(self, declaration):
status = Declaration.DeclarationStatus
date_statuses = [status.AWAITING_INSTRUCTION, status.AUTHORIZED, status.REJECTED]

try:
date = declaration.snapshots.filter(status__in=date_statuses).latest("creation_date").creation_date
date = (
declaration.snapshots.filter(status__in=date_statuses)
.exclude(action=Snapshot.SnapshotActions.REFUSE_VISA)
.latest("creation_date")
.creation_date
)
except Exception as e:
logger.error(f"Error obtaining certificate date for declaration {declaration.id}")
logger.exception(e)
date = declaration.creation_date

try:
submission_actions = [
Copy link
Collaborator

@pletelli pletelli Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste pour info : Je commence à me servir assez souvent dans metabase des catégories d'actions (submissions_action, ongoing_instruction_action, etc).
Je me demande si on ne devrait pas définir ça à un plus haut niveau à un moment donné

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah et je viens de capter du coup que ma catégorie submission n'est pas tout à fait exacte à cause du visa qui peut envoyer des AWAITING_INSTRUCTION

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tout à fait, je pense que par la suite on pourra créer des groupes d'actions dans le modèle Snapshot pour nous faciliter la vie

Snapshot.SnapshotActions.SUBMIT,
Snapshot.SnapshotActions.RESPOND_TO_OBJECTION,
Snapshot.SnapshotActions.RESPOND_TO_OBSERVATION,
]
last_submission_date = (
declaration.snapshots.filter(status=status.AWAITING_INSTRUCTION).latest("creation_date").creation_date
declaration.snapshots.filter(action__in=submission_actions).latest("creation_date").creation_date
)
except Exception as e:
logger.error(f"Error obtaining last submission date for declaration {declaration.id}")
Expand Down
Loading