From 989c6ad90cc25a9f013ddbf18ab6f405aa27bf05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <tomas@imaniti.org>
Date: Tue, 19 Mar 2024 11:06:25 +0100
Subject: [PATCH] default to true

---
 contracts/admin.py  | 19 ++++++++++++++++---
 contracts/models.py | 10 ++++++++--
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/contracts/admin.py b/contracts/admin.py
index d83bd23..349cf61 100644
--- a/contracts/admin.py
+++ b/contracts/admin.py
@@ -123,7 +123,10 @@ class ContractFileAdmin(
 
 class ParentContractInlineMixin:
     def get_parent_object_is_editable(self, obj):
-        return obj.is_editable_without_approve_permission
+        if hasattr(obj, "is_editable_without_approve_permission"):
+            return obj.is_editable_without_approve_permission
+
+        return False
 
     def has_add_permission(self, request, obj=None):
         if (
@@ -165,7 +168,12 @@ class ContracteeSignatureRepresentativeInline(
         elif hasattr(obj, "is_editable_without_approve_permission"):
             return obj.is_editable_without_approve_permission
 
-        return False
+        # FIXME: We MUST return a True value here, since the admin seemingly
+        # creates the parent ContracteeSignature with empty data, then
+        # validates this inline before actually filling any fields.
+        # Thus, it has no `contract` attribute.
+
+        return True
 
     def get_formset(self, request, obj=None, **kwargs):
         formset = super().get_formset(request, obj, **kwargs)
@@ -193,7 +201,12 @@ class SigneeSignatureRepresentativeInline(
         elif hasattr(obj, "is_editable_without_approve_permission"):
             return obj.is_editable_without_approve_permission
 
-        return False
+        # FIXME: We MUST return a True value here, since the admin seemingly
+        # creates the parent ContracteeSignature with empty data, then
+        # validates this inline before actually filling any fields.
+        # Thus, it has no `contract` attribute.
+
+        return True
 
     model = SigneeSignatureRepresentative
     extra = 0
diff --git a/contracts/models.py b/contracts/models.py
index 380e736..026c0dc 100644
--- a/contracts/models.py
+++ b/contracts/models.py
@@ -993,7 +993,10 @@ class ContracteeSignature(models.Model):
     )
 
     def __str__(self) -> str:
-        return f"{str(self.contractee)} - {self.date}"
+        if hasattr(self, "contractee"):
+            return f"{str(self.contractee)} - {self.date}"
+        else:
+            return f"Bez smluvnĂ­ strany - {self.date}"
 
     class Meta:
         app_label = "contracts"
@@ -1030,7 +1033,10 @@ class SigneeSignature(models.Model):
     )
 
     def __str__(self) -> str:
-        return f"{str(self.signee)} - {self.date}"
+        if hasattr(self, "signee"):
+            return f"{str(self.signee)} - {self.date}"
+        else:
+            return f"Bez smluvnĂ­ strany - {self.date}"
 
     class Meta:
         app_label = "contracts"
-- 
GitLab