diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-11-16 19:10:01 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:19 +0100 |
commit | c0c0f67e4f6150de5c3cee7b13ef257a367486b9 (patch) | |
tree | 101ceae0727da1829d5761dd65ac5d89d091a479 /archaeological_operations/models.py | |
parent | 2e15f5fd3525120d22336faf10e960050aaefb67 (diff) | |
download | Ishtar-c0c0f67e4f6150de5c3cee7b13ef257a367486b9.tar.bz2 Ishtar-c0c0f67e4f6150de5c3cee7b13ef257a367486b9.zip |
Operation from file creation - fix automatic town association and parcel recopy
Diffstat (limited to 'archaeological_operations/models.py')
-rw-r--r-- | archaeological_operations/models.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 57f538383..293b1e933 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -2260,6 +2260,12 @@ def operation_post_save(sender, **kwargs): post_save_geo(sender=sender, **kwargs) operation = kwargs["instance"] + + # on creation associate parcel from a file if the file exist + if kwargs.get("created", False) and operation.associated_file: + for parcel in operation.associated_file.parcels.all(): + parcel.copy_from_file_to_operation(operation) + operation.skip_history_when_saving = True if operation.fnap_financing and operation.cost: fnap_cost = int(float(operation.cost) / 100 * operation.fnap_financing) @@ -3194,6 +3200,31 @@ class Parcel(LightHistorizedItem): self.operation = None self.save() + def copy_from_file_to_operation(self, operation): + """ + Used to copy parcel from file on operation creation + """ + if not self.associated_file: + return + keys = { + "town": self.town, + "section": self.section, + "parcel_number": self.parcel_number, + "operation": operation, + "associated_file": None, + "defaults": {"address": self.address, "year": self.year}, + } + new_p, created = Parcel.objects.get_or_create(**keys) + # copy owning only if created + if created: + for owning in self.owners.all(): + ParcelOwner.objects.create( + owner=owning.owner, + parcel=new_p, + start_date=owning.start_date, + end_date=owning.end_date, + ) + def clean_orphan(self): """ Remove when the parcel is linked to nothing |