summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md3
-rw-r--r--ishtar_common/fixtures/initial_geo-fr.json (renamed from ishtar_common/fixtures/initial_spatialrefsystem-fr.json)0
-rw-r--r--ishtar_common/models_common.py9
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 810728039..47055895b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,6 +13,9 @@ v4.0.15 - 2022-
- "is locked" search
+### Bug fix ###
+- Fix INSEE number generation on error with years
+
v4.0.14 - 2022-08-05
--------------------
diff --git a/ishtar_common/fixtures/initial_spatialrefsystem-fr.json b/ishtar_common/fixtures/initial_geo-fr.json
index ea244e0d0..ea244e0d0 100644
--- a/ishtar_common/fixtures/initial_spatialrefsystem-fr.json
+++ b/ishtar_common/fixtures/initial_geo-fr.json
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 238bbeeac..aa644f35a 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2694,7 +2694,14 @@ class Town(GeographicItem, Imported, models.Model):
return
old_num = self.numero_insee[:]
numero = old_num.split("-")[0]
- self.numero_insee = "{}-{}".format(numero, self.year)
+ base_insee = "{}-{}".format(numero, self.year)
+ self.numero_insee = base_insee
+ idx = 0
+ while Town.objects.filter(
+ year=self.year, numero_insee=self.numero_insee).exclude(
+ pk=self.pk).count():
+ idx += 1
+ self.numero_insee = base_insee + "-" + str(idx)
if self.numero_insee != old_num:
return True