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 1 commit
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
6 changes: 3 additions & 3 deletions frontend/src/components/DeclarationAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ 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: true }
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -140,7 +140,7 @@ 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: true }
case "REJECTED":
return {
type: "warning",
Expand Down Expand Up @@ -196,7 +196,7 @@ 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: true }
case "REJECTED":
return {
type: "warning",
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
if template_status == status.ABANDONED:
pre_abandon_statuses = [status.OBJECTION, status.OBSERVATION]
template_status = (
declaration.snapshots.filter(status__in=pre_abandon_statuses).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