diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-08-28 18:27:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | eb99d500e8e1d5b8be8f02ffdf8c4b505159add5 (patch) | |
tree | 5542f0dc3de02b8d9596df321eed4a1bca1254b7 /archaeological_operations | |
parent | 131afa027985065ecf4c97600440500884a9ef26 (diff) | |
download | Ishtar-eb99d500e8e1d5b8be8f02ffdf8c4b505159add5.tar.bz2 Ishtar-eb99d500e8e1d5b8be8f02ffdf8c4b505159add5.zip |
Operation edit: clean potential parcel duplication
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/models.py | 16 | ||||
-rw-r--r-- | archaeological_operations/wizards.py | 3 |
2 files changed, 18 insertions, 1 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 014dbb269..368b2e33c 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -1739,6 +1739,18 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, res['mode'] = " ; ".join([str(m) for m in mode(finds)]) return res + def clean_parcel_duplicates(self): + parcels = [] + for p in self.parcels.order_by('pk').all(): + if p.associated_file: + continue + key = (p.section, p.parcel_number, p.year, p.town.pk, + p.public_domain) + if key in parcels: + p.delete() + else: + parcels.append(key) + def save(self, *args, **kwargs): # put a default year if start_date is defined if self.start_date and not self.year: @@ -1747,7 +1759,9 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem, self.operation_code = self.get_available_operation_code(self.year) if hasattr(self, 'code_patriarche'): self.code_patriarche = self.code_patriarche or None - return super(Operation, self).save(*args, **kwargs) + item = super(Operation, self).save(*args, **kwargs) + self.clean_parcel_duplicates() + return item m2m_changed.connect(force_cached_label_changed, sender=Operation.towns.through) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index a37e923fb..fc5ce0bf8 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -277,6 +277,9 @@ class OperationWizard(Wizard): request.POST = post_data return super(OperationWizard, self).post(*args, **kwargs) + def post_save(self): + self.current_object.clean_parcel_duplicates() + class OperationModificationWizard(OperationWizard): modification = True |