diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-08-29 15:55:25 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 | 
| commit | 781a8d8b4f5051694c532c22ffc273e3c437edb1 (patch) | |
| tree | 2343cfaf983c64cff42ab0700aca2c295d58a895 | |
| parent | 6a0de82841d7eab7d749ea5b951c4797e32b4dfe (diff) | |
| download | Ishtar-781a8d8b4f5051694c532c22ffc273e3c437edb1.tar.bz2 Ishtar-781a8d8b4f5051694c532c22ffc273e3c437edb1.zip  | |
Fix INSEE number generation on error with years
| -rw-r--r-- | CHANGES.md | 3 | ||||
| -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.py | 9 | 
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  | 
