Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
etchegom committed Jul 3, 2024
1 parent 3cc02f4 commit 79ecae8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
10 changes: 7 additions & 3 deletions conventions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,25 @@ def view_programme_operation(convention):
return convention.programme.numero_operation


@admin.display(description="Financement")
def view_financement(convention):
return convention.lot.financement


@admin.register(Convention)
class ConventionAdmin(ApilosModelAdmin):
list_display = (
view_programme,
"administration",
"bailleur",
"financement",
view_financement,
"uuid",
view_programme_operation,
)
search_fields = [
"programme__ville",
"programme__nom",
"financement",
"lot__financement",
"uuid",
"programme__bailleur__nom",
"programme__administration__nom",
Expand All @@ -107,7 +112,6 @@ class ConventionAdmin(ApilosModelAdmin):
"numero",
"numero_pour_recherche",
"date_fin_conventionnement",
"financement",
"fond_propre",
"commentaires",
"statut",
Expand Down
31 changes: 31 additions & 0 deletions conventions/migrations/0087_remove_convention_financement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.13 on 2024-07-03 15:53

from django.db import migrations
from django.db.models import F, Q


def check_convention_lot_financement(apps, schema_editor):
Convention = apps.get_model("conventions", "Convention")

qs = Convention.objects.annotate(lot_financement=F("lot__financement")).filter(
~Q(financement=F("lot_financement"))
)

assert qs.count() == 0, list(qs.values_list("id", "financement", "lot_financement"))


class Migration(migrations.Migration):
dependencies = [
("conventions", "0086_alter_convention_financement"),
]

operations = [
migrations.RunPython(
check_convention_lot_financement,
migrations.RunPython.noop,
),
migrations.RemoveField(
model_name="convention",
name="financement",
),
]
38 changes: 17 additions & 21 deletions conventions/models/convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,23 @@ class Meta:
name="convention_tele_signee_le_idx",
),
]
constraints = [
# https://github.com/betagouv/SPPNautInterface/issues/227
models.UniqueConstraint(
fields=["programme_id", "lot_id", "financement"],
condition=models.Q(
statut__in=[
ConventionStatut.PROJET.label,
ConventionStatut.INSTRUCTION.label,
ConventionStatut.CORRECTION.label,
ConventionStatut.A_SIGNER.label,
ConventionStatut.SIGNEE.label,
]
),
name="unique_display_name",
)
]
# FIXME: This constraint is not working anymore
# constraints = [
# # https://github.com/betagouv/SPPNautInterface/issues/227
# models.UniqueConstraint(
# fields=["programme_id", "lot_id", "financement"],
# condition=models.Q(
# statut__in=[
# ConventionStatut.PROJET.label,
# ConventionStatut.INSTRUCTION.label,
# ConventionStatut.CORRECTION.label,
# ConventionStatut.A_SIGNER.label,
# ConventionStatut.SIGNEE.label,
# ]
# ),
# name="unique_display_name",
# )
# ]

id = models.AutoField(primary_key=True)
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
Expand All @@ -88,11 +89,6 @@ class Meta:
related_name="conventions",
)
date_fin_conventionnement = models.DateField(null=True, blank=True)
financement = models.CharField(
max_length=25,
choices=Financement.choices,
default=Financement.PLUS,
)
# fix me: weird to keep fond_propre here
fond_propre = models.FloatField(null=True, blank=True)
commentaires = models.TextField(null=True, blank=True)
Expand Down

0 comments on commit 79ecae8

Please sign in to comment.