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

S1196 - Suppression du type de financement du modèle Convention #1496

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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 @@ -106,7 +111,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",
),
]
40 changes: 18 additions & 22 deletions conventions/models/convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ class Meta:
),
models.Index(fields=["cree_le"], name="convention_cree_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 @@ -90,11 +91,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 Expand Up @@ -567,7 +563,7 @@ def mixity_option(self):
with low revenu should be displayed in the interface and fill in the convention document
Should be editable when it is a PLUS convention
"""
return self.financement in [Financement.PLUS, Financement.PLUS_CD]
return self.lot.financement in [Financement.PLUS, Financement.PLUS_CD]

def display_not_validated_status(self):
"""
Expand Down
Loading