summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-11-25 17:34:36 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-19 14:45:56 +0100
commit225f4356ca145d7f634aa8050d936de2dbd1cfec (patch)
treeca6fa38d247d041f2292677dcb9d57511b944187
parentc799c6902e389d2c91f602380b5639878af73356 (diff)
downloadIshtar-225f4356ca145d7f634aa8050d936de2dbd1cfec.tar.bz2
Ishtar-225f4356ca145d7f634aa8050d936de2dbd1cfec.zip
🐛 fix associated basket for treatment requests
-rw-r--r--archaeological_finds/models_finds.py4
-rw-r--r--archaeological_finds/models_treatments.py18
2 files changed, 20 insertions, 2 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 93a3286bc..4c410f668 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2848,7 +2848,9 @@ class Find(
def associated_treatment_files(self):
TreatmentFile = apps.get_model("archaeological_finds", "TreatmentFile")
return TreatmentFile.objects.filter(
- associated_basket__items__pk=self.pk
+ associated_basket_id__in=FindBasket.objects.filter(
+ items__pk=self.pk
+ ).values_list("pk", flat=True)
).order_by("reception_date", "creation_date", "end_date")
def associated_treatment_files_count(self):
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index c7c4fcac9..9a9455ea1 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -113,6 +113,22 @@ class AssociatedFindBasket:
elif associated_basket and associated_basket.pk != self.associated_basket_id:
self.associated_basket_id = associated_basket.pk
+ @classmethod
+ def has_q_associated_basket_item_ids(cls):
+ # used by permission queries
+ return cls.objects.filter(
+ associated_basket_id__in=FindBasket.objects.filter(
+ items__pk__isnull=False).values_list("pk", flat=True)
+ )
+
+ @classmethod
+ def q_associated_basket_item_ids(cls, ids):
+ # used by permission queries
+ return cls.objects.filter(
+ associated_basket_id__in=FindBasket.objects.filter(
+ items__pk__in=ids
+ )
+ )
class Treatment(
@@ -1189,7 +1205,7 @@ class TreatmentFile(
]
UPPER_PERMISSIONS = [
(("archaeological_finds", "find"),
- "associated_basket__items__pk"),
+ "q_associated_basket_item_ids"),
]
# alternative names of fields for searches
ALT_NAMES = {