diff --git a/conventions/admin.py b/conventions/admin.py index 45a5f6e91..8b03836d0 100644 --- a/conventions/admin.py +++ b/conventions/admin.py @@ -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", @@ -107,7 +112,6 @@ class ConventionAdmin(ApilosModelAdmin): "numero", "numero_pour_recherche", "date_fin_conventionnement", - "financement", "fond_propre", "commentaires", "statut", diff --git a/conventions/migrations/0087_remove_convention_financement.py b/conventions/migrations/0087_remove_convention_financement.py new file mode 100644 index 000000000..1195031b5 --- /dev/null +++ b/conventions/migrations/0087_remove_convention_financement.py @@ -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", + ), + ] diff --git a/conventions/models/convention.py b/conventions/models/convention.py index 190e352ba..642890de3 100644 --- a/conventions/models/convention.py +++ b/conventions/models/convention.py @@ -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) @@ -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)