summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py16
-rw-r--r--archaeological_operations/wizards.py3
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