Skip to content

Commit

Permalink
Bug : parfois le numero_operation_recherche est nul (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolok authored Sep 4, 2024
1 parent e97e1e1 commit 86a6e76
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 2 deletions.
226 changes: 226 additions & 0 deletions programmes/migrations/0102_historicalprogramme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# Generated by Django 4.2.13 on 2024-09-03 19:58

import uuid

import django.contrib.postgres.search
import django.db.models.deletion
import simple_history.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bailleurs", "0001_initial_squashed_0027_remove_search_vector_trigger"),
("instructeurs", "0001_initial_squashed_0017_auto_20230925_1209"),
("programmes", "0101_programme_reassign_command_old_admin_backup"),
]

operations = [
migrations.CreateModel(
name="HistoricalProgramme",
fields=[
("id", models.IntegerField(blank=True, db_index=True)),
("uuid", models.UUIDField(default=uuid.uuid4, editable=False)),
("nom", models.CharField(max_length=255)),
("numero_operation", models.CharField(max_length=255, null=True)),
(
"numero_operation_pour_recherche",
models.CharField(max_length=255, null=True),
),
("seconde_vie", models.BooleanField(default=False)),
("adresse", models.TextField(blank=True, null=True)),
("code_postal", models.CharField(blank=True, max_length=5, null=True)),
("ville", models.CharField(blank=True, max_length=255, null=True)),
("code_insee_commune", models.CharField(max_length=10, null=True)),
("code_insee_departement", models.CharField(max_length=10, null=True)),
("code_insee_region", models.CharField(max_length=10, null=True)),
("annee_gestion_programmation", models.IntegerField(null=True)),
(
"zone_123",
models.CharField(
choices=[
("1", "01"),
("2", "02"),
("3", "03"),
("1bis", "1bis"),
],
default=None,
max_length=25,
null=True,
),
),
(
"zone_abc",
models.CharField(
choices=[
("A", "A"),
("Abis", "Abis"),
("B1", "B1"),
("B2", "B2"),
("C", "C"),
("DROM", "DROM"),
],
default=None,
max_length=25,
null=True,
),
),
(
"surface_utile_totale",
models.DecimalField(decimal_places=2, max_digits=10, null=True),
),
(
"surface_corrigee_totale",
models.DecimalField(decimal_places=2, max_digits=10, null=True),
),
(
"type_operation",
models.CharField(
choices=[
("SANSOBJET", "Sans Objet"),
("NEUF", "Construction Neuve"),
("VEFA", "Construction Neuve > VEFA"),
("ACQUIS", "Acquisition"),
("ACQUISAMELIORATION", "Acquisition-Amélioration"),
("REHABILITATION", "Réhabilitation"),
("ACQUISSANSTRAVAUX", "Acquisition sans travaux"),
("SANSTRAVAUX", "Sans aide financière (sans travaux)"),
("USUFRUIT", "Usufruit"),
],
default="NEUF",
max_length=25,
),
),
(
"nature_logement",
models.CharField(
choices=[
("LOGEMENTSORDINAIRES", "Logements ordinaires"),
("AUTRE", "Autres logements foyers"),
("HEBERGEMENT", "Hébergement"),
("RESISDENCESOCIALE", "Résidence sociale"),
(
"PENSIONSDEFAMILLE",
"Pensions de famille (Maisons relais)",
),
("RESIDENCEDACCUEIL", "Résidence d'accueil"),
("RESIDENCEUNIVERSITAIRE", "Résidence universitaire"),
("RHVS", "RHVS"),
],
default="LOGEMENTSORDINAIRES",
max_length=25,
),
),
("anru", models.BooleanField(default=False)),
("nb_locaux_commerciaux", models.IntegerField(null=True)),
("nb_bureaux", models.IntegerField(null=True)),
("autres_locaux_hors_convention", models.TextField(null=True)),
("vendeur", models.TextField(null=True)),
("acquereur", models.TextField(null=True)),
("date_acte_notarie", models.DateField(null=True)),
("reference_notaire", models.TextField(null=True)),
("reference_publication_acte", models.TextField(null=True)),
("acte_de_propriete", models.TextField(null=True)),
("effet_relatif", models.TextField(null=True)),
("certificat_adressage", models.TextField(null=True)),
("reference_cadastrale", models.TextField(null=True)),
("edd_volumetrique", models.TextField(max_length=5000, null=True)),
(
"mention_publication_edd_volumetrique",
models.TextField(max_length=5000, null=True),
),
("edd_classique", models.TextField(max_length=5000, null=True)),
(
"mention_publication_edd_classique",
models.TextField(max_length=5000, null=True),
),
(
"edd_stationnements",
models.TextField(blank=True, max_length=5000, null=True),
),
("permis_construire", models.CharField(max_length=255, null=True)),
("date_achevement_previsible", models.DateField(null=True)),
("date_achat", models.DateField(null=True)),
("date_achevement", models.DateField(null=True)),
(
"date_autorisation_hors_habitat_inclusif",
models.DateField(null=True),
),
("date_convention_location", models.DateField(null=True)),
(
"date_residence_argement_gestionnaire_intermediation",
models.DateField(null=True),
),
(
"departement_residence_argement_gestionnaire_intermediation",
models.CharField(max_length=255, null=True),
),
(
"ville_signature_residence_agrement_gestionnaire_intermediation",
models.CharField(max_length=255, null=True),
),
("date_achevement_compile", models.DateField(null=True)),
("cree_le", models.DateTimeField(blank=True, editable=False)),
("mis_a_jour_le", models.DateTimeField(blank=True, editable=False)),
(
"search_vector",
django.contrib.postgres.search.SearchVectorField(
blank=True, null=True
),
),
("reassign_command_old_admin_backup", models.IntegerField(null=True)),
("history_user_id", models.IntegerField(null=True)),
("history_id", models.AutoField(primary_key=True, serialize=False)),
("history_date", models.DateTimeField(db_index=True)),
("history_change_reason", models.CharField(max_length=100, null=True)),
(
"history_type",
models.CharField(
choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
max_length=1,
),
),
(
"administration",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="instructeurs.administration",
),
),
(
"bailleur",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="bailleurs.bailleur",
),
),
(
"parent",
models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="+",
to="programmes.programme",
),
),
],
options={
"verbose_name": "historical programme",
"verbose_name_plural": "historical programmes",
"ordering": ("-history_date", "-history_id"),
"get_latest_by": ("history_date", "history_id"),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
8 changes: 7 additions & 1 deletion programmes/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from django.contrib.postgres.search import SearchVectorField
from django.db import models
from django.forms import model_to_dict
from simple_history.models import HistoricalRecords

from conventions.models.choices import ConventionStatut
from core.utils import get_key_from_json_field
from core.utils import custom_history_user_setter, get_key_from_json_field

from .choices import (
Financement,
Expand Down Expand Up @@ -142,6 +143,11 @@ class Meta:
search_vector = SearchVectorField(null=True, blank=True)
reassign_command_old_admin_backup = models.IntegerField(null=True)

history = HistoricalRecords(
history_user_id_field=models.IntegerField(null=True),
history_user_setter=custom_history_user_setter,
)

@property
def all_conventions_are_signed(self):
not_signed_conventions = [
Expand Down
2 changes: 1 addition & 1 deletion programmes/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def compute_date_achevement_compile(sender, instance, *args, **kwargs):
instance.date_achevement or instance.date_achevement_previsible
)
if instance.code_postal and len(instance.code_postal) == 5:
if int(instance.code_postal) >= 97000:
if instance.code_postal.isnumeric() and int(instance.code_postal) >= 97000:
code_departement = instance.code_postal[0:3]
else:
code_departement = instance.code_postal[0:2]
Expand Down

0 comments on commit 86a6e76

Please sign in to comment.