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

Suppression de la notion de financement sur le modèle convention #1726

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 0 additions & 19 deletions conventions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ def _post_clean(self) -> None:

self.instance.statut = ConventionStatut[self.instance.statut].label

# try:
# self.instance.validate_constraints()
# except ValidationError as err:
# if "unique_display_name" in str(err):
# self.add_error(
# None,
# (
# "Problème d'unicité, une convention existe déjà pour ces critères. "
# f"Vérifiez les conventions existantes sur le programme {self.instance.programme.id}, "
# "le lot {self.instance.lot.id}, "
# f"avec un financement {self.instance.financement}."
# ),
# )
# else:
# self.add_error(None, err)

class Meta:
model = Convention
exclude = []
Expand All @@ -84,14 +68,12 @@ class ConventionAdmin(ApilosModelAdmin):
view_programme,
"administration",
"bailleur",
"financement",
"uuid",
view_programme_operation,
)
search_fields = [
"programme__ville",
"programme__nom",
"financement",
"uuid",
"programme__bailleur__nom",
"programme__administration__nom",
Expand All @@ -106,7 +88,6 @@ class ConventionAdmin(ApilosModelAdmin):
"numero",
"numero_pour_recherche",
"date_fin_conventionnement",
"financement",
"fond_propre",
"commentaires",
"statut",
Expand Down
4 changes: 0 additions & 4 deletions conventions/fixtures/conventions_for_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"numero": "0001",
"programme": 1,
"date_fin_conventionnement": null,
"financement": "PLUS",
"fond_propre": null,
"commentaires": "{\"text\": \"this is a test\", \"files\": {\"f7f5151c-6031-4ba4-a041-12666b700def\": {\"uuid\": \"f7f5151c-6031-4ba4-a041-12666b700def\", \"thumbnail\": \"data:image/png;base64,BLAHBLAH==\", \"size\": \"31185\", \"filename\": \"acquereur1.png\", \"realname\": \"acquereur1.png\", \"content_type\": \"image/png\"}, \"a9a47df6-5493-43be-bd21-e86c3d6e79b4\": {\"uuid\": \"a9a47df6-5493-43be-bd21-e86c3d6e79b4\", \"thumbnail\": \"data:image/png;base64,BLIHBLIH==\", \"size\": \"69076\", \"filename\": \"acquereur2.png\", \"realname\": \"acquereur2.png\", \"content_type\": \"image/png\"}}}",
"attached": null,
Expand Down Expand Up @@ -119,7 +118,6 @@
"numero": "0002",
"programme": 1,
"date_fin_conventionnement": null,
"financement": "PLAI",
"fond_propre": null,
"commentaires": "{\"text\": \"this is a test\", \"files\": {\"94520361-d943-44ee-a0c0-5ec93c85e2c5\": {\"uuid\": \"94520361-d943-44ee-a0c0-5ec93c85e2c5\", \"thumbnail\": \"data:image/png;base64,BLAHBLAH==\", \"size\": \"31185\", \"filename\": \"acquereur1.png\", \"realname\": \"acquereur1.png\", \"content_type\": \"image/png\"}, \"1a22e492-8d50-4b53-8336-9f925581d8fd\": {\"uuid\": \"1a22e492-8d50-4b53-8336-9f925581d8fd\", \"thumbnail\": \"data:image/png;base64,BLIHBLIH==\", \"size\": \"69076\", \"filename\": \"acquereur2.png\", \"realname\": \"acquereur2.png\", \"content_type\": \"image/png\"}}}",
"attached": null,
Expand Down Expand Up @@ -201,7 +199,6 @@
"numero": "0003",
"programme": 2,
"date_fin_conventionnement": null,
"financement": "PLUS",
"fond_propre": null,
"commentaires": "{\"text\": \"this is a test\", \"files\": {\"62ddb671-f021-4ae6-8de3-403ba7d80c2c\": {\"uuid\": \"62ddb671-f021-4ae6-8de3-403ba7d80c2c\", \"thumbnail\": \"data:image/png;base64,BLAHBLAH==\", \"size\": \"31185\", \"filename\": \"acquereur1.png\", \"realname\": \"acquereur1.png\", \"content_type\": \"image/png\"}, \"e309ed33-67e0-4fb3-89d9-35db87a9849f\": {\"uuid\": \"e309ed33-67e0-4fb3-89d9-35db87a9849f\", \"thumbnail\": \"data:image/png;base64,BLIHBLIH==\", \"size\": \"69076\", \"filename\": \"acquereur2.png\", \"realname\": \"acquereur2.png\", \"content_type\": \"image/png\"}}}",
"attached": null,
Expand Down Expand Up @@ -283,7 +280,6 @@
"numero": "0004",
"programme": 2,
"date_fin_conventionnement": null,
"financement": "PLAI",
"fond_propre": null,
"commentaires": "{\"text\": \"this is a test\", \"files\": {\"11df0962-e377-4133-a128-6a749256c4c8\": {\"uuid\": \"11df0962-e377-4133-a128-6a749256c4c8\", \"thumbnail\": \"data:image/png;base64,BLAHBLAH==\", \"size\": \"31185\", \"filename\": \"acquereur1.png\", \"realname\": \"acquereur1.png\", \"content_type\": \"image/png\"}, \"46caa33d-7e6d-440c-a652-75cab45f4dba\": {\"uuid\": \"46caa33d-7e6d-440c-a652-75cab45f4dba\", \"thumbnail\": \"data:image/png;base64,BLIHBLIH==\", \"size\": \"69076\", \"filename\": \"acquereur2.png\", \"realname\": \"acquereur2.png\", \"content_type\": \"image/png\"}}}",
"attached": null,
Expand Down
4 changes: 2 additions & 2 deletions conventions/forms/convention_form_financement.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def clean(self):
):
if self.convention.programme.is_outre_mer:
self._outre_mer_end_date_validation(annee_fin_conventionnement)
elif self.convention.financement == Financement.PLS:
elif self.convention.lot.financement == Financement.PLS:
self._pls_end_date_validation(annee_fin_conventionnement)
elif self.convention.programme.type_operation == TypeOperation.SANSTRAVAUX:
self._sans_travaux_end_date_validation(annee_fin_conventionnement)
Expand Down Expand Up @@ -316,7 +316,7 @@ def manage_cdc_validation(self):
"""
if (
self.convention is not None
and self.convention.financement != Financement.PLS
and self.convention.lot.financement != Financement.PLS
and self.convention.programme.type_operation != TypeOperation.SANSTRAVAUX
):
for form in self.forms:
Expand Down
11 changes: 2 additions & 9 deletions conventions/management/commands/update_financement.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add_arguments(self, parser):
)

def financement_update(self, numero, new_financement):
qs = Convention.objects.filter(numero=numero)
qs = Convention.objects.prefetch_related("lots").filter(numero=numero)
if qs.count() == 0:
self.stdout.write(self.style.WARNING(f"Convention {numero} not found."))
self.numeros_not_found.append(numero)
Expand All @@ -42,25 +42,18 @@ def financement_update(self, numero, new_financement):

for convention in qs:
lot_convention = convention.lot
if (
convention.financement == new_financement
and lot_convention.financement == new_financement
):
if lot_convention.financement == new_financement:
self.stdout.write(
self.style.WARNING(
f"Convention {numero} already in financement {new_financement}"
)
)
return
convention.financement = new_financement
lot_convention.financement = new_financement
convention.save()
lot_convention.save()
for avenant in convention.avenants.all():
avenant.financement = new_financement
lot_avenant = avenant.lot
lot_avenant.financement = new_financement
avenant.save()
lot_avenant.save()

self.counter_success += 1
Expand Down
19 changes: 19 additions & 0 deletions conventions/migrations/0101_remove_convention_financement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.3 on 2025-01-31 09:33

from django.db import migrations

# FIXME : supprimer cette migration vide ?


class Migration(migrations.Migration):

dependencies = [
("conventions", "0100_auto_20241213_1554"),
]

operations = [
migrations.RemoveField(
model_name="convention",
name="financement",
),
]
9 changes: 1 addition & 8 deletions conventions/models/convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ class Meta:

date_fin_conventionnement = models.DateField(null=True, blank=True)

# DEPRECATED: use lof.financeur instead
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 @@ -574,7 +567,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
2 changes: 1 addition & 1 deletion conventions/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _build_filters(self, queryset: QuerySet) -> QuerySet:
queryset = queryset.filter(parent_id__isnull=False)

if self.financement:
queryset = queryset.filter(financement=self.financement)
queryset = queryset.filter(lots__financement=self.financement)

if self.nature_logement:
queryset = queryset.filter(programme__nature_logement=self.nature_logement)
Expand Down
40 changes: 14 additions & 26 deletions conventions/services/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,19 @@ def post_create_convention(self):
# default ANRU when it is SIAP version
anru=bool(settings.CERBERE_AUTH),
)
programme.save()

lot = Lot.objects.create(
self.convention = Convention.objects.create(
programme=programme,
cree_par=self.request.user,
)

Lot.objects.create(
nb_logements=self.form.cleaned_data["nb_logements"],
financement=self.form.cleaned_data["financement"],
type_habitat=self.form.cleaned_data["type_habitat"],
programme=programme,
convention=self.convention,
)
lot.save()

self.convention = Convention.objects.create(
programme_id=lot.programme_id,
financement=lot.financement,
cree_par=self.request.user,
)
self.convention.save()

lot.convention = self.convention
lot.save()

file = self.request.FILES.get("nom_fichier_signe", False)
if file:
Expand Down Expand Up @@ -142,26 +136,20 @@ def post_for_avenant(self):
else TypeOperation.NEUF
),
)
programme.save()

lot = Lot.objects.create(
nb_logements=self.form.cleaned_data["nb_logements"],
financement=self.form.cleaned_data["financement"],
programme=programme,
)
lot.save()

self.convention = Convention.objects.create(
programme_id=lot.programme_id,
financement=lot.financement,
programme=programme,
cree_par=self.request.user,
statut=(ConventionStatut.SIGNEE.label),
numero=(self.form.cleaned_data["numero"]),
)
self.convention.save()

lot.convention = self.convention
lot.save()
Lot.objects.create(
nb_logements=self.form.cleaned_data["nb_logements"],
financement=self.form.cleaned_data["financement"],
programme=programme,
convention=self.convention,
)

conventionfile = self.request.FILES.get("nom_fichier_signe", False)
if conventionfile:
Expand Down
11 changes: 7 additions & 4 deletions conventions/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class Meta:
numero = factory.Sequence(lambda n: f"Convention {n}")
programme = factory.SubFactory(ProgrammeFactory)

# lot = factory.SubFactory("programmes.tests.factories.LotFactory")
# programme = factory.SelfAttribute("lot.programme")
# financement = factory.SelfAttribute("lot.financement")

@factory.post_generation
def create_lot(obj, create, extracted, **kwargs): # noqa: N805
if extracted and create:
Expand All @@ -30,6 +26,13 @@ class AvenantFactory(ConventionFactory):
numero = "1"
parent = factory.SubFactory(ConventionFactory)

@factory.post_generation
def create_lot(obj, create, extracted, **kwargs): # noqa: N805
if extracted and create:
lot = LotFactory.create(convention=obj, programme=obj.programme, **kwargs)
obj.financement = lot.financement
obj.save()


class AvenantTypeFactory(factory.django.DjangoModelFactory):
class Meta:
Expand Down
4 changes: 2 additions & 2 deletions conventions/tests/models/test_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ def test_short_statut_for_instructeur(self):
def test_mixity_option(self):
convention = Convention.objects.order_by("uuid").first()
for financement in [Financement.PLUS, Financement.PLUS_CD]:
convention.financement = financement
convention.lot.financement = financement
self.assertTrue(convention.mixity_option())
for financement in [
k
for (k, _) in Financement.choices
if k not in [Financement.PLUS, Financement.PLUS_CD]
]:
convention.financement = financement
convention.lot.financement = financement
self.assertFalse(convention.mixity_option())

def test_display_not_validated_status(self):
Expand Down
9 changes: 5 additions & 4 deletions conventions/tests/services/test_financement_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_year_isnot_too_far(self):
self.assertTrue(form.has_error("annee_fin_conventionnement"))

def test_year_max_limit_disabled(self):
self.service.convention.financement = Financement.PLS
self.service.convention.lot.financement = Financement.PLS
self.service.convention.save()
programme = self.service.convention.programme
programme.type_operation = TypeOperation.NEUF
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_outre_mer_sans_travaux_date_fin_conventionnement(self):
assert form.errors == {}

def test_outre_mer_lls_date_fin_conventionnement(self):
self.service.convention.financement = Financement.LLS
self.service.convention.lot.financement = Financement.LLS
self.service.convention.save()
programme = self.service.convention.programme
programme.type_operation = TypeOperation.REHABILITATION
Expand All @@ -204,8 +204,9 @@ def test_outre_mer_lls_date_fin_conventionnement(self):
assert form.errors == {}

def test_pls_avenant_date_fin_conventionnement(self):
self.service_avenant.convention.financement = Financement.PLS
self.service_avenant.convention.save()
lot = self.service_avenant.convention.lot
lot.financement = Financement.PLS
lot.save()

self.service_avenant.request.POST = {
**financement_form,
Expand Down
3 changes: 1 addition & 2 deletions conventions/tests/services/test_from_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from conventions.services.utils import ReturnStatus
from conventions.tests.factories import AvenantTypeFactory, ConventionFactory
from core.tests.test_utils import PGTrgmTestMixin
from programmes.models import Financement, NatureLogement
from programmes.models import NatureLogement
from programmes.tests.factories import ProgrammeFactory
from siap.siap_client.mock_data import operation_mock
from users.tests.factories import UserFactory
Expand Down Expand Up @@ -135,7 +135,6 @@ def setUp(self):
uuid="5611304e-74d6-41ab-8f9d-2d0c27563e9a",
numero="33N611709S700029",
statut=ConventionStatut.SIGNEE.label,
financement=Financement.PLUS,
televersement_convention_signee_le="2024-01-01",
programme=ProgrammeFactory(bailleur=self.bailleur),
create_lot=True,
Expand Down
Loading