diff options
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 16 |
1 files changed, 15 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) |